From dab2384b0eaffe50afd0e78c37f147fb722e5f21 Mon Sep 17 00:00:00 2001 From: Dmitry Gozman Date: Wed, 27 Apr 2022 15:01:30 +0100 Subject: [PATCH] fix(process launcher): use spawnSync to cleanup synchronously (#13769) This allows us to use the full retry logic of rimraf in the `onexit` handler. Note this is already covered by failing on Windows test `should remove temp dir on process.exit`. --- packages/playwright-core/package.json | 1 + .../src/utils/processLauncher.ts | 15 +++++----- .../utils/processLauncherCleanupEntrypoint.ts | 28 +++++++++++++++++++ 3 files changed, 37 insertions(+), 7 deletions(-) create mode 100644 packages/playwright-core/src/utils/processLauncherCleanupEntrypoint.ts diff --git a/packages/playwright-core/package.json b/packages/playwright-core/package.json index 7ee76439aa..b1c37eac43 100644 --- a/packages/playwright-core/package.json +++ b/packages/playwright-core/package.json @@ -29,6 +29,7 @@ "./lib/utils/manualPromise": "./lib/utils/manualPromise.js", "./lib/utils/multimap": "./lib/utils/multimap.js", "./lib/utils/processLauncher": "./lib/utils/processLauncher.js", + "./lib/utils/processLauncherCleanupEntrypoint": "./lib/utils/processLauncherCleanupEntrypoint.js", "./lib/utils/spawnAsync": "./lib/utils/spawnAsync.js", "./lib/utils/stackTrace": "./lib/utils/stackTrace.js", "./lib/utils/timeoutRunner": "./lib/utils/timeoutRunner.js", diff --git a/packages/playwright-core/src/utils/processLauncher.ts b/packages/playwright-core/src/utils/processLauncher.ts index 6d06a1be55..c2fa432848 100644 --- a/packages/playwright-core/src/utils/processLauncher.ts +++ b/packages/playwright-core/src/utils/processLauncher.ts @@ -17,10 +17,10 @@ import * as childProcess from 'child_process'; import * as readline from 'readline'; +import * as path from 'path'; import { eventsHelper } from './eventsHelper'; import { isUnderTest } from './'; import { removeFolders } from './fileUtils'; -import { rimraf } from '../utilsBundle'; export type Env = {[key: string]: string | number | boolean | undefined}; @@ -191,12 +191,13 @@ export async function launchProcess(options: LaunchProcessOptions): Promise { + 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]}`); + } + } +})();