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
fix(rimraf): allow 10 retires when removing the profile folder (#5826)
Pavel Feldmanbf36b487fc66
diff --git a/src/install/installer.ts b/src/install/installer.tsindex a0a86e414e..186c01c1f1 100644--- a/src/install/installer.ts+++ b/src/install/installer.ts@@ -17,11 +17,10 @@import fs from 'fs';import path from 'path';import util from 'util';-import removeFolder from 'rimraf';import lockfile from 'proper-lockfile';import {Registry, allBrowserNames, isBrowserDirectory, BrowserName, registryDirectory} from '../utils/registry';import * as browserFetcher from './browserFetcher';-import { getAsBooleanFromENV, calculateSha1 } from '../utils/utils';+import { getAsBooleanFromENV, calculateSha1, removeFolders } from '../utils/utils';const fsMkdirAsync = util.promisify(fs.mkdir.bind(fs));const fsReaddirAsync = util.promisify(fs.readdir.bind(fs));@@ -29,7 +28,6 @@ const fsReadFileAsync = util.promisify(fs.readFile.bind(fs));const fsExistsAsync = (filePath: string) => fsReadFileAsync(filePath).then(() => true).catch(e => false);const fsUnlinkAsync = util.promisify(fs.unlink.bind(fs));const fsWriteFileAsync = util.promisify(fs.writeFile.bind(fs));-const removeFolderAsync = util.promisify(removeFolder);const PACKAGE_PATH = path.join(__dirname, '..', '..');@@ -101,10 +99,9 @@ async function validateCache(linksDir: string, browserNames: BrowserName[]) {const directories = new Set<string>(downloadedBrowsers);for (const browserDirectory of usedBrowserPaths)directories.delete(browserDirectory);- for (const directory of directories) {+ for (const directory of directories)browserFetcher.logPolitely('Removing unused browser at ' + directory);- await removeFolderAsync(directory).catch(e => {});- }+ await removeFolders([...directories]);}// 3. Install missing browsers for this package.diff --git a/src/server/helper.ts b/src/server/helper.tsindex 4012a759d5..fb34204536 100644--- a/src/server/helper.ts+++ b/src/server/helper.ts@@ -16,14 +16,10 @@*/import { EventEmitter } from 'events';-import removeFolder from 'rimraf';-import util from 'util';import * as types from './types';import { Progress } from './progress';import { debugLogger } from '../utils/debugLogger';-const removeFolderAsync = util.promisify(removeFolder);-export type RegisteredListener = {emitter: EventEmitter;eventName: (string | symbol);@@ -77,12 +73,6 @@ class Helper {return null;}- static async removeFolders(dirs: string[]) {- await Promise.all(dirs.map(dir => {- return removeFolderAsync(dir).catch((err: Error) => console.error(err));- }));- }-static waitForEvent(progress: Progress | null, emitter: EventEmitter, event: string | symbol, predicate?: Function): { promise: Promise<any>, dispose: () => void } {const listeners: RegisteredListener[] = [];const promise = new Promise((resolve, reject) => {diff --git a/src/server/processLauncher.ts b/src/server/processLauncher.tsindex 361cf15d96..60835c374c 100644--- a/src/server/processLauncher.ts+++ b/src/server/processLauncher.ts@@ -17,10 +17,9 @@import * as childProcess from 'child_process';import * as readline from 'readline';-import * as removeFolder from 'rimraf';import { helper } from './helper';import * as types from './types';-import { isUnderTest } from '../utils/utils';+import { isUnderTest, removeFolders } from '../utils/utils';export type Env = {[key: string]: string | number | boolean | undefined};@@ -62,7 +61,7 @@ if (maxListeners !== 0)process.setMaxListeners(Math.max(maxListeners || 0, 100));export async function launchProcess(options: LaunchProcessOptions): Promise<LaunchResult> {- const cleanup = () => helper.removeFolders(options.tempDirectories);+ const cleanup = () => removeFolders(options.tempDirectories);const stdio: ('ignore' | 'pipe')[] = options.stdio === 'pipe' ? ['ignore', 'pipe', 'pipe', 'pipe', 'pipe'] : ['pipe', 'pipe', 'pipe'];options.log(`<launching> ${options.executablePath} ${options.args.join(' ')}`);@@ -172,11 +171,7 @@ export async function launchProcess(options: LaunchProcessOptions): Promise<Laun// the process might have already stopped}}- try {- // Attempt to remove temporary directories to avoid littering.- for (const dir of options.tempDirectories)- removeFolder.sync(dir);- } catch (e) { }+ cleanup();}function killAndWait() {diff --git a/src/utils/utils.ts b/src/utils/utils.tsindex d268981d02..cc4d1e079c 100644--- a/src/utils/utils.ts+++ b/src/utils/utils.ts@@ -16,6 +16,7 @@import path from 'path';import fs from 'fs';+import removeFolder from 'rimraf';import * as util from 'util';import * as crypto from 'crypto';@@ -145,3 +146,15 @@ export function calculateSha1(buffer: Buffer | string): string {export function createGuid(): string {return crypto.randomBytes(16).toString('hex');}++export async function removeFolders(dirs: string[]) {+ await Promise.all(dirs.map((dir: string) => {+ return new Promise<void>(fulfill => {+ removeFolder(dir, { maxBusyTries: 10 }, error => {+ if (error)+ console.error(error); // eslint-disable no-console+ fulfill();+ });+ });+ }));+}diff --git a/test/defaultbrowsercontext-2.spec.ts b/test/defaultbrowsercontext-2.spec.tsindex f7e873c9ad..e35857446a 100644--- a/test/defaultbrowsercontext-2.spec.ts+++ b/test/defaultbrowsercontext-2.spec.ts@@ -236,4 +236,5 @@ it('should connect to a browser with the default page', (test, { mode }) => {const options = { ...browserOptions, __testHookOnConnectToBrowser: () => new Promise(f => setTimeout(f, 3000)) };const context = await browserType.launchPersistentContext(await createUserDataDir(), options);expect(context.pages().length).toBe(1);+ await context.close();});diff --git a/test/fixtures.ts b/test/fixtures.tsindex fd7dde40fa..44f5c1537f 100644--- a/test/fixtures.ts+++ b/test/fixtures.ts@@ -26,9 +26,9 @@ import { folio as httpFolio } from './http.fixtures';import { folio as playwrightFolio } from './playwright.fixtures';import { PlaywrightClient } from '../lib/remote/playwrightClient';import { start } from '../lib/outofprocess';+import { removeFolders } from '../lib/utils/utils';export { expect, config } from 'folio';-const removeFolderAsync = util.promisify(require('rimraf'));const mkdtempAsync = util.promisify(fs.mkdtemp);const getExecutablePath = browserName => {@@ -69,7 +69,7 @@ fixtures.createUserDataDir.init(async ({ }, run) => {return dir;}await run(createUserDataDir);- await Promise.all(dirs.map(dir => removeFolderAsync(dir).catch(e => { })));+ await removeFolders(dirs);});fixtures.launchPersistent.init(async ({ createUserDataDir, browserOptions, browserType }, run) => {