From 5235bea36c4570f24163bce3869aa314e939c79d Mon Sep 17 00:00:00 2001 From: MUI bot <2109932+Janpot@users.noreply.github.com> Date: Sat, 10 Feb 2024 09:00:54 +0100 Subject: [PATCH 1/2] Create predictably named test directories --- test/playwright/localTest.ts | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/test/playwright/localTest.ts b/test/playwright/localTest.ts index a519be25529..baa9dcfbe6e 100644 --- a/test/playwright/localTest.ts +++ b/test/playwright/localTest.ts @@ -10,7 +10,7 @@ import archiver from 'archiver'; import * as url from 'url'; import getPort from 'get-port'; import * as execa from 'execa'; -import { PageScreenshotOptions, test as baseTest } from './test'; +import { PageScreenshotOptions, WorkerInfo, test as baseTest } from './test'; import { waitForMatch } from '../utils/streams'; import { asyncDisposeSymbol, using } from '../utils/resources'; @@ -59,8 +59,12 @@ interface LocalServerConfig { base?: string; } -export async function getTemporaryDir({ template, setup }: ProjectConfig = {}) { - const tmpTestDir = await fs.mkdtemp(path.resolve(currentDirectory, './tmp-')); +export async function getTemporaryDir( + workerInfo: WorkerInfo, + { template, setup }: ProjectConfig = {}, +) { + const tmpTestDir = path.resolve(currentDirectory, `./.tmp-test-dir-${workerInfo.parallelIndex}`); + await fs.mkdir(tmpTestDir); // Each test runs in its own temporary folder to avoid race conditions when running tests in parallel. // It also avoids mutating the source code of the fixture while running the test. const projectDir = path.resolve(tmpTestDir, './fixture'); @@ -306,8 +310,8 @@ const test = baseTest.extend< customServerConfig: [undefined, { option: true, scope: 'worker' }], projectConfig: [undefined, { option: true, scope: 'worker' }], projectDir: [ - async ({ projectConfig }, use) => { - await using(await getTemporaryDir(projectConfig), async (projectDir) => { + async ({ projectConfig }, use, workerInfo) => { + await using(await getTemporaryDir(workerInfo, projectConfig), async (projectDir) => { await use(projectDir); }); }, From 64289b5ef5c3df5f14fd62441b05cebb60efd370 Mon Sep 17 00:00:00 2001 From: MUI bot <2109932+Janpot@users.noreply.github.com> Date: Sat, 10 Feb 2024 09:21:13 +0100 Subject: [PATCH 2/2] Update localTest.ts --- test/playwright/localTest.ts | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/test/playwright/localTest.ts b/test/playwright/localTest.ts index baa9dcfbe6e..9950d8c63e1 100644 --- a/test/playwright/localTest.ts +++ b/test/playwright/localTest.ts @@ -58,8 +58,18 @@ interface LocalServerConfig { env?: Record; base?: string; } +export async function getTemporaryDir() { + const tmpDir = await fs.mkdtemp(path.resolve(currentDirectory, './tmp-')); -export async function getTemporaryDir( + return { + path: tmpDir, + [asyncDisposeSymbol]: async () => { + await fs.rm(tmpDir, { recursive: true, maxRetries: 3, retryDelay: 1000 }); + }, + }; +} + +async function getTestFixtureTempDir( workerInfo: WorkerInfo, { template, setup }: ProjectConfig = {}, ) { @@ -311,7 +321,7 @@ const test = baseTest.extend< projectConfig: [undefined, { option: true, scope: 'worker' }], projectDir: [ async ({ projectConfig }, use, workerInfo) => { - await using(await getTemporaryDir(workerInfo, projectConfig), async (projectDir) => { + await using(await getTestFixtureTempDir(workerInfo, projectConfig), async (projectDir) => { await use(projectDir); }); },