Skip to content

Commit d59972a

Browse files
committed
cherry-pick(#22050): fix(tracing): allow disabling tracing through env
We point `tracesDir` inside `test-results`, so it is removed between test runs, while reused context is still writing there. To fix the issue, we can now pass `env.PW_TEST_REUSE_CONTEXT`. References #21993.
1 parent c132756 commit d59972a

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

packages/playwright-test/src/index.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ const playwrightFixtures: Fixtures<TestFixtures, WorkerFixtures> = ({
239239

240240
_snapshotSuffix: [process.platform, { scope: 'worker' }],
241241

242-
_setupContextOptionsAndArtifacts: [async ({ playwright, _snapshotSuffix, _combinedContextOptions, _artifactsDir, trace, screenshot, actionTimeout, navigationTimeout, testIdAttribute }, use, testInfo) => {
242+
_setupContextOptionsAndArtifacts: [async ({ playwright, _contextReuseMode, _snapshotSuffix, _combinedContextOptions, _artifactsDir, trace, screenshot, actionTimeout, navigationTimeout, testIdAttribute }, use, testInfo) => {
243243
if (testIdAttribute)
244244
playwrightLibrary.selectors.setTestIdAttribute(testIdAttribute);
245245
testInfo.snapshotSuffix = _snapshotSuffix;
@@ -251,7 +251,7 @@ const playwrightFixtures: Fixtures<TestFixtures, WorkerFixtures> = ({
251251
const traceMode = normalizeTraceMode(trace);
252252
const defaultTraceOptions = { screenshots: true, snapshots: true, sources: true };
253253
const traceOptions = typeof trace === 'string' ? defaultTraceOptions : { ...defaultTraceOptions, ...trace, mode: undefined };
254-
const captureTrace = shouldCaptureTrace(traceMode, testInfo);
254+
const captureTrace = shouldCaptureTrace(traceMode, testInfo) && !process.env.PW_TEST_DISABLE_TRACING;
255255
const temporaryTraceFiles: string[] = [];
256256
const temporaryScreenshots: string[] = [];
257257
const testInfoImpl = testInfo as TestInfoImpl;
@@ -603,7 +603,7 @@ type ParsedStackTrace = {
603603
apiName: string;
604604
};
605605

606-
export function normalizeVideoMode(video: VideoMode | 'retry-with-video' | { mode: VideoMode } | undefined): VideoMode {
606+
function normalizeVideoMode(video: VideoMode | 'retry-with-video' | { mode: VideoMode } | undefined): VideoMode {
607607
if (!video)
608608
return 'off';
609609
let videoMode = typeof video === 'string' ? video : video.mode;
@@ -616,7 +616,7 @@ function shouldCaptureVideo(videoMode: VideoMode, testInfo: TestInfo) {
616616
return (videoMode === 'on' || videoMode === 'retain-on-failure' || (videoMode === 'on-first-retry' && testInfo.retry === 1));
617617
}
618618

619-
export function normalizeTraceMode(trace: TraceMode | 'retry-with-trace' | { mode: TraceMode } | undefined): TraceMode {
619+
function normalizeTraceMode(trace: TraceMode | 'retry-with-trace' | { mode: TraceMode } | undefined): TraceMode {
620620
if (!trace)
621621
return 'off';
622622
let traceMode = typeof trace === 'string' ? trace : trace.mode;

tests/playwright-test/playwright.trace.spec.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,3 +286,21 @@ test('should respect --trace', async ({ runInlineTest }, testInfo) => {
286286
expect(result.passed).toBe(1);
287287
expect(fs.existsSync(testInfo.outputPath('test-results', 'a-test-1', 'trace.zip'))).toBeTruthy();
288288
});
289+
290+
test('should respect PW_TEST_DISABLE_TRACING', async ({ runInlineTest }, testInfo) => {
291+
const result = await runInlineTest({
292+
'playwright.config.ts': `
293+
export default { use: { trace: 'on' } };
294+
`,
295+
'a.spec.ts': `
296+
import { test, expect } from '@playwright/test';
297+
test('test 1', async ({ page }) => {
298+
await page.goto('about:blank');
299+
});
300+
`,
301+
}, {}, { PW_TEST_DISABLE_TRACING: '1' });
302+
303+
expect(result.exitCode).toBe(0);
304+
expect(result.passed).toBe(1);
305+
expect(fs.existsSync(testInfo.outputPath('test-results', 'a-test-1', 'trace.zip'))).toBe(false);
306+
});

0 commit comments

Comments
 (0)