diff --git a/packages/aws-cdk/test/api/logs/logs-monitor.test.ts b/packages/aws-cdk/test/api/logs/logs-monitor.test.ts index becb3d97dfbf3..930e6427dbab7 100644 --- a/packages/aws-cdk/test/api/logs/logs-monitor.test.ts +++ b/packages/aws-cdk/test/api/logs/logs-monitor.test.ts @@ -17,20 +17,13 @@ afterAll(() => { monitor.deactivate(); }); -let TIMESTAMP: number; -let HUMAN_TIME: string; - -beforeAll(() => { - TIMESTAMP = new Date().getTime(); - HUMAN_TIME = new Date(TIMESTAMP).toLocaleTimeString(); -}); - test('continue to the next page if it exists', async () => { // GIVEN + const eventDate = new Date(T0 + 102 * 1000); sdk.stubCloudWatchLogs({ filterLogEvents() { return { - events: [event(102, 'message')], + events: [event(102, 'message', eventDate)], nextToken: 'some-token', }; }, @@ -50,22 +43,23 @@ test('continue to the next page if it exists', async () => { await sleep(1000); // THEN + const expectedLocaleTimeString = eventDate.toLocaleTimeString(); expect(stderrMock).toHaveBeenCalledTimes(2); expect(stderrMock.mock.calls[0][0]).toContain( - `[${blue('loggroup')}] ${yellow(HUMAN_TIME)} message`, + `[${blue('loggroup')}] ${yellow(expectedLocaleTimeString)} message`, ); expect(stderrMock.mock.calls[1][0]).toContain( - `[${blue('loggroup')}] ${yellow(new Date(T100).toLocaleTimeString())} >>> \`watch\` shows only the first 100 log messages - the rest have been truncated...`, + `[${blue('loggroup')}] ${yellow(expectedLocaleTimeString)} >>> \`watch\` shows only the first 100 log messages - the rest have been truncated...`, ); }); const T0 = 1597837230504; const T100 = T0 + 100 * 1000; -function event(nr: number, message: string): AWS.CloudWatchLogs.FilteredLogEvent { +function event(nr: number, message: string, timestamp: Date): AWS.CloudWatchLogs.FilteredLogEvent { return { eventId: `${nr}`, message, - timestamp: new Date(T0 * nr * 1000).getTime(), - ingestionTime: new Date(T0 * nr * 1000).getTime(), + timestamp: timestamp.getTime(), + ingestionTime: timestamp.getTime(), }; }