test: make sure browser crashes in CLI tests are marked as such (#15821)

This commit is contained in:
Dmitry Gozman 2022-07-20 15:32:57 -07:00 committed by GitHub
parent f954891491
commit ba3c8ffa5c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 1 deletions

View file

@ -410,6 +410,23 @@ async function launchContext(options: Options, headless: boolean, executablePath
const browser = await browserType.launch(launchOptions);
if (process.env.PWTEST_CLI_EXIT) {
const logs: string[] = [];
require('playwright-core/lib/utilsBundle').debug.log = (...args: any[]) => {
const line = require('util').format(...args) + '\n';
logs.push(line);
process.stderr.write(line);
};
browser.on('disconnected', () => {
const hasCrashLine = logs.some(line => line.includes('process did exit:') && !line.includes('process did exit: exitCode=0, signal=null'));
if (hasCrashLine) {
process.stderr.write('Detected browser crash.\n');
// Make sure we exit abnormally when browser crashes.
process.exit(1);
}
});
}
// Viewport size
if (options.viewportSize) {
try {

View file

@ -60,7 +60,7 @@ export const test = contextTest.extend<CLITestArgs>({
return cli;
});
if (cli)
await cli.exited;
await cli.exited.catch(() => {});
},
openRecorder: async ({ page, recorderPageGetter }, run) => {
@ -199,6 +199,7 @@ class CLIMock {
PWTEST_CLI_EXIT: '1',
PWTEST_CLI_HEADLESS: headless ? '1' : undefined,
PWTEST_CLI_EXECUTABLE_PATH: executablePath,
DEBUG: (process.env.DEBUG ?? '') + ',pw:browser*',
},
});
this.process.onOutput = () => {