cherry-pick(#12070): fix: propagate exit code in experimental mode (#12133)

SHA: 5db7ce5964

In experimental ESM mode a child process is forked in order to run the tests. Currently the exit code of this child process is not propagated to the exit code of the parent process, which means that the process exits with a status code of `0` even if some of the tests failed.

This makes it difficult to use Playwright in CI in experimental mode, as the CI pipeline as a whole will pass despite the test failures.

This change addresses this by propagating the exit code in the case where it is non-zero.

Co-authored-by: pierscowburn <me@pierscowburn.com>
This commit is contained in:
Andrey Lushnikov 2022-02-15 14:25:14 -07:00 committed by GitHub
parent 46aeb8fe3d
commit e57b4b5073
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 1 deletions

View file

@ -19,9 +19,13 @@ import { fork } from 'child_process';
if (process.env.PW_EXPERIMENTAL_TS_ESM) {
const NODE_OPTIONS = (process.env.NODE_OPTIONS || '') + ` --experimental-loader=${require.resolve('@playwright/test/lib/experimentalLoader')}`;
fork(require.resolve('./innerCli'), process.argv.slice(2), {
const innerProcess = fork(require.resolve('./innerCli'), process.argv.slice(2), {
env: { ...process.env, NODE_OPTIONS }
});
innerProcess.on('close', code => {
if (code !== 0 && code !== null) process.exit(code);
});
} else {
require('./innerCli');
}

View file

@ -267,6 +267,24 @@ test('should import esm from ts when package.json has type module in experimenta
expect(result.exitCode).toBe(0);
});
test('should propagate subprocess exit code in experimental mode', async ({ runInlineTest }) => {
// We only support experimental esm mode on Node 16+
test.skip(parseInt(process.version.slice(1), 10) < 16);
const result = await runInlineTest({
'package.json': JSON.stringify({ type: 'module' }),
'a.test.ts': `
const { test } = pwt;
test('failing test', ({}, testInfo) => {
expect(1).toBe(2);
});
`,
}, {}, {
PW_EXPERIMENTAL_TS_ESM: true
});
expect(result.exitCode).toBe(1);
});
test('should filter stack trace for simple expect', async ({ runInlineTest }) => {
const result = await runInlineTest({
'expect-test.spec.ts': `