Skip to content

Commit 7eb1900

Browse files
authored
feat(test runner): add PLAYWRIGHT_TRANSFORM_CACHE_DIR (#43733)
1 parent 4d05531 commit 7eb1900

5 files changed

Lines changed: 14 additions & 8 deletions

File tree

‎docs/src/test-cli-js.md‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,3 +334,9 @@ Clear all Playwright caches.
334334
```bash
335335
npx playwright clear-cache
336336
```
337+
338+
Playwright keeps transpiled test files in the system temporary directory. To keep them in another directory, for example on a Linux machine shared with other users, set the `PLAYWRIGHT_TRANSFORM_CACHE_DIR` environment variable:
339+
340+
```bash
341+
PLAYWRIGHT_TRANSFORM_CACHE_DIR=~/.cache/playwright-transform npx playwright test
342+
```

‎packages/playwright/src/transform/compilationCache.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ export type SerializedCompilationCache = {
4949
// - For workers-only dynamic imports or some cache problems, we will re-transpile files in
5050
// each worker anew.
5151

52-
export const cacheDir = process.env.PWTEST_CACHE_DIR || (() => {
52+
export const cacheDir = process.env.PLAYWRIGHT_TRANSFORM_CACHE_DIR || (() => {
5353
if (process.platform === 'win32')
5454
return path.join(os.tmpdir(), `playwright-transform-cache`);
5555
// Use `geteuid()` instead of more natural `os.userInfo().username`

‎tests/playwright-test/cache.spec.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ test('should automatically clean cached versions of a changed file', async ({ ru
5858
test('example', () => {});
5959
`,
6060
}, undefined, {
61-
PWTEST_CACHE_DIR: cacheDir
61+
PLAYWRIGHT_TRANSFORM_CACHE_DIR: cacheDir
6262
});
6363

6464
const cacheDirectories = await fs.promises.readdir(cacheDir);
@@ -84,7 +84,7 @@ test('should automatically clean cached versions of a changed file', async ({ ru
8484
test('modified test', () => {});
8585
`,
8686
}, undefined, {
87-
PWTEST_CACHE_DIR: cacheDir
87+
PLAYWRIGHT_TRANSFORM_CACHE_DIR: cacheDir
8888
});
8989

9090
cachedFiles = await fs.promises.readdir(testCacheDirectory);

‎tests/playwright-test/playwright-test-fixtures.ts‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ export const test = base
266266
const cacheDir = await fs.promises.mkdtemp(path.join(os.tmpdir(), 'playwright-test-cache-'));
267267
await use(async (files: Files, params: Params = {}, env: NodeJS.ProcessEnv = {}, options: RunOptions = {}) => {
268268
const baseDir = await writeFiles(testInfo, files, true);
269-
return await runPlaywrightTest(childProcess, baseDir, params, { PWTEST_CACHE_DIR: cacheDir, ...env }, options, files, mergeReports, useIntermediateMergeReport);
269+
return await runPlaywrightTest(childProcess, baseDir, params, { PLAYWRIGHT_TRANSFORM_CACHE_DIR: cacheDir, ...env }, options, files, mergeReports, useIntermediateMergeReport);
270270
});
271271
await removeFolders([cacheDir]);
272272
},
@@ -275,7 +275,7 @@ export const test = base
275275
const cacheDir = await fs.promises.mkdtemp(path.join(os.tmpdir(), 'playwright-test-cache-'));
276276
await use(async (files: Files, command: string, args?: string[]) => {
277277
const baseDir = await writeFiles(testInfo, files, true);
278-
return await runPlaywrightCLI(childProcess, [command, ...(args || [])], baseDir, { PWTEST_CACHE_DIR: cacheDir });
278+
return await runPlaywrightCLI(childProcess, [command, ...(args || [])], baseDir, { PLAYWRIGHT_TRANSFORM_CACHE_DIR: cacheDir });
279279
});
280280
await removeFolders([cacheDir]);
281281
},
@@ -284,7 +284,7 @@ export const test = base
284284
const cacheDir = await fs.promises.mkdtemp(path.join(os.tmpdir(), 'playwright-test-cache-'));
285285
await use(async (files: Files, command: string, args?: string[], options: RunOptions = {}, env: NodeJS.ProcessEnv = {}) => {
286286
const baseDir = await writeFiles(testInfo, files, true);
287-
return startPlaywrightChildProcess(childProcess, baseDir, [command, ...(args || [])], { ...env, PWTEST_CACHE_DIR: cacheDir }, options);
287+
return startPlaywrightChildProcess(childProcess, baseDir, [command, ...(args || [])], { ...env, PLAYWRIGHT_TRANSFORM_CACHE_DIR: cacheDir }, options);
288288
});
289289
await removeFolders([cacheDir]);
290290
},
@@ -298,7 +298,7 @@ export const test = base
298298
let testProcess: TestChildProcess | undefined;
299299
await use(async (files: Files, params: Params = {}, env: NodeJS.ProcessEnv = {}, options: RunOptions = {}) => {
300300
const baseDir = await writeFiles(testInfo, files, true);
301-
testProcess = startPlaywrightTest(childProcess, baseDir, params, { PWTEST_CACHE_DIR: cacheDir, ...env }, options);
301+
testProcess = startPlaywrightTest(childProcess, baseDir, params, { PLAYWRIGHT_TRANSFORM_CACHE_DIR: cacheDir, ...env }, options);
302302
return testProcess;
303303
});
304304
await testProcess?.kill();

‎tests/playwright-test/ui-mode-fixtures.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ export const test = base
102102
command: [...cliCommand, 'test', (options.useWeb ? '--ui-host=127.0.0.1' : '--ui'), '--workers=1', ...(options.additionalArgs || [])],
103103
env: inheritAndCleanEnv({
104104
...env,
105-
PWTEST_CACHE_DIR: cacheDir,
105+
PLAYWRIGHT_TRANSFORM_CACHE_DIR: cacheDir,
106106
PWTEST_HEADED_FOR_TEST: headless ? '0' : '1',
107107
PWTEST_PRINT_WS_ENDPOINT: '1',
108108
}),

0 commit comments

Comments
 (0)