Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create predictably named test directories #3194

Merged
merged 2 commits into from
Feb 13, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 19 additions & 5 deletions test/playwright/localTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -58,9 +58,23 @@ interface LocalServerConfig {
env?: Record<string, string>;
base?: string;
}
export async function getTemporaryDir() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we still need this function? I see it's only being used in a custom server test now, not sure if it could be replaced there too?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, it's using a random directory that's different from the test directory

const tmpDir = await fs.mkdtemp(path.resolve(currentDirectory, './tmp-'));

export async function getTemporaryDir({ template, setup }: ProjectConfig = {}) {
const tmpTestDir = await fs.mkdtemp(path.resolve(currentDirectory, './tmp-'));
return {
path: tmpDir,
[asyncDisposeSymbol]: async () => {
await fs.rm(tmpDir, { recursive: true, maxRetries: 3, retryDelay: 1000 });
},
};
}

async function getTestFixtureTempDir(
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');
Expand Down Expand Up @@ -306,8 +320,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 getTestFixtureTempDir(workerInfo, projectConfig), async (projectDir) => {
await use(projectDir);
});
},
Expand Down
Loading