Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.
TypeScript automationchromechromiume2e-testingelectronend-to-end-testingfirefoxjavascriptplaywrighttesttest-automationtestingtesting-toolswebwebkit
chore: remove separate process that cleans up directories (#24376)
Dmitry Gozman4c8912f74eac
diff --git a/packages/playwright-core/src/utils/processLauncher.ts b/packages/playwright-core/src/utils/processLauncher.tsindex 184241f8f0..f4222744a7 100644--- a/packages/playwright-core/src/utils/processLauncher.ts+++ b/packages/playwright-core/src/utils/processLauncher.ts@@ -17,9 +17,9 @@import * as childProcess from 'child_process';import * as readline from 'readline';-import * as path from 'path';import { isUnderTest } from './';import { removeFolders } from './fileUtils';+import { rimraf } from '../utilsBundle';export type Env = {[key: string]: string | number | boolean | undefined};@@ -243,13 +243,12 @@ export async function launchProcess(options: LaunchProcessOptions): Promise<Launfunction killProcessAndCleanup() {killProcess();options.log(`[pid=${spawnedProcess.pid || 'N/A'}] starting temporary directories cleanup`);- if (options.tempDirectories.length) {- const cleanupProcess = childProcess.spawnSync(process.argv0, [path.join(__dirname, 'processLauncherCleanupEntrypoint.js'), ...options.tempDirectories]);- const [stdout, stderr] = [cleanupProcess.stdout.toString(), cleanupProcess.stderr.toString()];- if (stdout)- options.log(`[pid=${spawnedProcess.pid || 'N/A'}] ${stdout}`);- if (stderr)- options.log(`[pid=${spawnedProcess.pid || 'N/A'}] ${stderr}`);+ for (const dir of options.tempDirectories) {+ try {+ rimraf.sync(dir);+ } catch (e) {+ options.log(`[pid=${spawnedProcess.pid || 'N/A'}] exception while removing ${dir}: ${e}`);+ }}options.log(`[pid=${spawnedProcess.pid || 'N/A'}] finished temporary directories cleanup`);}diff --git a/packages/playwright-core/src/utils/processLauncherCleanupEntrypoint.ts b/packages/playwright-core/src/utils/processLauncherCleanupEntrypoint.tsdeleted file mode 100644index e11c67f158..0000000000--- a/packages/playwright-core/src/utils/processLauncherCleanupEntrypoint.ts+++ /dev/null@@ -1,28 +0,0 @@-/**- * Copyright (c) Microsoft Corporation.- *- * Licensed under the Apache License, Version 2.0 (the "License");- * you may not use this file except in compliance with the License.- * You may obtain a copy of the License at- *- * http://www.apache.org/licenses/LICENSE-2.0- *- * Unless required by applicable law or agreed to in writing, software- * distributed under the License is distributed on an "AS IS" BASIS,- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.- * See the License for the specific language governing permissions and- * limitations under the License.- */--import { removeFolders } from './fileUtils';--(async () => {- const dirs = process.argv.slice(2);- const errors = await removeFolders(dirs);- for (let i = 0; i < dirs.length; ++i) {- if (errors[i]) {- // eslint-disable-next-line no-console- console.error(`exception while removing ${dirs[i]}: ${errors[i]}`);- }- }-})();diff --git a/tests/library/signals.spec.ts b/tests/library/signals.spec.tsindex 50b34c15e5..85f6d45ca6 100644--- a/tests/library/signals.spec.ts+++ b/tests/library/signals.spec.ts@@ -42,7 +42,9 @@ test('should close the browser when the node process closes', async ({ startRemoexpect(await remoteServer.childExitCode()).toBe(isWindows ? 1 : 0);});-test('should remove temp dir on process.exit', async ({ startRemoteServer, server }, testInfo) => {+test('should remove temp dir on process.exit', async ({ startRemoteServer, server, platform }, testInfo) => {+ test.skip(platform === 'win32', 'Removing user data dir synchronously is blocked on Windows');+const file = testInfo.outputPath('exit.file');const remoteServer = await startRemoteServer('launchServer', { url: server.EMPTY_PAGE, exitOnFile: file });const tempDir = await remoteServer.out('tempDir');