Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: default to ssblocks for richevents #322

Merged
merged 1 commit into from
Jun 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 52 additions & 14 deletions __tests__/cli.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,11 @@ describe('CLI', () => {
});

it('produce json output via --json flag', async () => {
const cli = new CLIMock([join(FIXTURES_DIR, 'fake.journey.ts'), '--json']);
const cli = new CLIMock([
join(FIXTURES_DIR, 'fake.journey.ts'),
'--reporter',
'json',
]);
await cli.waitFor('fake journey');
const output = cli.output();
expect(JSON.parse(output).journey).toEqual({
Expand All @@ -52,17 +56,41 @@ describe('CLI', () => {
expect(await cli.exitCode).toBe(0);
});

it('enables rich events on `--rich-events` flag', async () => {
it('mimick heartbeat with `--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',
await cli.waitFor('journey/end');
const screenshotRef = cli
.buffer()
.map(data => JSON.parse(data))
.find(({ type }) => type === 'step/screenshot_ref');

expect(screenshotRef).toMatchObject({
journey: {
id: 'fake journey',
name: 'fake journey',
},
root_fields: expect.any(Object),
});

expect(await cli.exitCode).toBe(0);
});

it('override screenshots with `--rich-events` flag', async () => {
const cli = new CLIMock([
join(FIXTURES_DIR, 'fake.journey.ts'),
'--rich-events',
'--screenshots',
'off',
]);
await cli.waitFor('journey/end');
const screenshots = cli
.buffer()
.map(data => JSON.parse(data))
.find(({ type }) => type === 'step/screenshot_ref');
expect(screenshots).not.toBeDefined();
expect(await cli.exitCode).toBe(0);
});

Expand All @@ -72,7 +100,8 @@ describe('CLI', () => {
const output = async () => {
const cli = new CLIMock([
join(FIXTURES_DIR, 'fake.journey.ts'),
'--json',
'--reporter',
'json',
'--config',
join(FIXTURES_DIR, 'synthetics.config.ts'),
]);
Expand All @@ -94,7 +123,8 @@ describe('CLI', () => {
it('suite params wins over config params', async () => {
const cli = new CLIMock([
join(FIXTURES_DIR, 'fake.journey.ts'),
'--json',
'--reporter',
'json',
'--config',
join(FIXTURES_DIR, 'synthetics.config.ts'),
'-s',
Expand All @@ -111,7 +141,8 @@ describe('CLI', () => {
it('throw error on modifying params', async () => {
const cli = new CLIMock([
join(FIXTURES_DIR, 'params-error.journey.ts'),
'-j',
'--reporter',
'json',
]);
expect(await cli.exitCode).toBe(1);
const output = cli.output();
Expand All @@ -124,7 +155,8 @@ describe('CLI', () => {
it('support capability flag', async () => {
const cli = new CLIMock([
join(FIXTURES_DIR, 'example.journey.ts'),
'-j',
'--reporter',
'json',
'--capability',
'metrics',
]);
Expand All @@ -137,7 +169,8 @@ describe('CLI', () => {
it('show warn for unknown capability flag', async () => {
const cli = new CLIMock([
join(FIXTURES_DIR, 'fake.journey.ts'),
'-j',
'--reporter',
'json',
'--capability',
'unknown',
]);
Expand All @@ -159,13 +192,13 @@ describe('CLI', () => {

class CLIMock {
private process: ChildProcess;
private data: string;
private data = '';
private chunks: Array<string> = [];
private waitForText: string;
private waitForPromise: () => void;
exitCode: Promise<number>;

constructor(args: string[]) {
this.data = '';
this.process = spawn(
'node',
[join(__dirname, '..', 'dist', 'cli.js'), ...args],
Expand All @@ -176,6 +209,7 @@ class CLIMock {
);
const dataListener = data => {
this.data = data.toString();
this.chunks.push(...this.data.split('\n').filter(Boolean));
if (this.waitForPromise && this.data.includes(this.waitForText)) {
this.process.stdout.off('data', dataListener);
this.waitForPromise();
Expand All @@ -197,4 +231,8 @@ class CLIMock {
output() {
return this.data;
}

buffer() {
return this.chunks;
}
}
13 changes: 9 additions & 4 deletions 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('-j, --json', 'output newline delimited JSON')
.addOption(
new Option('--reporter <value>', `output repoter format`).choices(
Object.keys(reporters)
Expand All @@ -63,7 +62,6 @@ program
.choices(['on', 'off', 'only-on-failure'])
.default('on')
)
.option('--network', 'capture network information for all journeys')
.option(
'--dry-run',
"don't actually execute anything, report only registered journeys"
Expand Down Expand Up @@ -101,14 +99,21 @@ const options = command.opts() as CliArgs;
*/
if (options.richEvents) {
options.reporter = options.reporter ?? 'json';
options.screenshots = 'on';
options.ssblocks = true;
options.network = true;
}

if (options.capability) {
const supportedCapabilities = ['trace', 'filmstrips', 'metrics', 'ssblocks'];
const supportedCapabilities = [
'trace',
'network',
'filmstrips',
'metrics',
'ssblocks',
];
/**
* trace - record chrome trace events(LCP, FCP, CLS, etc.) for all journeys
* network - capture network information for all journeys
* filmstrips - record detailed filmstrips for all journeys
* metrics - capture performance metrics (DOM Nodes, Heap size, etc.) for each step
* ssblocks - Dedupes the screenshots in to blocks to save storage space
Expand Down