Skip to content

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.

fix: propagate exit code in experimental mode (#12070)

pierscowburn5db7ce5964dc
diff --git a/packages/playwright-core/src/cli/cli.ts b/packages/playwright-core/src/cli/cli.ts
index 0da0cfd554..2b18e669fb 100755
--- a/packages/playwright-core/src/cli/cli.ts
+++ b/packages/playwright-core/src/cli/cli.ts
@@ -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');
}
diff --git a/tests/playwright-test/loader.spec.ts b/tests/playwright-test/loader.spec.ts
index 5aba8151a5..d596947b88 100644
--- a/tests/playwright-test/loader.spec.ts
+++ b/tests/playwright-test/loader.spec.ts
@@ -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': `