feat: add logic for capturing and abandoning trace when using on-first-failure mode

This commit is contained in:
Stevan Freeborn 2024-02-23 18:38:01 -06:00
parent fd38fe8dc2
commit 05cdbdf362

View file

@ -54,6 +54,7 @@ export class TestTracing {
if (this._options?.mode === 'retain-on-failure') capture = true; if (this._options?.mode === 'retain-on-failure') capture = true;
if (this._options?.mode === 'on-first-retry' && this._testInfo.retry === 1) capture = true; if (this._options?.mode === 'on-first-retry' && this._testInfo.retry === 1) capture = true;
if (this._options?.mode === 'on-all-retries' && this._testInfo.retry > 0) capture = true; if (this._options?.mode === 'on-all-retries' && this._testInfo.retry > 0) capture = true;
if (this._options?.mode === 'on-first-failure' && this._testInfo.retry === 0) capture = true;
return capture && !process.env.PW_TEST_DISABLE_TRACING; return capture && !process.env.PW_TEST_DISABLE_TRACING;
} }
@ -119,7 +120,8 @@ export class TestTracing {
return; return;
const testFailed = this._testInfo.status !== this._testInfo.expectedStatus; const testFailed = this._testInfo.status !== this._testInfo.expectedStatus;
const shouldAbandonTrace = !testFailed && this._options.mode === 'retain-on-failure'; const shouldAbandonTrace = !testFailed && (this._options.mode === 'retain-on-failure' || this._options.mode === 'on-first-failure');
if (shouldAbandonTrace) { if (shouldAbandonTrace) {
for (const file of this._temporaryTraceFiles) for (const file of this._temporaryTraceFiles)
await fs.promises.unlink(file).catch(() => {}); await fs.promises.unlink(file).catch(() => {});