Skip to content

Commit

Permalink
BREAKING CHANGE: remove -e in favor of NODE_ENV
Browse files Browse the repository at this point in the history
  • Loading branch information
vigneshshanmugam committed Jun 24, 2021
1 parent fc4f9bf commit fc4fe01
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 18 deletions.
34 changes: 21 additions & 13 deletions __tests__/cli.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down
5 changes: 2 additions & 3 deletions src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
1 change: 0 additions & 1 deletion src/common_types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,6 @@ export type ScreenshotOptions = 'on' | 'off' | 'only-on-failure';
export type CliArgs = {
capability?: Array<string>;
config?: string;
environment?: string;
outfd?: number;
headless?: boolean;
screenshots?: ScreenshotOptions;
Expand Down
1 change: 1 addition & 0 deletions src/core/runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ export type RunOptions = Omit<
| 'richEvents'
| 'capability'
> & {
environment?: string;
params?: Params;
reporter?: CliArgs['reporter'] | Reporter;
};
Expand Down
1 change: 0 additions & 1 deletion src/parse_args.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ program
'configuration path (default: synthetics.config.js)'
)
.option('-s, --suite-params <jsonstring>', 'suite variables', '{}')
.option('-e, --environment <envname>', 'e.g. production', 'development')
.option('-j, --json', 'output newline delimited JSON')
.addOption(
new Option('--reporter <value>', `output repoter format`).choices(
Expand Down

0 comments on commit fc4fe01

Please sign in to comment.