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.
This commit is contained in:
parent
c132756306
commit
d59972aeb7
|
|
@ -239,7 +239,7 @@ const playwrightFixtures: Fixtures<TestFixtures, WorkerFixtures> = ({
|
||||||
|
|
||||||
_snapshotSuffix: [process.platform, { scope: 'worker' }],
|
_snapshotSuffix: [process.platform, { scope: 'worker' }],
|
||||||
|
|
||||||
_setupContextOptionsAndArtifacts: [async ({ playwright, _snapshotSuffix, _combinedContextOptions, _artifactsDir, trace, screenshot, actionTimeout, navigationTimeout, testIdAttribute }, use, testInfo) => {
|
_setupContextOptionsAndArtifacts: [async ({ playwright, _contextReuseMode, _snapshotSuffix, _combinedContextOptions, _artifactsDir, trace, screenshot, actionTimeout, navigationTimeout, testIdAttribute }, use, testInfo) => {
|
||||||
if (testIdAttribute)
|
if (testIdAttribute)
|
||||||
playwrightLibrary.selectors.setTestIdAttribute(testIdAttribute);
|
playwrightLibrary.selectors.setTestIdAttribute(testIdAttribute);
|
||||||
testInfo.snapshotSuffix = _snapshotSuffix;
|
testInfo.snapshotSuffix = _snapshotSuffix;
|
||||||
|
|
@ -251,7 +251,7 @@ const playwrightFixtures: Fixtures<TestFixtures, WorkerFixtures> = ({
|
||||||
const traceMode = normalizeTraceMode(trace);
|
const traceMode = normalizeTraceMode(trace);
|
||||||
const defaultTraceOptions = { screenshots: true, snapshots: true, sources: true };
|
const defaultTraceOptions = { screenshots: true, snapshots: true, sources: true };
|
||||||
const traceOptions = typeof trace === 'string' ? defaultTraceOptions : { ...defaultTraceOptions, ...trace, mode: undefined };
|
const traceOptions = typeof trace === 'string' ? defaultTraceOptions : { ...defaultTraceOptions, ...trace, mode: undefined };
|
||||||
const captureTrace = shouldCaptureTrace(traceMode, testInfo);
|
const captureTrace = shouldCaptureTrace(traceMode, testInfo) && !process.env.PW_TEST_DISABLE_TRACING;
|
||||||
const temporaryTraceFiles: string[] = [];
|
const temporaryTraceFiles: string[] = [];
|
||||||
const temporaryScreenshots: string[] = [];
|
const temporaryScreenshots: string[] = [];
|
||||||
const testInfoImpl = testInfo as TestInfoImpl;
|
const testInfoImpl = testInfo as TestInfoImpl;
|
||||||
|
|
@ -603,7 +603,7 @@ type ParsedStackTrace = {
|
||||||
apiName: string;
|
apiName: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
export function normalizeVideoMode(video: VideoMode | 'retry-with-video' | { mode: VideoMode } | undefined): VideoMode {
|
function normalizeVideoMode(video: VideoMode | 'retry-with-video' | { mode: VideoMode } | undefined): VideoMode {
|
||||||
if (!video)
|
if (!video)
|
||||||
return 'off';
|
return 'off';
|
||||||
let videoMode = typeof video === 'string' ? video : video.mode;
|
let videoMode = typeof video === 'string' ? video : video.mode;
|
||||||
|
|
@ -616,7 +616,7 @@ function shouldCaptureVideo(videoMode: VideoMode, testInfo: TestInfo) {
|
||||||
return (videoMode === 'on' || videoMode === 'retain-on-failure' || (videoMode === 'on-first-retry' && testInfo.retry === 1));
|
return (videoMode === 'on' || videoMode === 'retain-on-failure' || (videoMode === 'on-first-retry' && testInfo.retry === 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
export function normalizeTraceMode(trace: TraceMode | 'retry-with-trace' | { mode: TraceMode } | undefined): TraceMode {
|
function normalizeTraceMode(trace: TraceMode | 'retry-with-trace' | { mode: TraceMode } | undefined): TraceMode {
|
||||||
if (!trace)
|
if (!trace)
|
||||||
return 'off';
|
return 'off';
|
||||||
let traceMode = typeof trace === 'string' ? trace : trace.mode;
|
let traceMode = typeof trace === 'string' ? trace : trace.mode;
|
||||||
|
|
|
||||||
|
|
@ -286,3 +286,21 @@ test('should respect --trace', async ({ runInlineTest }, testInfo) => {
|
||||||
expect(result.passed).toBe(1);
|
expect(result.passed).toBe(1);
|
||||||
expect(fs.existsSync(testInfo.outputPath('test-results', 'a-test-1', 'trace.zip'))).toBeTruthy();
|
expect(fs.existsSync(testInfo.outputPath('test-results', 'a-test-1', 'trace.zip'))).toBeTruthy();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('should respect PW_TEST_DISABLE_TRACING', async ({ runInlineTest }, testInfo) => {
|
||||||
|
const result = await runInlineTest({
|
||||||
|
'playwright.config.ts': `
|
||||||
|
export default { use: { trace: 'on' } };
|
||||||
|
`,
|
||||||
|
'a.spec.ts': `
|
||||||
|
import { test, expect } from '@playwright/test';
|
||||||
|
test('test 1', async ({ page }) => {
|
||||||
|
await page.goto('about:blank');
|
||||||
|
});
|
||||||
|
`,
|
||||||
|
}, {}, { PW_TEST_DISABLE_TRACING: '1' });
|
||||||
|
|
||||||
|
expect(result.exitCode).toBe(0);
|
||||||
|
expect(result.passed).toBe(1);
|
||||||
|
expect(fs.existsSync(testInfo.outputPath('test-results', 'a-test-1', 'trace.zip'))).toBe(false);
|
||||||
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue