Repository: elastic/synthetics
Pull request #699 (2023-02-08 12:55:06)

chore: remove params from journey/start event payload 
We are pushing params values to journey start document payload. It serves no purpose. So in this PR i am removing those.

apmmachine: 
## :broken_heart: Build Failed


<!-- BUILD BADGES-->
> _the below badges are clickable and redirect to their specific view in the CI or DOCS_
[![Pipeline View](https://img.shields.io/badge/pipeline-pipeline%20-green)](https://apm-ci.elastic.co/blue/organizations/jenkins/apm-agent-rum%2Felastic-synthetics%2FPR-699/detail/PR-699/1//pipeline) [![Test View](https://img.shields.io/badge/test-test-green)](https://apm-ci.elastic.co/blue/organizations/jenkins/apm-agent-rum%2Felastic-synthetics%2FPR-699/detail/PR-699/1//tests) [![Changes](https://img.shields.io/badge/changes-changes-green)](https://apm-ci.elastic.co/blue/organizations/jenkins/apm-agent-rum%2Felastic-synthetics%2FPR-699/detail/PR-699/1//changes) [![Artifacts](https://img.shields.io/badge/artifacts-artifacts-yellow)](https://apm-ci.elastic.co/blue/organizations/jenkins/apm-agent-rum%2Felastic-synthetics%2FPR-699/detail/PR-699/1//artifacts) [![preview](https://img.shields.io/badge/docs-preview-yellowgreen)](http://synthetics_699.docs-preview.app.elstc.co/diff)  [![preview](https://img.shields.io/badge/elastic-observability-blue)](https://ci-stats.elastic.co/app/apm/services/apm-ci/transactions/view?rangeFrom=2023-02-08T12:45:23.544Z&rangeTo=2023-02-08T13:05:23.544Z&transactionName=BUILD+apm-agent-rum%2Felastic-synthetics%2FPR-%7Bnumber%7D&transactionType=job&latencyAggregationType=avg&traceId=317b7bb6d53ee07c8e1d6a0ccadb7fc2&transactionId=d4f5c4a8b6c962fe)

<!-- BUILD SUMMARY-->
<details><summary>Expand to view the summary</summary>
<p>

#### Build stats




* Start Time: 2023-02-08T12:55:23.544+0000


* Duration: 5 min 54 sec





</p>
</details>

<!-- TEST RESULTS IF ANY-->


<!-- STEPS ERRORS IF ANY -->














### Steps errors [![1](https://img.shields.io/badge/1%20-red)](https://apm-ci.elastic.co/blue/organizations/jenkins/apm-agent-rum%2Felastic-synthetics%2FPR-699/detail/PR-699/1//pipeline)
  <details><summary>Expand to view the steps failures</summary>
  <p>


  
  
  
  
##### `Checks linting`
<ul>
<li>Took 0 min 5 sec . View more details <a href="https://apm-ci.elastic.co//blue/rest/organizations/jenkins/pipelines/apm-agent-rum/pipelines/elastic-synthetics/pipelines/PR-699/runs/1/steps/186/log/?start=0">here</a></li>
<li>Description: <code>npm run-script lint</code></l1>
</ul>
  
  </p>
  </details>



## :robot: GitHub comments

<details><summary>Expand to view the GitHub comments</summary>
<p>

To re-run your PR in the CI, just comment with:



- `/test` : Re-trigger the build.




</p>
</details>

<!--COMMENT_GENERATED_WITH_ID_comment.id-->

Patch:
diff --git a/src/options.ts b/src/options.ts
index f954943..8e7c0c1 100644
--- a/src/options.ts
+++ b/src/options.ts
@@ -206,7 +206,7 @@ export function getCommonCommandOpts() {
 
   const pattern = createOption(
     '--pattern <pattern>',
-    'RegExp file patterns to search inside directory'
+    'RegExp pattern to look for journey files that are different from the default (ex: /*.journey.(ts|js)$/)'
   );
   const tags = createOption(
     '--tags <name...>',
diff --git a/src/reporters/base.ts b/src/reporters/base.ts
index fdd9493..abe4581 100644
--- a/src/reporters/base.ts
+++ b/src/reporters/base.ts
@@ -86,7 +86,7 @@ export default class BaseReporter implements Reporter {
     this.write(`\nJourney: ${journey.name}`);
   }
 
-  onStepEnd(journey: Journey, step: Step, result: StepEndResult) {
+  onStepEnd(_: Journey, step: Step, result: StepEndResult) {
     const { status, end, start, error } = result;
     const message = `${symbols[status]}  Step: '${
       step.name
@@ -97,7 +97,7 @@ export default class BaseReporter implements Reporter {
   }
 
   /* eslint-disable @typescript-eslint/no-unused-vars */
-  onJourneyEnd(journey: Journey, { error }: JourneyEndResult) {
+  onJourneyEnd(_: Journey, { error }: JourneyEndResult) {
     const { failed, succeeded, skipped } = this.metrics;
     const total = failed + succeeded + skipped;
     /**
diff --git a/src/reporters/json.ts b/src/reporters/json.ts
index fe67523..944d476 100644
--- a/src/reporters/json.ts
+++ b/src/reporters/json.ts
@@ -45,7 +45,6 @@ import {
   TraceOutput,
   StatusValue,
   PerfMetrics,
-  Params,
   Screenshot,
   StartEvent,
   JourneyStartResult,
@@ -78,7 +77,6 @@ type Payload = {
   url?: string;
   status?: StatusValue;
   pagemetrics?: PageMetrics;
-  params?: Params;
   type?: OutputType;
   text?: string;
   index?: number;
@@ -301,7 +299,7 @@ export async function gatherScreenshots(
 }
 
 export default class JSONReporter extends BaseReporter {
-  onStart(params: StartEvent) {
+  onStart(event: StartEvent) {
     /**
      * report the number of journeys that exists on a suite which
      * could be used for better sharding
@@ -309,11 +307,11 @@ export default class JSONReporter extends BaseReporter {
     this.writeJSON({
       type: 'synthetics/metadata',
       root_fields: {
-        num_journeys: params.numJourneys,
+        num_journeys: event.numJourneys,
       },
-      payload: params.networkConditions
+      payload: event.networkConditions
         ? {
-            network_conditions: params.networkConditions,
+            network_conditions: event.networkConditions,
           }
         : undefined,
     });
@@ -326,15 +324,12 @@ export default class JSONReporter extends BaseReporter {
     });
   }
 
-  override onJourneyStart(
-    journey: Journey,
-    { timestamp, params }: JourneyStartResult
-  ) {
+  override onJourneyStart(journey: Journey, { timestamp }: JourneyStartResult) {
     this.writeJSON({
       type: 'journey/start',
       journey,
       timestamp,
-      payload: { params, source: journey.callback.toString() },
+      payload: { source: journey.callback.toString() },
     });
   }
 


Test patch:
diff --git a/__tests__/cli.test.ts b/__tests__/cli.test.ts
index 560eb8c..514832a 100644
--- a/__tests__/cli.test.ts
+++ b/__tests__/cli.test.ts
@@ -136,28 +136,21 @@ describe('CLI', () => {
     });
 
     it('loads a configuration file when passing a config param', async () => {
-      const output = async () => {
-        const cli = new CLIMock()
-          .stdin(`step('fake step', async () => {})`)
-          .args([
-            '--reporter',
-            'json',
-            '--inline',
-            '--config',
-            join(FIXTURES_DIR, 'synthetics.config.ts'),
-          ])
-          .run({ cwd: FIXTURES_DIR });
-        await cli.waitFor('journey/start');
-        expect(await cli.exitCode).toBe(0);
-        return getJourneyStart(cli.output());
-      };
-
-      expect((await output()).payload).toMatchObject({
-        params: { url: 'non-dev' },
-      });
-      process.env['NODE_ENV'] = 'development';
-      expect((await output()).payload).toMatchObject({
-        params: { url: 'dev' },
+      const cli = new CLIMock(false)
+        .stdin(`step('fake step', async () => {})`)
+        .args([
+          '--reporter',
+          'json',
+          '--inline',
+          '--config',
+          join(FIXTURES_DIR, 'synthetics.config.ts'),
+        ])
+        .run({ cwd: FIXTURES_DIR });
+      await cli.waitFor('synthetics/metadata');
+      expect(await cli.exitCode).toBe(0);
+      const [output] = safeNDJSONParse(cli.output());
+      expect(output.payload).toMatchObject({
+        network_conditions: { latency: 11 },
       });
     });
   });
@@ -282,7 +275,7 @@ describe('CLI', () => {
   });
 
   it('pass dynamic config to journey params', async () => {
-    const getJourneyStart = async () => {
+    const getMetadata = async () => {
       const cli = new CLIMock()
         .args([
           join(FIXTURES_DIR, 'fake.journey.ts'),
@@ -292,27 +285,27 @@ describe('CLI', () => {
           join(FIXTURES_DIR, 'synthetics.config.ts'),
         ])
         .run();
-      await cli.waitFor('journey/start');
+      await cli.waitFor('synthetics/metadata');
       expect(await cli.exitCode).toBe(0);
       return cli.output();
     };
 
-    let [output] = safeNDJSONParse([await getJourneyStart()]);
+    let [output] = safeNDJSONParse([await getMetadata()]);
     expect(output.payload).toMatchObject({
-      params: { url: 'non-dev' },
+      network_conditions: { latency: 11 },
     });
 
     process.env['NODE_ENV'] = 'development';
-    [output] = safeNDJSONParse([await getJourneyStart()]);
+    [output] = safeNDJSONParse([await getMetadata()]);
     expect(output.payload).toMatchObject({
-      params: { url: 'dev' },
+      network_conditions: { latency: 10 },
     });
   });
 
   it('params wins over config params', async () => {
     const cli = new CLIMock()
       .args([
-        join(FIXTURES_DIR, 'fake.journey.ts'),
+        join(FIXTURES_DIR, 'example.journey.ts'),
         '--reporter',
         'json',
         '--config',
@@ -321,12 +314,10 @@ describe('CLI', () => {
         '{"url": "suite-url"}',
       ])
       .run();
-    await cli.waitFor('journey/start');
-    const output = getJourneyStart(cli.output());
-    expect(await cli.exitCode).toBe(0);
-    expect(output.payload).toMatchObject({
-      params: { url: 'suite-url' },
-    });
+    await cli.waitFor('step/end');
+    expect(await cli.exitCode).toBe(1);
+    const [output] = safeNDJSONParse(cli.output());
+    expect(output.error.stack).toContain('suite-url');
   });
 
   it('throw error on modifying params', async () => {
diff --git a/__tests__/config.test.ts b/__tests__/config.test.ts
index 8999db8..ff6aa00 100644
--- a/__tests__/config.test.ts
+++ b/__tests__/config.test.ts
@@ -33,7 +33,7 @@ const FIXTURES_DIR = join(__dirname, 'fixtures');
 describe('Config', () => {
   it('read config based on environment', async () => {
     const configPath = join(FIXTURES_DIR, 'synthetics.config.ts');
-    expect(readConfig('development', configPath)).toEqual({
+    expect(readConfig('development', configPath)).toMatchObject({
       params: {
         url: 'dev',
       },
diff --git a/__tests__/fixtures/synthetics.config.ts b/__tests__/fixtures/synthetics.config.ts
index 1c3d944..8040482 100644
--- a/__tests__/fixtures/synthetics.config.ts
+++ b/__tests__/fixtures/synthetics.config.ts
@@ -31,12 +31,16 @@ module.exports = env => {
     params: {
       url: 'dev',
     },
+    monitor: {
+      throttling: { latency: 10 },
+    },
     playwrightOptions: {
       ...devices['Galaxy S9+'],
     },
   };
-  if (env !== 'development') {
+  if (env !== 'development' && config.params && config.monitor) {
     config.params.url = 'non-dev';
+    config.monitor.throttling = { latency: 11 };
   }
   return config;
 };
diff --git a/__tests__/helper.test.ts b/__tests__/helper.test.ts
index 721f2e0..5f4944e 100644
--- a/__tests__/helper.test.ts
+++ b/__tests__/helper.test.ts
@@ -71,7 +71,7 @@ describe('formatting errors', () => {
 
   ["c'est ne pas une Error", 42, { an: 'object' }].forEach(obj => {
     it(`formats thrown non-error errors like: ${obj}(${typeof obj})`, () => {
-      const formatted = formatError(obj)!;
+      const formatted = formatError(obj);
       expect(formatted.message).toContain(`${obj}`);
       expect(formatted.name).toStrictEqual('');
       expect(formatted.stack).toStrictEqual('');
diff --git a/__tests__/reporters/__snapshots__/json.test.ts.snap b/__tests__/reporters/__snapshots__/json.test.ts.snap
index fa8ec4e..c69156e 100644
--- a/__tests__/reporters/__snapshots__/json.test.ts.snap
+++ b/__tests__/reporters/__snapshots__/json.test.ts.snap
@@ -201,7 +201,7 @@ exports[`json reporter screenshots write block & reference docs 1`] = `
 
 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\\":{\\"environment\\":\\"testing\\"},\\"source\\":\\"() => { }\\"},\\"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\\":{\\"source\\":\\"() => { }\\"},\\"package_version\\":\\"0.0.1\\"}
 {\\"type\\":\\"step/metrics\\",\\"@timestamp\\":1600300800000000,\\"journey\\":{\\"name\\":\\"j1\\",\\"id\\":\\"j1\\"},\\"step\\":{\\"name\\":\\"s1\\",\\"index\\":1},\\"root_fields\\":{\\"browser\\":{\\"relative_trace\\":{\\"name\\":\\"navigationStart\\",\\"type\\":\\"mark\\",\\"start\\":{\\"us\\":3065705158085}}},\\"os\\":{\\"platform\\":\\"darwin\\"},\\"package\\":{\\"name\\":\\"@elastic/synthetics\\",\\"version\\":\\"0.0.1\\"}},\\"package_version\\":\\"0.0.1\\"}
 {\\"type\\":\\"step/metrics\\",\\"@timestamp\\":1600300800000000,\\"journey\\":{\\"name\\":\\"j1\\",\\"id\\":\\"j1\\"},\\"step\\":{\\"name\\":\\"s1\\",\\"index\\":1},\\"root_fields\\":{\\"browser\\":{\\"relative_trace\\":{\\"name\\":\\"firstContentfulPaint\\",\\"type\\":\\"mark\\",\\"start\\":{\\"us\\":3065705560142}}},\\"os\\":{\\"platform\\":\\"darwin\\"},\\"package\\":{\\"name\\":\\"@elastic/synthetics\\",\\"version\\":\\"0.0.1\\"}},\\"package_version\\":\\"0.0.1\\"}
 {\\"type\\":\\"step/metrics\\",\\"@timestamp\\":1600300800000000,\\"journey\\":{\\"name\\":\\"j1\\",\\"id\\":\\"j1\\"},\\"step\\":{\\"name\\":\\"s1\\",\\"index\\":1},\\"root_fields\\":{\\"browser\\":{\\"relative_trace\\":{\\"name\\":\\"layoutShift\\",\\"type\\":\\"mark\\",\\"start\\":{\\"us\\":463045197179},\\"score\\":0.19932291666666668}},\\"os\\":{\\"platform\\":\\"darwin\\"},\\"package\\":{\\"name\\":\\"@elastic/synthetics\\",\\"version\\":\\"0.0.1\\"}},\\"package_version\\":\\"0.0.1\\"}
diff --git a/__tests__/reporters/base.test.ts b/__tests__/reporters/base.test.ts
index 70e91bc..7e9bec8 100644
--- a/__tests__/reporters/base.test.ts
+++ b/__tests__/reporters/base.test.ts
@@ -67,7 +67,6 @@ describe('base reporter', () => {
 
   it('writes each step to the FD', async () => {
     reporter.onJourneyStart(j1, {
-      params: { environment: 'testing' },
       timestamp,
     });
     reporter.onStepEnd(j1, step('s1', helpers.noop), {
@@ -87,7 +86,6 @@ describe('base reporter', () => {
 
   it('render hook errors without steps', async () => {
     reporter.onJourneyStart(j1, {
-      params: { environment: 'testing' },
       timestamp,
     });
     const error = {
diff --git a/__tests__/reporters/json.test.ts b/__tests__/reporters/json.test.ts
index a85124e..cf88cc4 100644
--- a/__tests__/reporters/json.test.ts
+++ b/__tests__/reporters/json.test.ts
@@ -105,7 +105,6 @@ describe('json reporter', () => {
     error.stack = '';
     reporter.onJourneyRegister(j1);
     reporter.onJourneyStart(j1, {
-      params: { environment: 'testing' },
       timestamp,
     });
     reporter.onStepEnd(j1, step('s1', helpers.noop), {
diff --git a/__tests__/reporters/junit.test.ts b/__tests__/reporters/junit.test.ts
index 910ad4e..bb8b1da 100644
--- a/__tests__/reporters/junit.test.ts
+++ b/__tests__/reporters/junit.test.ts
@@ -50,7 +50,6 @@ describe('junit reporter', () => {
 
   it('writes the output to fd', async () => {
     reporter.onJourneyStart(j1, {
-      params: { environment: 'testing' },
       timestamp,
     });
     const error = new Error('Boom');
@@ -91,7 +90,6 @@ describe('junit reporter', () => {
     const filepath = join(__dirname, '../../tmp', 'junit.xml');
     process.env.SYNTHETICS_JUNIT_FILE = filepath;
     reporter.onJourneyStart(j1, {
-      params: { environment: 'testing' },
       timestamp,
     });
     reporter.onStepEnd(j1, s1, {