Repository: elastic/synthetics (ts)

Issue:
rewrite screenshots blocks timestamp with creation time 
+ Currently screenshot block `timestamp` is based on screenshot blob construction time instead of when the screenshot was taken. As a result, the screenshot timestamp would be greater than the journey/end timestamp which is not true. 


### Wrong order
```
-- step/end timestamp
-- journey/end timestamp

--- screenshot/block timestamp
--- screenshot/block timestamp

-- end timestamp
```

#### Correct order
```
-- screenshot/block timestamp
-- screenshot/block timestamp

-- step/end timestamp
-- journey/end timestamp
-- end timestamp
```




Pull request:
fix: ensure timestamps of events are inorder
+ fix #411 

Patch:
diff --git a/src/common_types.ts b/src/common_types.ts
index b48baf4..1550d8f 100644
--- a/src/common_types.ts
+++ b/src/common_types.ts
@@ -94,6 +94,12 @@ export type BrowserInfo = {
   version: string;
 };
 
+export type Screenshot = {
+  timestamp: number;
+  step: Step;
+  data: string;
+};
+
 export type NetworkInfo = {
   url: string;
   browser: BrowserInfo;
diff --git a/src/core/runner.ts b/src/core/runner.ts
index 93a2838..6fc3bed 100644
--- a/src/core/runner.ts
+++ b/src/core/runner.ts
@@ -48,6 +48,7 @@ import {
   HooksArgs,
   PlaywrightOptions,
   Driver,
+  Screenshot,
 } from '../common_types';
 import { PageMetrics, PluginManager } from '../plugins';
 import { PerformanceManager } from '../plugins';
@@ -73,13 +74,12 @@ export type RunOptions = Omit<
   reporter?: CliArgs['reporter'] | Reporter;
 };
 
