From 3395a281815220f92b1429f14ee1a54ba752f954 Mon Sep 17 00:00:00 2001 From: Pavel Feldman Date: Thu, 18 May 2023 11:27:45 -0700 Subject: [PATCH] chore: opt out of trace attachments (#23139) Fixes: https://github.com/microsoft/playwright/issues/23137 --- docs/src/test-api/class-testoptions.md | 1 + packages/playwright-test/src/index.ts | 10 ++++++++-- packages/playwright-test/types/test.d.ts | 2 +- utils/generate_types/overrides-test.d.ts | 2 +- 4 files changed, 11 insertions(+), 4 deletions(-) diff --git a/docs/src/test-api/class-testoptions.md b/docs/src/test-api/class-testoptions.md index 6c9154faaa..6ce6ad75e3 100644 --- a/docs/src/test-api/class-testoptions.md +++ b/docs/src/test-api/class-testoptions.md @@ -526,6 +526,7 @@ export default defineConfig({ * since: v1.10 - type: <[Object]|[TraceMode]<"off"|"on"|"retain-on-failure"|"on-first-retry">> - `mode` <[TraceMode]<"off"|"on"|"retain-on-failure"|"on-first-retry"|"on-all-retries">> Trace recording mode. + - `attachments` ?<[boolean]> Whether to include test attachments. Defaults to true. Optional. - `screenshots` ?<[boolean]> Whether to capture screenshots during tracing. Screenshots are used to build a timeline preview. Defaults to true. Optional. - `snapshots` ?<[boolean]> Whether to capture DOM snapshot on every action. Defaults to true. Optional. - `sources` ?<[boolean]> Whether to include source files for trace actions. Defaults to true. Optional. diff --git a/packages/playwright-test/src/index.ts b/packages/playwright-test/src/index.ts index 4a0f88f8d8..c719e21f84 100644 --- a/packages/playwright-test/src/index.ts +++ b/packages/playwright-test/src/index.ts @@ -558,7 +558,7 @@ class ArtifactsRecorder { private _traceMode: TraceMode; private _captureTrace = false; private _screenshotOptions: { mode: ScreenshotMode } & Pick | undefined; - private _traceOptions: { screenshots: boolean, snapshots: boolean, sources: boolean, mode?: TraceMode }; + private _traceOptions: { screenshots: boolean, snapshots: boolean, sources: boolean, attachments: boolean, mode?: TraceMode }; private _temporaryTraceFiles: string[] = []; private _temporaryScreenshots: string[] = []; private _reusedContexts = new Set(); @@ -572,7 +572,7 @@ class ArtifactsRecorder { this._screenshotMode = normalizeScreenshotMode(screenshot); this._screenshotOptions = typeof screenshot === 'string' ? undefined : screenshot; this._traceMode = normalizeTraceMode(trace); - const defaultTraceOptions = { screenshots: true, snapshots: true, sources: true }; + const defaultTraceOptions = { screenshots: true, snapshots: true, sources: true, attachments: true }; this._traceOptions = typeof trace === 'string' ? defaultTraceOptions : { ...defaultTraceOptions, ...trace, mode: undefined }; this._screenshottedSymbol = Symbol('screenshotted'); this._startedCollectingArtifacts = Symbol('startedCollectingArtifacts'); @@ -661,6 +661,12 @@ class ArtifactsRecorder { if (this._preserveTrace()) { const events = this._testInfo._traceEvents; if (events.length) { + if (!this._traceOptions.attachments) { + for (const event of events) { + if (event.type === 'after') + delete event.attachments; + } + } const tracePath = path.join(this._artifactsDir, createGuid() + '.zip'); this._temporaryTraceFiles.push(tracePath); await saveTraceFile(tracePath, events, this._traceOptions.sources); diff --git a/packages/playwright-test/types/test.d.ts b/packages/playwright-test/types/test.d.ts index 5a5e1828f0..32d96c846e 100644 --- a/packages/playwright-test/types/test.d.ts +++ b/packages/playwright-test/types/test.d.ts @@ -3554,7 +3554,7 @@ export interface PlaywrightWorkerOptions { * * Learn more about [recording trace](https://playwright.dev/docs/test-configuration#record-test-trace). */ - trace: TraceMode | /** deprecated */ 'retry-with-trace' | { mode: TraceMode, snapshots?: boolean, screenshots?: boolean, sources?: boolean }; + trace: TraceMode | /** deprecated */ 'retry-with-trace' | { mode: TraceMode, snapshots?: boolean, screenshots?: boolean, sources?: boolean, attachments?: boolean }; /** * Whether to record video for each test. Defaults to `'off'`. * - `'off'`: Do not record video. diff --git a/utils/generate_types/overrides-test.d.ts b/utils/generate_types/overrides-test.d.ts index 1a34759636..f9a9e6b56c 100644 --- a/utils/generate_types/overrides-test.d.ts +++ b/utils/generate_types/overrides-test.d.ts @@ -206,7 +206,7 @@ export interface PlaywrightWorkerOptions { launchOptions: LaunchOptions; connectOptions: ConnectOptions | undefined; screenshot: ScreenshotMode | { mode: ScreenshotMode } & Pick; - trace: TraceMode | /** deprecated */ 'retry-with-trace' | { mode: TraceMode, snapshots?: boolean, screenshots?: boolean, sources?: boolean }; + trace: TraceMode | /** deprecated */ 'retry-with-trace' | { mode: TraceMode, snapshots?: boolean, screenshots?: boolean, sources?: boolean, attachments?: boolean }; video: VideoMode | /** deprecated */ 'retry-with-video' | { mode: VideoMode, size?: ViewportSize }; }