Skip to content

Commit

Permalink
feat: add support for rich events flag
Browse files Browse the repository at this point in the history
  • Loading branch information
vigneshshanmugam committed Jun 1, 2021
1 parent ce473d9 commit 890629d
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 4 deletions.
14 changes: 14 additions & 0 deletions __tests__/cli.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,20 @@ describe('CLI', () => {
expect(await cli.exitCode).toBe(0);
});

it('enables rich events on `--rich-events` flag', async () => {
const cli = new CLIMock([
join(FIXTURES_DIR, 'fake.journey.ts'),
'--rich-events',
]);
await cli.waitFor('fake journey');
const output = cli.output();
expect(JSON.parse(output).journey).toEqual({
id: 'fake journey',
name: 'fake journey',
});
expect(await cli.exitCode).toBe(0);
});

it('pass config to journey params', async () => {
const cli = new CLIMock([
join(FIXTURES_DIR, 'fake.journey.ts'),
Expand Down
4 changes: 1 addition & 3 deletions src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ import { stdin, cwd } from 'process';
import { resolve } from 'path';
import { step, journey } from './core';
import { log } from './core/logger';
import program from './parse_args';
import { CliArgs } from './common_types';
import program, { options } from './parse_args';
import {
findPkgJsonByTraversing,
isDepInstalled,
Expand All @@ -40,7 +39,6 @@ import {
import { run } from './';
import { readConfig } from './config';

const options = program.opts() as CliArgs;
const resolvedCwd = cwd();
/**
* Set debug based on DEBUG ENV and -d flags
Expand Down
1 change: 1 addition & 0 deletions src/common_types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,4 +102,5 @@ export type CliArgs = {
require: string[];
debug?: boolean;
suiteParams?: string;
richEvents?: true;
};
1 change: 1 addition & 0 deletions src/core/runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ export type RunOptions = Omit<
| 'require'
| 'suiteParams'
| 'reporter'
| 'richEvents'
> & {
params?: Params;
reporter?: CliArgs['reporter'] | Reporter;
Expand Down
18 changes: 17 additions & 1 deletion src/parse_args.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
*/

import { program } from 'commander';
import { CliArgs } from './common_types';
import { reporters } from './reporters';

const availableReporters = Object.keys(reporters)
Expand Down Expand Up @@ -55,6 +56,7 @@ program
.option('-r, --require <modules...>', 'module(s) to preload')
.option('--no-headless', 'run browser in headful mode')
.option('--sandbox', 'enable chromium sandboxing')
.option('--rich-events', 'Mimics a heartbeat run')
.option(
'--ws-endpoint <endpoint>',
'Browser WebSocket endpoint to connect to'
Expand All @@ -80,4 +82,18 @@ program
.version(version)
.description('Run synthetic tests');

export default program.parse(process.argv);
const command = program.parse(process.argv);
const options = command.opts() as CliArgs;

/**
* Group all events that can be consumed by heartbeat and
* eventually by the Synthetics UI.
*/
if (options.richEvents) {
options.reporter = options.reporter ?? 'json';
options.screenshots = true;
options.network = true;
}

export { options };
export default command;

0 comments on commit 890629d

Please sign in to comment.