Repository: elastic/synthetics (ts)

Issue:
Journey callbacks shouldn't be async
`journey()` callbacks are currently forced to be async by the types, but best I can tell we shouldn't be doing any async work in those callbacks, right? All async work should be wrapped in a `step()` and then executed by synthetics. I think that would be more obvious if the types required a `void` return type for the callback.

Pull request:
fix: keep journey callback to be sync
+ fix #256 
+ Updated tests which was expecting async all over the place. 

Patch:
diff --git a/examples/todos/advanced.journey.ts b/examples/todos/advanced.journey.ts
index 213dac1..1abc12a 100644
--- a/examples/todos/advanced.journey.ts
+++ b/examples/todos/advanced.journey.ts
@@ -7,7 +7,7 @@ import {
   destroyTaskStep,
 } from './helpers';
 
-journey('addition and completion of single task', async ({ page }) => {
+journey('addition and completion of single task', ({ page }) => {
   const testText = "Don't put salt in your eyes";
 
   loadAppStep(page);
@@ -18,7 +18,7 @@ journey('addition and completion of single task', async ({ page }) => {
   assertTaskListSizeStep(page, 0);
 });
 
-journey('adding and removing multiple tasks', async ({ page }) => {
+journey('adding and removing multiple tasks', ({ page }) => {
   const testTasks = ['Task 1', 'Task 2', 'Task 3'];
 
   loadAppStep(page);
diff --git a/examples/todos/basic.journey.ts b/examples/todos/basic.journey.ts
index c24fdff..c22e26c 100644
--- a/examples/todos/basic.journey.ts
+++ b/examples/todos/basic.journey.ts
@@ -2,7 +2,7 @@ import { journey, step } from '@elastic/synthetics';
 import { deepStrictEqual } from 'assert';
 import { join } from 'path';
 
-journey('check if title is present', async ({ page }) => {
+journey('check if title is present', ({ page }) => {
   step('launch app', async () => {
     const path = 'file://' + join(__dirname, 'app', 'index.html');
     await page.goto(path);
@@ -14,7 +14,7 @@ journey('check if title is present', async ({ page }) => {
   });
 });
 
-journey('check if input placeholder is correct', async ({ page }) => {
+journey('check if input placeholder is correct', ({ page }) => {
   step('launch app', async () => {
     const path = 'file://' + join(__dirname, 'app', 'index.html');
     await page.goto(path);
diff --git a/src/core/runner.ts b/src/core/runner.ts
index 062b2ab..66d0368 100644
--- a/src/core/runner.ts
+++ b/src/core/runner.ts
@@ -252,7 +252,7 @@ export default class Runner {
     return results;
   }
 
-  async registerJourney(journey: Journey, context: JourneyContext) {
+  registerJourney(journey: Journey, context: JourneyContext) {
     this.currentJourney = journey;
     const timestamp = getTimestamp();
     const { params } = context;
@@ -260,7 +260,7 @@ export default class Runner {
     /**
      * Load and register the steps for the current journey
      */
-    await journey.callback({ ...context.driver, params });
+    journey.callback({ ...context.driver, params });
   }
 
   async endJourney(journey, result: JourneyContext & JourneyResult) {
diff --git a/src/dsl/journey.ts b/src/dsl/journey.ts
index 2d61de2..78e077b 100644
--- a/src/dsl/journey.ts
+++ b/src/dsl/journey.ts
@@ -41,7 +41,7 @@ export type JourneyCallback = (options: {
   browser: Browser;
   client: CDPSession;
   params: Record<string, any>;
-}) => Promise<void>;
+}) => void;
 
 export class Journey {
   name: string;


Test patch:
diff --git a/__tests__/core/index.test.ts b/__tests__/core/index.test.ts
index 482d315..4afb423 100644
--- a/__tests__/core/index.test.ts
+++ b/__tests__/core/index.test.ts
@@ -35,7 +35,7 @@ import {
 
 beforeEach(() => runner.reset());
 
-const noop = async () => {};
+const noop = () => {};
 const name = 'journey';
 
 it('add global hooks to runner', () => {
diff --git a/__tests__/core/runner.test.ts b/__tests__/core/runner.test.ts
index ed9bfb0..b621c10 100644
--- a/__tests__/core/runner.test.ts
+++ b/__tests__/core/runner.test.ts
@@ -34,7 +34,7 @@ import { wsEndpoint } from '../utils/test-config';
 
 describe('runner', () => {
   let runner: Runner, server: Server;
-  const noop = async () => {};
+  const noop = () => {};
   const dest = generateTempPath();
   beforeEach(async () => {
     runner = new Runner();
diff --git a/__tests__/dsl/journey.test.ts b/__tests__/dsl/journey.test.ts
index 89ec5f2..1905027 100644
--- a/__tests__/dsl/journey.test.ts
+++ b/__tests__/dsl/journey.test.ts
@@ -25,7 +25,7 @@
 
 import { Journey, Step } from '../../src/dsl';
 
-const noop = async () => {};
+const noop = () => {};
 describe('Journey', () => {
   it('add step to the journey', () => {
     const journey = new Journey({ name: 'j1' }, noop);
diff --git a/__tests__/fixtures/error.journey.ts b/__tests__/fixtures/error.journey.ts
index a19f2bc..093d31e 100644
--- a/__tests__/fixtures/error.journey.ts
+++ b/__tests__/fixtures/error.journey.ts
@@ -25,8 +25,8 @@
 
 import { journey, step } from '../../';
 
-journey('error journey', async ({}) => {
-  step('throw error', async () => {
+journey('error journey', () => {
+  step('throw error', () => {
     throw new Error('boom');
   });
 });
diff --git a/__tests__/fixtures/fake.journey.ts b/__tests__/fixtures/fake.journey.ts
index ade523a..1707ed6 100644
--- a/__tests__/fixtures/fake.journey.ts
+++ b/__tests__/fixtures/fake.journey.ts
@@ -23,8 +23,8 @@
  *
  */
 
-import { journey, step } from '../../dist';
+import { journey, step } from '../../';
 
-journey('fake journey', async ({}) => {
-  step('step1', async () => {});
+journey('fake journey', ({}) => {
+  step('step1', () => {});
 });
diff --git a/__tests__/index.test.ts b/__tests__/index.test.ts
index bc443db..0fdbcc6 100644
--- a/__tests__/index.test.ts
+++ b/__tests__/index.test.ts
@@ -36,8 +36,8 @@ describe('Run', () => {
   });
 
   it('multiple run invokes runner only once', async () => {
-    journey('j1', async () => {});
-    journey('j2', async () => {});
+    journey('j1', () => {});
+    journey('j2', () => {});
     /**
      * call multiple runs in parallel simulating
      * CLI and programmatic API runs
diff --git a/__tests__/reporters/__snapshots__/json.test.ts.snap b/__tests__/reporters/__snapshots__/json.test.ts.snap
index a36d5dc..abc2692 100644
--- a/__tests__/reporters/__snapshots__/json.test.ts.snap
+++ b/__tests__/reporters/__snapshots__/json.test.ts.snap
@@ -278,9 +278,9 @@ Object {
 
 exports[`json reporter writes each step as NDJSON to the FD 1`] = `
 "{\\"type\\":\\"journey/register\\",\\"@timestamp\\":1600300800000000,\\"journey\\":{\\"name\\":\\"j1\\",\\"id\\":\\"j1\\"},\\"root_fields\\":{\\"os\\":{\\"platform\\":\\"darwin\\"},\\"package\\":{\\"name\\":\\"@elastic/synthetics\\",\\"version\\":\\"0.0.1\\"}},\\"package_version\\":\\"0.0.1\\"}
-{\\"type\\":\\"journey/start\\",\\"@timestamp\\":1600300800000000,\\"journey\\":{\\"name\\":\\"j1\\",\\"id\\":\\"j1\\"},\\"root_fields\\":{\\"os\\":{\\"platform\\":\\"darwin\\"},\\"package\\":{\\"name\\":\\"@elastic/synthetics\\",\\"version\\":\\"0.0.1\\"}},\\"payload\\":{\\"params\\":{},\\"source\\":\\"async () => { }\\"},\\"package_version\\":\\"0.0.1\\"}
+{\\"type\\":\\"journey/start\\",\\"@timestamp\\":1600300800000000,\\"journey\\":{\\"name\\":\\"j1\\",\\"id\\":\\"j1\\"},\\"root_fields\\":{\\"os\\":{\\"platform\\":\\"darwin\\"},\\"package\\":{\\"name\\":\\"@elastic/synthetics\\",\\"version\\":\\"0.0.1\\"}},\\"payload\\":{\\"params\\":{},\\"source\\":\\"() => { }\\"},\\"package_version\\":\\"0.0.1\\"}
 {\\"type\\":\\"step/screenshot\\",\\"@timestamp\\":1600300800000000,\\"journey\\":{\\"name\\":\\"j1\\",\\"id\\":\\"j1\\"},\\"step\\":{\\"name\\":\\"s1\\",\\"index\\":1},\\"root_fields\\":{\\"os\\":{\\"platform\\":\\"darwin\\"},\\"package\\":{\\"name\\":\\"@elastic/synthetics\\",\\"version\\":\\"0.0.1\\"}},\\"blob\\":\\"dummy\\",\\"blob_mime\\":\\"image/jpeg\\",\\"package_version\\":\\"0.0.1\\"}
-{\\"type\\":\\"step/end\\",\\"@timestamp\\":1600300800000000,\\"journey\\":{\\"name\\":\\"j1\\",\\"id\\":\\"j1\\"},\\"step\\":{\\"name\\":\\"s1\\",\\"index\\":1,\\"status\\":\\"succeeded\\"},\\"root_fields\\":{\\"os\\":{\\"platform\\":\\"darwin\\"},\\"package\\":{\\"name\\":\\"@elastic/synthetics\\",\\"version\\":\\"0.0.1\\"}},\\"payload\\":{\\"source\\":\\"async () => { }\\",\\"start\\":0,\\"end\\":10,\\"url\\":\\"dummy\\",\\"status\\":\\"succeeded\\"},\\"url\\":\\"dummy\\",\\"package_version\\":\\"0.0.1\\"}
+{\\"type\\":\\"step/end\\",\\"@timestamp\\":1600300800000000,\\"journey\\":{\\"name\\":\\"j1\\",\\"id\\":\\"j1\\"},\\"step\\":{\\"name\\":\\"s1\\",\\"index\\":1,\\"status\\":\\"succeeded\\"},\\"root_fields\\":{\\"os\\":{\\"platform\\":\\"darwin\\"},\\"package\\":{\\"name\\":\\"@elastic/synthetics\\",\\"version\\":\\"0.0.1\\"}},\\"payload\\":{\\"source\\":\\"() => { }\\",\\"start\\":0,\\"end\\":10,\\"url\\":\\"dummy\\",\\"status\\":\\"succeeded\\"},\\"url\\":\\"dummy\\",\\"package_version\\":\\"0.0.1\\"}
 {\\"type\\":\\"journey/network_info\\",\\"@timestamp\\":1600300800000000,\\"journey\\":{\\"name\\":\\"j1\\",\\"id\\":\\"j1\\"},\\"root_fields\\":{\\"user_agent\\":{},\\"http\\":{\\"request\\":{\\"body\\":{\\"bytes\\":0,\\"content\\":\\"\\"}}},\\"os\\":{\\"platform\\":\\"darwin\\"},\\"package\\":{\\"name\\":\\"@elastic/synthetics\\",\\"version\\":\\"0.0.1\\"}},\\"payload\\":{\\"browser\\":{},\\"is_navigation_request\\":true},\\"package_version\\":\\"0.0.1\\"}
 {\\"type\\":\\"journey/filmstrips\\",\\"@timestamp\\":1600300800000000,\\"journey\\":{\\"name\\":\\"j1\\",\\"id\\":\\"j1\\"},\\"root_fields\\":{\\"os\\":{\\"platform\\":\\"darwin\\"},\\"package\\":{\\"name\\":\\"@elastic/synthetics\\",\\"version\\":\\"0.0.1\\"}},\\"payload\\":{\\"index\\":0,\\"startTime\\":392583.998697,\\"ts\\":392583998697},\\"blob\\":\\"dummy\\",\\"package_version\\":\\"0.0.1\\"}
 {\\"type\\":\\"journey/end\\",\\"@timestamp\\":1600300800000000,\\"journey\\":{\\"name\\":\\"j1\\",\\"id\\":\\"j1\\",\\"status\\":\\"succeeded\\"},\\"root_fields\\":{\\"os\\":{\\"platform\\":\\"darwin\\"},\\"package\\":{\\"name\\":\\"@elastic/synthetics\\",\\"version\\":\\"0.0.1\\"}},\\"payload\\":{\\"start\\":0,\\"end\\":11,\\"status\\":\\"succeeded\\"},\\"package_version\\":\\"0.0.1\\"}
diff --git a/__tests__/reporters/base.test.ts b/__tests__/reporters/base.test.ts
index f3656b2..c9ca764 100644
--- a/__tests__/reporters/base.test.ts
+++ b/__tests__/reporters/base.test.ts
@@ -45,7 +45,7 @@ describe('base reporter', () => {
     jest.spyOn(helpers, 'now').mockImplementation(() => 0);
     const { stream } = new BaseReporter(runner, { fd: fs.openSync(dest, 'w') });
     runner.emit('start', { numJourneys: 1 });
-    const j1 = journey('j1', async () => {});
+    const j1 = journey('j1', () => {});
     runner.emit('journey:start', {
       journey: j1,
       params: {},
@@ -60,7 +60,7 @@ describe('base reporter', () => {
       journey: j1,
       status: 'failed',
       error,
-      step: step('s1', async () => {}),
+      step: step('s1', () => {}),
       url: 'dummy',
       start: 0,
       end: 1,
diff --git a/__tests__/reporters/json.test.ts b/__tests__/reporters/json.test.ts
index de520bb..cf632e3 100644
--- a/__tests__/reporters/json.test.ts
+++ b/__tests__/reporters/json.test.ts
@@ -42,7 +42,7 @@ jest.mock(
 
 describe('json reporter', () => {
   let dest: string;
-  const j1 = journey('j1', async () => {});
+  const j1 = journey('j1', () => {});
   let stream;
   let runner: Runner;
   const timestamp = 1600300800000000;
@@ -107,7 +107,7 @@ describe('json reporter', () => {
     runner.emit('step:end', {
       journey: j1,
       status: 'succeeded',
-      step: step('s1', async () => {}),
+      step: step('s1', () => {}),
       screenshot: 'dummy',
       url: 'dummy',
       start: 0,
@@ -156,7 +156,7 @@ describe('json reporter', () => {
     runner.emit('step:end', {
       journey: j1,
       status: 'failed',
-      step: step('s2', async () => {}),
+      step: step('s2', () => {}),
       screenshot: 'dummy2',
       url: 'dummy2',
       start: 11,
diff --git a/__tests__/reporters/junit.test.ts b/__tests__/reporters/junit.test.ts
index 9cb71f2..bca18bf 100644
--- a/__tests__/reporters/junit.test.ts
+++ b/__tests__/reporters/junit.test.ts
@@ -36,8 +36,8 @@ describe('junit reporter', () => {
   let runner: Runner;
   let stream;
   const timestamp = 1600300800000000;
-  const j1 = journey('j1', async () => {});
-  const s1 = step('s1', async () => {});
+  const j1 = journey('j1', () => {});
+  const s1 = step('s1', () => {});
 
   beforeAll(() => {
     runner = new Runner();
@@ -75,7 +75,7 @@ describe('junit reporter', () => {
     runner.emit('step:end', {
       journey: j1,
       status: 'skipped',
-      step: step('s2', async () => {}),
+      step: step('s2', () => {}),
       start: 0,
       end: 1,
     });