Skip to content

Commit

Permalink
fix: end timestamp should reflect duration (#410)
Browse files Browse the repository at this point in the history
  • Loading branch information
vigneshshanmugam authored Nov 5, 2021
1 parent 0bc9949 commit cdcf690
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 3 deletions.
1 change: 1 addition & 0 deletions __tests__/reporters/base.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ describe('base reporter', () => {
};
runner.emit('journey:end', {
journey: j1,
timestamp,
status: 'failed',
error,
start: 0,
Expand Down
4 changes: 4 additions & 0 deletions __tests__/reporters/json.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ describe('json reporter', () => {
});
runner.emit('journey:end', {
journey: j1,
timestamp,
status: 'succeeded',
start: 0,
end: 11,
Expand Down Expand Up @@ -225,6 +226,7 @@ describe('json reporter', () => {

runner.emit('journey:end', {
journey: j1,
timestamp,
start: 0,
end: 1,
status: 'failed',
Expand All @@ -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',
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions __tests__/reporters/junit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ describe('junit reporter', () => {
});
runner.emit('journey:end', {
journey: j1,
timestamp,
start: 0,
status: 'failed',
options: {},
Expand Down Expand Up @@ -115,6 +116,7 @@ describe('junit reporter', () => {
});
runner.emit('journey:end', {
journey: j1,
timestamp,
start: 0,
status: 'failed',
options: {},
Expand Down
1 change: 1 addition & 0 deletions src/core/gatherer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export class Gatherer {
static browser: ChromiumBrowser;

static async setupDriver(options: RunOptions): Promise<Driver> {
log('Gatherer: setup driver');
const { wsEndpoint, playwrightOptions, networkConditions } = options;

if (Gatherer.browser == null) {
Expand Down
14 changes: 11 additions & 3 deletions src/core/runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ interface Events {
JourneyResult & {
journey: Journey;
options: RunOptions;
timestamp: number;
};
'journey:end:reported': unknown;
'step:start': { journey: Journey; step: Step };
Expand All @@ -149,8 +150,12 @@ export default class Runner extends EventEmitter {
static screenshotPath = join(CACHE_PATH, 'screenshots');

static async createContext(options: RunOptions): Promise<JourneyContext> {
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
Expand Down Expand Up @@ -339,14 +344,16 @@ 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', {
journey,
status,
error,
start,
end: monotonicTimeInSeconds(),
end,
timestamp: getTimestamp(),
options,
...pluginOutput,
browserconsole: status == 'failed' ? pluginOutput.browserconsole : [],
Expand Down Expand Up @@ -378,6 +385,7 @@ export default class Runner extends EventEmitter {
};
this.emit('journey:end', {
journey,
timestamp: getTimestamp(),
start,
options,
end: monotonicTimeInSeconds(),
Expand All @@ -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 = {
Expand Down
2 changes: 2 additions & 0 deletions src/reporters/json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,7 @@ export default class JSONReporter extends BaseReporter {
'journey:end',
async ({
journey,
timestamp,
start,
end,
networkinfo,
Expand Down Expand Up @@ -501,6 +502,7 @@ export default class JSONReporter extends BaseReporter {
this.writeJSON({
type: 'journey/end',
journey,
timestamp,
error,
payload: {
start,
Expand Down

0 comments on commit cdcf690

Please sign in to comment.