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

Add --quiet-exit-code and make it default --rich-events behavior #357

Merged
merged 3 commits into from
Jul 29, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 11 additions & 1 deletion __tests__/cli.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,15 @@ describe('CLI', () => {
expect(await cli.exitCode).toBe(1);
});

it('runs the suites with --quiet-exit-code, always exiting with 0', async () => {
const cli = new CLIMock([
join(FIXTURES_DIR, 'error.journey.ts'),
'--quiet-exit-code',
]);
await cli.waitFor('boom');
expect(await cli.exitCode).toBe(0);
});

it('produce json output --json and reporter=json flag', async () => {
const output = async args => {
const cli = new CLIMock([join(FIXTURES_DIR, 'fake.journey.ts'), ...args]);
Expand Down Expand Up @@ -77,6 +86,7 @@ describe('CLI', () => {
it('mimick new heartbeat with `--rich-events` flag', async () => {
const cli = new CLIMock([
join(FIXTURES_DIR, 'fake.journey.ts'),
join(FIXTURES_DIR, 'error.journey.ts'),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to increase the timeout for this specific test.

it ('asda', callback, timeout: number), Increasing with 10 secs should do it as we now test for 2 files and also screenshots which takes more than 5 seconds.

'--rich-events',
]);
await cli.waitFor('journey/end');
Expand All @@ -94,7 +104,7 @@ describe('CLI', () => {
});

expect(await cli.exitCode).toBe(0);
});
}, 30);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: this is in milliseconds.


it('override screenshots with `--rich-events` flag', async () => {
const cli = new CLIMock([
Expand Down
1 change: 1 addition & 0 deletions __tests__/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ describe('Run', () => {
match: 'check*',
network: true,
pauseOnError: true,
quietExitCode: true,
reporter: 'json',
};
await run(options);
Expand Down
14 changes: 8 additions & 6 deletions src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,12 +194,14 @@ async function prepareSuites(inputs: string[]) {
...options,
});

/**
* Exit with error status if any journey fails
*/
for (const result of Object.values(results)) {
if (result.status === 'failed') {
process.exit(1);
if (!options.quietExitCode) {
/**
* Exit with error status if any journey fails
*/
for (const result of Object.values(results)) {
if (result.status === 'failed') {
process.exit(1);
}
}
}
})().catch(e => {
Expand Down
1 change: 1 addition & 0 deletions src/common_types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ export type CliArgs = {
dryRun?: boolean;
network?: boolean;
pauseOnError?: boolean;
quietExitCode?: boolean;
reporter?: Reporters;
wsEndpoint?: string;
sandbox?: boolean;
Expand Down
5 changes: 5 additions & 0 deletions src/parse_args.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ program
'--pause-on-error',
'pause on error until a keypress is made in the console. Useful during development'
)
.option(
'--quiet-exit-code',
'always return 0 as an exit code status, regardless of test pass / fail. Only return > 0 exit codes on internal errors where the suite could not be run'
)
.version(version)
.description('Run synthetic tests');

Expand All @@ -112,6 +116,7 @@ if (options.richEvents) {
options.reporter = options.reporter ?? 'json';
options.ssblocks = true;
options.network = true;
options.quietExitCode = true;
}

if (options.capability) {
Expand Down