-type BaseContext = {
+type HookType = 'beforeAll' | 'afterAll';
+export type SuiteHooks = Record<HookType, Array<HooksCallback>>;
+
+type JourneyContext = {
   params?: Params;
   start: number;
-  end?: number;
-};
-
-type JourneyContext = BaseContext & {
   driver: Driver;
   pluginManager: PluginManager;
 };
@@ -103,8 +103,16 @@ type JourneyResult = {
 
 type RunResult = Record<string, JourneyResult>;
 
-type HookType = 'beforeAll' | 'afterAll';
-export type SuiteHooks = Record<HookType, Array<HooksCallback>>;
+interface StepEvent {
+  step: Step;
+  journey: Journey;
+}
+
+interface JourneyEvent {
+  journey: Journey;
+  timestamp: number;
+  params?: Params;
+}
 
 interface Events {
   start: {
@@ -114,25 +122,21 @@ interface Events {
   'journey:register': {
     journey: Journey;
   };
-  'journey:start': {
-    journey: Journey;
-    timestamp: number;
-    params: Params;
-  };
-  'journey:end': BaseContext &
+  'journey:start': JourneyEvent;
+  'journey:end': JourneyEvent &
     JourneyResult & {
-      journey: Journey;
+      start: number;
+      end: number;
       options: RunOptions;
       timestamp: number;
     };
   'journey:end:reported': unknown;
-  'step:start': { journey: Journey; step: Step };
-  'step:end': StepResult & {
-    start: number;
-    end: number;
-    journey: Journey;
-    step: Step;
-  };
+  'step:start': StepEvent;
+  'step:end': StepEvent &
+    StepResult & {
+      start: number;
+      end: number;
+    };
   end: unknown;
 }
 
@@ -185,12 +189,14 @@ export default class Runner extends EventEmitter {
      */
     if (buffer) {
       const fileName = `${generateUniqueId()}.json`;
+      const screenshot: Screenshot = {
+        step,
+        timestamp: getTimestamp(),
+        data: buffer.toString('base64'),
+      };
       await writeFileAsync(
         join(Runner.screenshotPath, fileName),
-        JSON.stringify({
-          step,
-          data: buffer.toString('base64'),
-        })
+        JSON.stringify(screenshot)
       );
     }
   }
diff --git a/src/reporters/json.ts b/src/reporters/json.ts
index e484499..69a3fb9 100644
--- a/src/reporters/json.ts
+++ b/src/reporters/json.ts
@@ -45,6 +45,7 @@ import {
   StatusValue,
   PerfMetrics,
   Params,
+  Screenshot,
 } from '../common_types';
 import { Protocol } from 'playwright-chromium/types/protocol';
 import { PageMetrics } from '../plugins';
@@ -326,14 +327,14 @@ export async function getScreenshotBlocks(screenshot: Buffer) {
  */
 export async function gatherScreenshots(
   screenshotsPath: string,
-  callback: (step: Step, data: string) => Promise<void>
+  callback: (data: Screenshot) => Promise<void>
 ) {
   if (isDirectory(screenshotsPath)) {
     await totalist(screenshotsPath, async (_, absPath) => {
       try {
         const content = readFileSync(absPath, 'utf8');
-        const { step, data } = JSON.parse(content);
-        await callback(step, data);
+        const screenshot: Screenshot = JSON.parse(content);
+        await callback(screenshot);
       } catch (_) {
         // TODO: capture progarammatic synthetic errors under different type
       }
@@ -451,15 +452,17 @@ export default class JSONReporter extends BaseReporter {
         if (writeScreenshots) {
           await gatherScreenshots(
             join(CACHE_PATH, 'screenshots'),
-            async (step, data) => {
+            async screenshot => {
+              const { data, timestamp, step } = screenshot;
               if (!data) {
                 return;
               }
               if (ssblocks) {
-                await this.writeScreenshotBlocks(journey, step, data);
+                await this.writeScreenshotBlocks(journey, screenshot);
               } else {
                 this.writeJSON({
                   type: 'step/screenshot',
+                  timestamp,
                   journey,
                   step,
                   blob: data,
@@ -515,14 +518,15 @@ export default class JSONReporter extends BaseReporter {
     );
   }
 
-  async writeScreenshotBlocks(journey: Journey, step: Step, data: string) {
+  async writeScreenshotBlocks(journey: Journey, screenshot: Screenshot) {
     const { blob_mime, blocks, reference } = await getScreenshotBlocks(
-      Buffer.from(data, 'base64')
+      Buffer.from(screenshot.data, 'base64')
     );
     for (let i = 0; i < blocks.length; i++) {
       const block = blocks[i];
       this.writeJSON({
         type: 'screenshot/block',
+        timestamp: screenshot.timestamp,
         _id: block.id,
         blob: block.blob,
         blob_mime,
@@ -530,8 +534,9 @@ export default class JSONReporter extends BaseReporter {
     }
     this.writeJSON({
       type: 'step/screenshot_ref',
+      timestamp: screenshot.timestamp,
       journey,
-      step,
+      step: screenshot.step,
       root_fields: {
         screenshot_ref: reference,
       },


Test patch:
diff --git a/__tests__/core/runner.test.ts b/__tests__/core/runner.test.ts
index 146880e..3262672 100644
--- a/__tests__/core/runner.test.ts
+++ b/__tests__/core/runner.test.ts
@@ -655,4 +655,39 @@ describe('runner', () => {
       },
     });
   });
+
+  it('run - timestamps must be in order', async () => {
+    const j1 = journey('journey1', async ({ page }) => {
+      step('step1', async () => {
+        await page.goto(server.TEST_PAGE);
+      });
+    });
+    runner.addJourney(j1);
+    await runner.run({
+      reporter: 'json',
+      screenshots: 'on',
+      filmstrips: true,
+      network: true,
+      wsEndpoint,
+      outfd: fs.openSync(dest, 'w'),
+    });
+
+    const events = readAndCloseStreamJson().map(event => ({
+      type: event.type,
+      timestamp: event['@timestamp'],
+    }));
+    // sort the events as written order might be different
+    events.sort((a, b) => a.timestamp - b.timestamp);
+    const realEventsOrder = [
+      'synthetics/metadata',
+      'journey/start',
+      'journey/network_info',
+      'step/screenshot',
+      'step/filmstrips',
+      'step/end',
+      'journey/end',
+    ];
+    const collectOrder = events.map(event => event.type);
+    expect(collectOrder).toEqual(realEventsOrder);
+  });
 });
diff --git a/__tests__/reporters/__snapshots__/json.test.ts.snap b/__tests__/reporters/__snapshots__/json.test.ts.snap
index 5086664..db06edd 100644
--- a/__tests__/reporters/__snapshots__/json.test.ts.snap
+++ b/__tests__/reporters/__snapshots__/json.test.ts.snap
@@ -342,7 +342,7 @@ exports[`json reporter screenshots write block & reference docs 1`] = `
 {\\"type\\":\\"screenshot/block\\",\\"_id\\":\\"e89af7cc2cae152df54ccf091793db64b3dfe995\\",\\"@timestamp\\":1600300800000000,\\"root_fields\\":{\\"os\\":{\\"platform\\":\\"darwin\\"},\\"package\\":{\\"name\\":\\"@elastic/synthetics\\",\\"version\\":\\"0.0.1\\"}},\\"blob\\":\\"/9j/2wBDAAYEBQYFBAYGBQYHBwYIChAKCgkJChQODwwQFxQYGBcUFhYaHSUfGhsjHBYWICwgIyYnKSopGR8tMC0oMCUoKSj/2wBDAQcHBwoIChMKChMoGhYaKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCj/wAARCABaAKADASIAAhEBAxEB/8QAFQABAQAAAAAAAAAAAAAAAAAAAAj/xAAUEAEAAAAAAAAAAAAAAAAAAAAA/8QAFAEBAAAAAAAAAAAAAAAAAAAAAP/EABQRAQAAAAAAAAAAAAAAAAAAAAD/2gAMAwEAAhEDEQA/AKcAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAB//9k=\\",\\"blob_mime\\":\\"image/jpeg\\",\\"package_version\\":\\"0.0.1\\"}
 {\\"type\\":\\"screenshot/block\\",\\"_id\\":\\"e89af7cc2cae152df54ccf091793db64b3dfe995\\",\\"@timestamp\\":1600300800000000,\\"root_fields\\":{\\"os\\":{\\"platform\\":\\"darwin\\"},\\"package\\":{\\"name\\":\\"@elastic/synthetics\\",\\"version\\":\\"0.0.1\\"}},\\"blob\\":\\"/9j/2wBDAAYEBQYFBAYGBQYHBwYIChAKCgkJChQODwwQFxQYGBcUFhYaHSUfGhsjHBYWICwgIyYnKSopGR8tMC0oMCUoKSj/2wBDAQcHBwoIChMKChMoGhYaKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCj/wAARCABaAKADASIAAhEBAxEB/8QAFQABAQAAAAAAAAAAAAAAAAAAAAj/xAAUEAEAAAAAAAAAAAAAAAAAAAAA/8QAFAEBAAAAAAAAAAAAAAAAAAAAAP/EABQRAQAAAAAAAAAAAAAAAAAAAAD/2gAMAwEAAhEDEQA/AKcAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAB//9k=\\",\\"blob_mime\\":\\"image/jpeg\\",\\"package_version\\":\\"0.0.1\\"}
 {\\"type\\":\\"step/screenshot_ref\\",\\"@timestamp\\":1600300800000000,\\"journey\\":{\\"name\\":\\"j1\\",\\"id\\":\\"j1\\"},\\"step\\":{\\"name\\":\\"launch app\\",\\"index\\":1},\\"root_fields\\":{\\"screenshot_ref\\":{\\"width\\":1280,\\"height\\":720,\\"blocks\\":[{\\"hash\\":\\"e89af7cc2cae152df54ccf091793db64b3dfe995\\",\\"top\\":0,\\"left\\":0,\\"width\\":160,\\"height\\":90},{\\"hash\\":\\"e89af7cc2cae152df54ccf091793db64b3dfe995\\",\\"top\\":0,\\"left\\":160,\\"width\\":160,\\"height\\":90},{\\"hash\\":\\"e89af7cc2cae152df54ccf091793db64b3dfe995\\",\\"top\\":0,\\"left\\":320,\\"width\\":160,\\"height\\":90},{\\"hash\\":\\"7207d2da8fc8a9423ea2e38501061ba30dca2e49\\",\\"top\\":0,\\"left\\":480,\\"width\\":160,\\"height\\":90},{\\"hash\\":\\"c895742d0c552bb1e90bb9054dce0a207e0612f4\\",\\"top\\":0,\\"left\\":640,\\"width\\":160,\\"height\\":90},{\\"hash\\":\\"e89af7cc2cae152df54ccf091793db64b3dfe995\\",\\"top\\":0,\\"left\\":800,\\"width\\":160,\\"height\\":90},{\\"hash\\":\\"e89af7cc2cae152df54ccf091793db64b3dfe995\\",\\"top\\":0,\\"left\\":960,\\"width\\":160,\\"height\\":90},{\\"hash\\":\\"e89af7cc2cae152df54ccf091793db64b3dfe995\\",\\"top\\":0,\\"left\\":1120,\\"width\\":160,\\"height\\":90},{\\"hash\\":\\"e89af7cc2cae152df54ccf091793db64b3dfe995\\",\\"top\\":90,\\"left\\":0,\\"width\\":160,\\"height\\":90},{\\"hash\\":\\"e89af7cc2cae152df54ccf091793db64b3dfe995\\",\\"top\\":90,\\"left\\":160,\\"width\\":160,\\"height\\":90},{\\"hash\\":\\"8dab22ef3ba33256e102c7755d6d05309d447a5d\\",\\"top\\":90,\\"left\\":320,\\"width\\":160,\\"height\\":90},{\\"hash\\":\\"0503e01e69b834685b61bb12b897189f70b7f8cf\\",\\"top\\":90,\\"left\\":480,\\"width\\":160,\\"height\\":90},{\\"hash\\":\\"1e2e95c527b7911704f108caa2dc124b71a6906c\\",\\"top\\":90,\\"left\\":640,\\"width\\":160,\\"height\\":90},{\\"hash\\":\\"6bb91d0bcccfe17810c585ff9676da9bf060e7ea\\",\\"top\\":90,\\"left\\":800,\\"width\\":160,\\"height\\":90},{\\"hash\\":\\"e89af7cc2cae152df54ccf091793db64b3dfe995\\",\\"top\\":90,\\"left\\":960,\\"width\\":160,\\"height\\":90},{\\"hash\\":\\"e89af7cc2cae152df54ccf091793db64b3dfe995\\",\\"top\\":90,\\"left\\":1120,\\"width\\":160,\\"height\\":90},{\\"hash\\":\\"e89af7cc2cae152df54ccf091793db64b3dfe995\\",\\"top\\":180,\\"left\\":0,\\"width\\":160,\\"height\\":90},{\\"hash\\":\\"e89af7cc2cae152df54ccf091793db64b3dfe995\\",\\"top\\":180,\\"left\\":160,\\"width\\":160,\\"height\\":90},{\\"hash\\":\\"4bef2a34c082065f7fd8a9246be3b82265640151\\",\\"top\\":180,\\"left\\":320,\\"width\\":160,\\"height\\":90},{\\"hash\\":\\"166035c43b7ec64602a23cecb800d72d07a8fd07\\",\\"top\\":180,\\"left\\":480,\\"width\\":160,\\"height\\":90},{\\"hash\\":\\"5da56b5b7ff6d979000b0e6c3e5047a07eb746a9\\",\\"top\\":180,\\"left\\":640,\\"width\\":160,\\"height\\":90},{\\"hash\\":\\"2cd55289e3819c419182ad42af7b0e017ef252ec\\",\\"top\\":180,\\"left\\":800,\\"width\\":160,\\"height\\":90},{\\"hash\\":\\"e89af7cc2cae152df54ccf091793db64b3dfe995\\",\\"top\\":180,\\"left\\":960,\\"width\\":160,\\"height\\":90},{\\"hash\\":\\"e89af7cc2cae152df54ccf091793db64b3dfe995\\",\\"top\\":180,\\"left\\":1120,\\"width\\":160,\\"height\\":90},{\\"hash\\":\\"e89af7cc2cae152df54ccf091793db64b3dfe995\\",\\"top\\":270,\\"left\\":0,\\"width\\":160,\\"height\\":90},{\\"hash\\":\\"e89af7cc2cae152df54ccf091793db64b3dfe995\\",\\"top\\":270,\\"left\\":160,\\"width\\":160,\\"height\\":90},{\\"hash\\":\\"e89af7cc2cae152df54ccf091793db64b3dfe995\\",\\"top\\":270,\\"left\\":320,\\"width\\":160,\\"height\\":90},{\\"hash\\":\\"fead29b7726776d52be4fa448f1e0c603f89ea21\\",\\"top\\":270,\\"left\\":480,\\"width\\":160,\\"height\\":90},{\\"hash\\":\\"07b755d38bae03aac9cfd6c0f10d98387d81026d\\",\\"top\\":270,\\"left\\":640,\\"width\\":160,\\"height\\":90},{\\"hash\\":\\"e89af7cc2cae152df54ccf091793db64b3dfe995\\",\\"top\\":270,\\"left\\":800,\\"width\\":160,\\"height\\":90},{\\"hash\\":\\"e89af7cc2cae152df54ccf091793db64b3dfe995\\",\\"top\\":270,\\"left\\":960,\\"width\\":160,\\"height\\":90},{\\"hash\\":\\"e89af7cc2cae152df54ccf091793db64b3dfe995\\",\\"top\\":270,\\"left\\":1120,\\"width\\":160,\\"height\\":90},{\\"hash\\":\\"e89af7cc2cae152df54ccf091793db64b3dfe995\\",\\"top\\":360,\\"left\\":0,\\"width\\":160,\\"height\\":90},{\\"hash\\":\\"e89af7cc2cae152df54ccf091793db64b3dfe995\\",\\"top\\":360,\\"left\\":160,\\"width\\":160,\\"height\\":90},{\\"hash\\":\\"e89af7cc2cae152df54ccf091793db64b3dfe995\\",\\"top\\":360,\\"left\\":320,\\"width\\":160,\\"height\\":90},{\\"hash\\":\\"e89af7cc2cae152df54ccf091793db64b3dfe995\\",\\"top\\":360,\\"left\\":480,\\"width\\":160,\\"height\\":90},{\\"hash\\":\\"e89af7cc2cae152df54ccf091793db64b3dfe995\\",\\"top\\":360,\\"left\\":640,\\"width\\":160,\\"height\\":90},{\\"hash\\":\\"e89af7cc2cae152df54ccf091793db64b3dfe995\\",\\"top\\":360,\\"left\\":800,\\"width\\":160,\\"height\\":90},{\\"hash\\":\\"e89af7cc2cae152df54ccf091793db64b3dfe995\\",\\"top\\":360,\\"left\\":960,\\"width\\":160,\\"height\\":90},{\\"hash\\":\\"e89af7cc2cae152df54ccf091793db64b3dfe995\\",\\"top\\":360,\\"left\\":1120,\\"width\\":160,\\"height\\":90},{\\"hash\\":\\"e89af7cc2cae152df54ccf091793db64b3dfe995\\",\\"top\\":450,\\"left\\":0,\\"width\\":160,\\"height\\":90},{\\"hash\\":\\"e89af7cc2cae152df54ccf091793db64b3dfe995\\",\\"top\\":450,\\"left\\":160,\\"width\\":160,\\"height\\":90},{\\"hash\\":\\"e89af7cc2cae152df54ccf091793db64b3dfe995\\",\\"top\\":450,\\"left\\":320,\\"width\\":160,\\"height\\":90},{\\"hash\\":\\"e89af7cc2cae152df54ccf091793db64b3dfe995\\",\\"top\\":450,\\"left\\":480,\\"width\\":160,\\"height\\":90},{\\"hash\\":\\"e89af7cc2cae152df54ccf091793db64b3dfe995\\",\\"top\\":450,\\"left\\":640,\\"width\\":160,\\"height\\":90},{\\"hash\\":\\"e89af7cc2cae152df54ccf091793db64b3dfe995\\",\\"top\\":450,\\"left\\":800,\\"width\\":160,\\"height\\":90},{\\"hash\\":\\"e89af7cc2cae152df54ccf091793db64b3dfe995\\",\\"top\\":450,\\"left\\":960,\\"width\\":160,\\"height\\":90},{\\"hash\\":\\"e89af7cc2cae152df54ccf091793db64b3dfe995\\",\\"top\\":450,\\"left\\":1120,\\"width\\":160,\\"height\\":90},{\\"hash\\":\\"e89af7cc2cae152df54ccf091793db64b3dfe995\\",\\"top\\":540,\\"left\\":0,\\"width\\":160,\\"height\\":90},{\\"hash\\":\\"e89af7cc2cae152df54ccf091793db64b3dfe995\\",\\"top\\":540,\\"left\\":160,\\"width\\":160,\\"height\\":90},{\\"hash\\":\\"e89af7cc2cae152df54ccf091793db64b3dfe995\\",\\"top\\":540,\\"left\\":320,\\"width\\":160,\\"height\\":90},{\\"hash\\":\\"e89af7cc2cae152df54ccf091793db64b3dfe995\\",\\"top\\":540,\\"left\\":480,\\"width\\":160,\\"height\\":90},{\\"hash\\":\\"e89af7cc2cae152df54ccf091793db64b3dfe995\\",\\"top\\":540,\\"left\\":640,\\"width\\":160,\\"height\\":90},{\\"hash\\":\\"e89af7cc2cae152df54ccf091793db64b3dfe995\\",\\"top\\":540,\\"left\\":800,\\"width\\":160,\\"height\\":90},{\\"hash\\":\\"e89af7cc2cae152df54ccf091793db64b3dfe995\\",\\"top\\":540,\\"left\\":960,\\"width\\":160,\\"height\\":90},{\\"hash\\":\\"e89af7cc2cae152df54ccf091793db64b3dfe995\\",\\"top\\":540,\\"left\\":1120,\\"width\\":160,\\"height\\":90},{\\"hash\\":\\"e89af7cc2cae152df54ccf091793db64b3dfe995\\",\\"top\\":630,\\"left\\":0,\\"width\\":160,\\"height\\":90},{\\"hash\\":\\"e89af7cc2cae152df54ccf091793db64b3dfe995\\",\\"top\\":630,\\"left\\":160,\\"width\\":160,\\"height\\":90},{\\"hash\\":\\"e89af7cc2cae152df54ccf091793db64b3dfe995\\",\\"top\\":630,\\"left\\":320,\\"width\\":160,\\"height\\":90},{\\"hash\\":\\"e89af7cc2cae152df54ccf091793db64b3dfe995\\",\\"top\\":630,\\"left\\":480,\\"width\\":160,\\"height\\":90},{\\"hash\\":\\"e89af7cc2cae152df54ccf091793db64b3dfe995\\",\\"top\\":630,\\"left\\":640,\\"width\\":160,\\"height\\":90},{\\"hash\\":\\"e89af7cc2cae152df54ccf091793db64b3dfe995\\",\\"top\\":630,\\"left\\":800,\\"width\\":160,\\"height\\":90},{\\"hash\\":\\"e89af7cc2cae152df54ccf091793db64b3dfe995\\",\\"top\\":630,\\"left\\":960,\\"width\\":160,\\"height\\":90},{\\"hash\\":\\"e89af7cc2cae152df54ccf091793db64b3dfe995\\",\\"top\\":630,\\"left\\":1120,\\"width\\":160,\\"height\\":90}]},\\"os\\":{\\"platform\\":\\"darwin\\"},\\"package\\":{\\"name\\":\\"@elastic/synthetics\\",\\"version\\":\\"0.0.1\\"}},\\"package_version\\":\\"0.0.1\\"}
-{\\"type\\":\\"journey/end\\",\\"@timestamp\\":1600300800000000,\\"journey\\":{\\"name\\":\\"j1\\",\\"id\\":\\"j1\\",\\"status\\":\\"failed\\"},\\"root_fields\\":{\\"os\\":{\\"platform\\":\\"darwin\\"},\\"package\\":{\\"name\\":\\"@elastic/synthetics\\",\\"version\\":\\"0.0.1\\"}},\\"payload\\":{\\"start\\":0,\\"status\\":\\"failed\\"},\\"package_version\\":\\"0.0.1\\"}
+{\\"type\\":\\"journey/end\\",\\"@timestamp\\":1600300800000000,\\"journey\\":{\\"name\\":\\"j1\\",\\"id\\":\\"j1\\",\\"status\\":\\"failed\\"},\\"root_fields\\":{\\"os\\":{\\"platform\\":\\"darwin\\"},\\"package\\":{\\"name\\":\\"@elastic/synthetics\\",\\"version\\":\\"0.0.1\\"}},\\"payload\\":{\\"start\\":0,\\"end\\":2,\\"status\\":\\"failed\\"},\\"package_version\\":\\"0.0.1\\"}
 "
 `;
 
diff --git a/__tests__/reporters/json.test.ts b/__tests__/reporters/json.test.ts
index adade9d..b9d93c9 100644
--- a/__tests__/reporters/json.test.ts
+++ b/__tests__/reporters/json.test.ts
@@ -276,7 +276,7 @@ describe('json reporter', () => {
     const screenshotsDir = join(FIXTURES_DIR, 'screenshots');
     const collectScreenshots = async () => {
       const screenshots = [];
-      await gatherScreenshots(screenshotsDir, async (_, data) => {
+      await gatherScreenshots(screenshotsDir, async ({ data }) => {
         const result = await getScreenshotBlocks(Buffer.from(data, 'base64'));
         screenshots.push(result);
       });
@@ -306,6 +306,7 @@ describe('json reporter', () => {
         journey: j1,
         timestamp,
         start: 0,
+        end: 2,
         status,
         options,
       });
diff --git a/__tests__/reporters/junit.test.ts b/__tests__/reporters/junit.test.ts
index 8ce7d0a..c41ecf6 100644
--- a/__tests__/reporters/junit.test.ts
+++ b/__tests__/reporters/junit.test.ts
@@ -83,6 +83,7 @@ describe('junit reporter', () => {
       journey: j1,
       timestamp,
       start: 0,
+      end: 2,
       status: 'failed',
       options: {},
     });
@@ -118,6 +119,7 @@ describe('junit reporter', () => {
       journey: j1,
       timestamp,
       start: 0,
+      end: 2,
       status: 'failed',
       options: {},
     });