Skip to content

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

test: check that we remove temp directories on process exit (#13494)

Dmitry Gozman2a97ad2487c3
diff --git a/tests/config/remote-server-impl.js b/tests/config/remote-server-impl.js
index 19eeeda9c4..55980009e8 100644
--- a/tests/config/remote-server-impl.js
+++ b/tests/config/remote-server-impl.js
@@ -1,7 +1,8 @@
+const fs = require('fs');
const cluster = require('cluster');
async function start() {
- const { browserTypeName, launchOptions, stallOnClose, disconnectOnSIGHUP } = JSON.parse(process.argv[2]);
+ const { browserTypeName, launchOptions, stallOnClose, disconnectOnSIGHUP, exitOnFile } = JSON.parse(process.argv[2]);
if (stallOnClose) {
launchOptions.__testHookGracefullyClose = () => {
console.log(`(stalled=>true)`);
@@ -17,6 +18,17 @@ async function start() {
if (disconnectOnSIGHUP)
process.on('SIGHUP', () => browserServer._disconnectForTest());
+ if (exitOnFile) {
+ (async function waitForFileAndExit() {
+ while (true) {
+ if (fs.existsSync(exitOnFile))
+ break;
+ await new Promise(f => setTimeout(f, 100));
+ }
+ process.exit(42);
+ })();
+ }
+
browserServer.on('close', (exitCode, signal) => {
console.log(`(exitCode=>${exitCode})`);
console.log(`(signal=>${signal})`);
diff --git a/tests/config/remoteServer.ts b/tests/config/remoteServer.ts
index 57b291e3b4..fa003d3117 100644
--- a/tests/config/remoteServer.ts
+++ b/tests/config/remoteServer.ts
@@ -21,6 +21,7 @@ import type { CommonFixtures, TestChildProcess } from './commonFixtures';
export type RemoteServerOptions = {
stallOnClose?: boolean;
disconnectOnSIGHUP?: boolean;
+ exitOnFile?: string;
inCluster?: boolean;
url?: string;
};
diff --git a/tests/library/signals.spec.ts b/tests/library/signals.spec.ts
index 5c8fbc71e3..931b87e885 100644
--- a/tests/library/signals.spec.ts
+++ b/tests/library/signals.spec.ts
@@ -33,9 +33,11 @@ test('should close the browser when the node process closes', async ({ startRemo
});
test.describe('signals', () => {
- test.skip(({ platform, headless }) => platform === 'win32' || !headless);
+ test.skip(({ platform }) => platform === 'win32');
+
+ test('should report browser close signal', async ({ startRemoteServer, server, headless }) => {
+ test.skip(!headless, 'Wrong exit code in headed');
- test('should report browser close signal', async ({ startRemoteServer, server }) => {
const remoteServer = await startRemoteServer({ url: server.EMPTY_PAGE });
const pid = await remoteServer.out('pid');
process.kill(-pid, 'SIGTERM');
@@ -94,6 +96,18 @@ test.describe('signals', () => {
expect(after).toBe(false);
});
+ test('should remove temp dir on process.exit', async ({ startRemoteServer, server }, testInfo) => {
+ const file = testInfo.outputPath('exit.file');
+ const remoteServer = await startRemoteServer({ url: server.EMPTY_PAGE, exitOnFile: file });
+ const tempDir = await remoteServer.out('tempDir');
+ const before = fs.existsSync(tempDir);
+ fs.writeFileSync(file, 'data', 'utf-8');
+ expect(await remoteServer.childExitCode()).toBe(42);
+ const after = fs.existsSync(tempDir);
+ expect(before).toBe(true);
+ expect(after).toBe(false);
+ });
+
test('should kill the browser on SIGINT + SIGTERM', async ({ startRemoteServer, server }) => {
const remoteServer = await startRemoteServer({ stallOnClose: true, url: server.EMPTY_PAGE });
process.kill(remoteServer.child().pid, 'SIGINT');