chore: opt out of trace attachments (#23139)

Fixes: https://github.com/microsoft/playwright/issues/23137
This commit is contained in:
Pavel Feldman 2023-05-18 11:27:45 -07:00 коммит произвёл GitHub
Родитель a1fc8ff07d
Коммит 3395a28181
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
4 изменённых файлов: 11 добавлений и 4 удалений

Просмотреть файл

@ -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.

Просмотреть файл

@ -558,7 +558,7 @@ class ArtifactsRecorder {
private _traceMode: TraceMode;
private _captureTrace = false;
private _screenshotOptions: { mode: ScreenshotMode } & Pick<playwrightLibrary.PageScreenshotOptions, 'fullPage' | 'omitBackground'> | 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<BrowserContext>();
@ -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);

2
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.

2
utils/generate_types/overrides-test.d.ts поставляемый
Просмотреть файл

@ -206,7 +206,7 @@ export interface PlaywrightWorkerOptions {
launchOptions: LaunchOptions;
connectOptions: ConnectOptions | undefined;
screenshot: ScreenshotMode | { mode: ScreenshotMode } & Pick<PageScreenshotOptions, 'fullPage' | 'omitBackground'>;
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 };
}