This commit is contained in:
Adam Gastineau 2025-02-25 23:10:01 -08:00 committed by GitHub
commit 7c235ce437
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 13 additions and 3 deletions

View file

@ -57,6 +57,7 @@ export function runDriver() {
// We still will destruct everything (close browsers and exit) when the transport pipe closes. // We still will destruct everything (close browsers and exit) when the transport pipe closes.
process.on('SIGINT', () => { process.on('SIGINT', () => {
// Keep the process running. // Keep the process running.
console.log('SIGINT received');
}); });
} }

View file

@ -528,6 +528,7 @@ async function launchContext(options: Options, extraOptions: LaunchOptions): Pro
}); });
}); });
process.on('SIGINT', async () => { process.on('SIGINT', async () => {
console.log('SIGINT received, closing browser...');
await closeBrowser(); await closeBrowser();
gracefullyProcessExitDoNotHang(130); gracefullyProcessExitDoNotHang(130);
}); });

View file

@ -51,8 +51,12 @@ let forceExitInitiated = false;
sendMessageToParent({ method: 'ready' }); sendMessageToParent({ method: 'ready' });
process.on('disconnect', () => gracefullyCloseAndExit(true)); process.on('disconnect', () => gracefullyCloseAndExit(true));
process.on('SIGINT', () => {}); process.on('SIGINT', () => {
process.on('SIGTERM', () => {}); console.log('SIGINT received');
});
process.on('SIGTERM', () => {
console.log('SIGTERM received');
});
// Clear execArgv immediately, so that the user-code does not inherit our loader. // Clear execArgv immediately, so that the user-code does not inherit our loader.
process.execArgv = execArgvWithoutExperimentalLoaderOptions(); process.execArgv = execArgvWithoutExperimentalLoaderOptions();

View file

@ -49,6 +49,7 @@ class FixedNodeSIGINTHandler {
private static _handlerInstalled = false; private static _handlerInstalled = false;
static _dispatch = () => { static _dispatch = () => {
console.log('SIGINT received');
if (this._ignoreNextSIGINTs) if (this._ignoreNextSIGINTs)
return; return;

View file

@ -458,13 +458,16 @@ await page1.GotoAsync("about:blank?foo");`);
const harFileName = testInfo.outputPath('har.har'); const harFileName = testInfo.outputPath('har.har');
const cli = runCLI([`--save-storage=${storageFileName}`, `--save-har=${harFileName}`]); const cli = runCLI([`--save-storage=${storageFileName}`, `--save-har=${harFileName}`]);
await cli.waitFor(`import { test, expect } from '@playwright/test'`); await cli.waitFor(`import { test, expect } from '@playwright/test'`);
cli.process.process.on('SIGINT', () => {
console.log('Local SIGINT');
});
await cli.process.kill('SIGINT'); await cli.process.kill('SIGINT');
const { exitCode, signal } = await cli.process.exited; const { exitCode, signal } = await cli.process.exited;
if (exitCode !== null) { if (exitCode !== null) {
expect(exitCode).toBe(130); expect(exitCode).toBe(130);
} else { } else {
// If the runner is slow enough, the process will be forcibly terminated by the signal // If the runner is slow enough, the process will be forcibly terminated by the signal
expect(signal).toBe('SIGINT'); expect(signal).toMatch(/SIGINT|SIGKILL/);
} }
expect(fs.existsSync(storageFileName)).toBeTruthy(); expect(fs.existsSync(storageFileName)).toBeTruthy();
expect(fs.existsSync(harFileName)).toBeTruthy(); expect(fs.existsSync(harFileName)).toBeTruthy();