From fc4fe01d79fb226b54542b0049a7bf83ad85a74e Mon Sep 17 00:00:00 2001 From: vigneshshanmugam Date: Thu, 24 Jun 2021 08:17:18 -0700 Subject: [PATCH] BREAKING CHANGE: remove -e in favor of NODE_ENV --- __tests__/cli.test.ts | 34 +++++++++++++++++++++------------- src/cli.ts | 5 ++--- src/common_types.ts | 1 - src/core/runner.ts | 1 + src/parse_args.ts | 1 - 5 files changed, 24 insertions(+), 18 deletions(-) diff --git a/__tests__/cli.test.ts b/__tests__/cli.test.ts index 45ac0340..40eeba30 100644 --- a/__tests__/cli.test.ts +++ b/__tests__/cli.test.ts @@ -66,21 +66,29 @@ describe('CLI', () => { expect(await cli.exitCode).toBe(0); }); - it('pass config to journey params', async () => { - const cli = new CLIMock([ - join(FIXTURES_DIR, 'fake.journey.ts'), - '--json', - '--config', - join(FIXTURES_DIR, 'synthetics.config.ts'), - '-e', - 'testing', - ]); - await cli.waitFor('journey/start'); - expect(await cli.exitCode).toBe(0); - const output = cli.output(); - expect(JSON.parse(output).payload).toMatchObject({ + it('pass dynamic config to journey params', async () => { + // jest by default sets NODE_ENV to `test` + const original = process.env['NODE_ENV']; + const output = async () => { + const cli = new CLIMock([ + join(FIXTURES_DIR, 'fake.journey.ts'), + '--json', + '--config', + join(FIXTURES_DIR, 'synthetics.config.ts'), + ]); + await cli.waitFor('journey/start'); + expect(await cli.exitCode).toBe(0); + return cli.output(); + }; + + expect(JSON.parse(await output()).payload).toMatchObject({ params: { url: 'non-dev' }, }); + process.env['NODE_ENV'] = 'development'; + expect(JSON.parse(await output()).payload).toMatchObject({ + params: { url: 'dev' }, + }); + process.env['NODE_ENV'] = original; }); it('suite params wins over config params', async () => { diff --git a/src/cli.ts b/src/cli.ts index 7973b339..9062017e 100644 --- a/src/cli.ts +++ b/src/cli.ts @@ -158,10 +158,9 @@ async function prepareSuites(inputs: string[]) { } /** - * Use the NODE_ENV variable to control the environment if its not explicity - * passed from either CLI or through the API + * Use the NODE_ENV variable to control the environment */ - const environment = options.environment || process.env['NODE_ENV']; + const environment = process.env['NODE_ENV'] || 'development'; /** * Validate and handle configs */ diff --git a/src/common_types.ts b/src/common_types.ts index 2417d76f..531f9910 100644 --- a/src/common_types.ts +++ b/src/common_types.ts @@ -119,7 +119,6 @@ export type ScreenshotOptions = 'on' | 'off' | 'only-on-failure'; export type CliArgs = { capability?: Array; config?: string; - environment?: string; outfd?: number; headless?: boolean; screenshots?: ScreenshotOptions; diff --git a/src/core/runner.ts b/src/core/runner.ts index 649a22a7..81d0c3b6 100644 --- a/src/core/runner.ts +++ b/src/core/runner.ts @@ -61,6 +61,7 @@ export type RunOptions = Omit< | 'richEvents' | 'capability' > & { + environment?: string; params?: Params; reporter?: CliArgs['reporter'] | Reporter; }; diff --git a/src/parse_args.ts b/src/parse_args.ts index 61b6788a..d5d32083 100644 --- a/src/parse_args.ts +++ b/src/parse_args.ts @@ -38,7 +38,6 @@ program 'configuration path (default: synthetics.config.js)' ) .option('-s, --suite-params ', 'suite variables', '{}') - .option('-e, --environment ', 'e.g. production', 'development') .option('-j, --json', 'output newline delimited JSON') .addOption( new Option('--reporter ', `output repoter format`).choices(