From 56e8049c4bc2626d8dce447aa0fd3be222a099d8 Mon Sep 17 00:00:00 2001 From: vigneshshanmugam Date: Fri, 5 Nov 2021 13:47:22 -0700 Subject: [PATCH] fix: end timestamp should reflect duration --- __tests__/reporters/base.test.ts | 1 + __tests__/reporters/json.test.ts | 4 ++++ __tests__/reporters/junit.test.ts | 2 ++ src/core/gatherer.ts | 1 + src/core/runner.ts | 14 +++++++++++--- src/reporters/json.ts | 2 ++ 6 files changed, 21 insertions(+), 3 deletions(-) diff --git a/__tests__/reporters/base.test.ts b/__tests__/reporters/base.test.ts index da871d17..dce4eed5 100644 --- a/__tests__/reporters/base.test.ts +++ b/__tests__/reporters/base.test.ts @@ -102,6 +102,7 @@ describe('base reporter', () => { }; runner.emit('journey:end', { journey: j1, + timestamp, status: 'failed', error, start: 0, diff --git a/__tests__/reporters/json.test.ts b/__tests__/reporters/json.test.ts index 49fd3ca1..adade9de 100644 --- a/__tests__/reporters/json.test.ts +++ b/__tests__/reporters/json.test.ts @@ -163,6 +163,7 @@ describe('json reporter', () => { }); runner.emit('journey:end', { journey: j1, + timestamp, status: 'succeeded', start: 0, end: 11, @@ -225,6 +226,7 @@ describe('json reporter', () => { runner.emit('journey:end', { journey: j1, + timestamp, start: 0, end: 1, status: 'failed', @@ -242,6 +244,7 @@ describe('json reporter', () => { const journeyOpts = { name: 'name', id: 'id', tags: ['tag1', 'tag2'] }; runner.emit('journey:end', { journey: journey(journeyOpts, () => {}), + timestamp, start: 0, end: 1, status: 'skipped', @@ -301,6 +304,7 @@ describe('json reporter', () => { const emitEnd = (options, status = 'failed' as StatusValue) => runner.emit('journey:end', { journey: j1, + timestamp, start: 0, status, options, diff --git a/__tests__/reporters/junit.test.ts b/__tests__/reporters/junit.test.ts index 375c3a4f..8ce7d0ae 100644 --- a/__tests__/reporters/junit.test.ts +++ b/__tests__/reporters/junit.test.ts @@ -81,6 +81,7 @@ describe('junit reporter', () => { }); runner.emit('journey:end', { journey: j1, + timestamp, start: 0, status: 'failed', options: {}, @@ -115,6 +116,7 @@ describe('junit reporter', () => { }); runner.emit('journey:end', { journey: j1, + timestamp, start: 0, status: 'failed', options: {}, diff --git a/src/core/gatherer.ts b/src/core/gatherer.ts index 51b15ea5..b73c9ed9 100644 --- a/src/core/gatherer.ts +++ b/src/core/gatherer.ts @@ -37,6 +37,7 @@ export class Gatherer { static browser: ChromiumBrowser; static async setupDriver(options: RunOptions): Promise { + log('Gatherer: setup driver'); const { wsEndpoint, playwrightOptions, networkConditions } = options; if (Gatherer.browser == null) { diff --git a/src/core/runner.ts b/src/core/runner.ts index c9e9354b..93a2838a 100644 --- a/src/core/runner.ts +++ b/src/core/runner.ts @@ -123,6 +123,7 @@ interface Events { JourneyResult & { journey: Journey; options: RunOptions; + timestamp: number; }; 'journey:end:reported': unknown; 'step:start': { journey: Journey; step: Step }; @@ -149,8 +150,12 @@ export default class Runner extends EventEmitter { static screenshotPath = join(CACHE_PATH, 'screenshots'); static async createContext(options: RunOptions): Promise { - const start = monotonicTimeInSeconds(); const driver = await Gatherer.setupDriver(options); + /** + * Do not include browser launch/context creation duration + * as part of journey duration + */ + const start = monotonicTimeInSeconds(); const pluginManager = await Gatherer.beginRecording(driver, options); /** * For each journey we create the screenshots folder for @@ -339,6 +344,7 @@ export default class Runner extends EventEmitter { result: JourneyContext & JourneyResult, options: RunOptions ) { + const end = monotonicTimeInSeconds(); const { pluginManager, start, status, error } = result; const pluginOutput = pluginManager.output(); this.emit('journey:end', { @@ -346,7 +352,8 @@ export default class Runner extends EventEmitter { status, error, start, - end: monotonicTimeInSeconds(), + end, + timestamp: getTimestamp(), options, ...pluginOutput, browserconsole: status == 'failed' ? pluginOutput.browserconsole : [], @@ -378,6 +385,7 @@ export default class Runner extends EventEmitter { }; this.emit('journey:end', { journey, + timestamp: getTimestamp(), start, options, end: monotonicTimeInSeconds(), @@ -393,8 +401,8 @@ export default class Runner extends EventEmitter { const result: JourneyResult = { status: 'succeeded', }; - log(`Runner: start journey (${journey.name})`); const context = await Runner.createContext(options); + log(`Runner: start journey (${journey.name})`); try { this.registerJourney(journey, context); const hookArgs = { diff --git a/src/reporters/json.ts b/src/reporters/json.ts index 1dfa2770..e4844998 100644 --- a/src/reporters/json.ts +++ b/src/reporters/json.ts @@ -435,6 +435,7 @@ export default class JSONReporter extends BaseReporter { 'journey:end', async ({ journey, + timestamp, start, end, networkinfo, @@ -501,6 +502,7 @@ export default class JSONReporter extends BaseReporter { this.writeJSON({ type: 'journey/end', journey, + timestamp, error, payload: { start,