fix(trace): do not attach screenshots twice (#26971)

This commit is contained in:
Pavel Feldman 2023-09-08 18:00:12 -07:00 committed by GitHub
parent 2feae015aa
commit 80b9e02837
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 14 deletions

View file

@ -25,9 +25,10 @@ import type { Annotation, FullConfigInternal, FullProjectInternal } from '../com
import type { Location } from '../../types/testReporter'; import type { Location } from '../../types/testReporter';
import { getContainedPath, normalizeAndSaveAttachment, serializeError, trimLongString } from '../util'; import { getContainedPath, normalizeAndSaveAttachment, serializeError, trimLongString } from '../util';
import { TestTracing } from './testTracing'; import { TestTracing } from './testTracing';
import type { Attachment } from './testTracing';
export interface TestStepInternal { export interface TestStepInternal {
complete(result: { error?: Error | TestInfoError }): void; complete(result: { error?: Error | TestInfoError, attachments?: Attachment[] }): void;
stepId: string; stepId: string;
title: string; title: string;
category: string; category: string;
@ -261,8 +262,6 @@ export class TestInfoImpl implements TestInfo {
isLaxParent = !!parentStep; isLaxParent = !!parentStep;
} }
const initialAttachments = new Set(this.attachments);
const step: TestStepInternal = { const step: TestStepInternal = {
stepId, stepId,
...data, ...data,
@ -304,7 +303,7 @@ export class TestInfoImpl implements TestInfo {
}; };
this._onStepEnd(payload); this._onStepEnd(payload);
const errorForTrace = error ? { name: '', message: error.message || '', stack: error.stack } : undefined; const errorForTrace = error ? { name: '', message: error.message || '', stack: error.stack } : undefined;
this._tracing.appendAfterActionForStep(stepId, this.attachments, initialAttachments, errorForTrace); this._tracing.appendAfterActionForStep(stepId, errorForTrace, result.attachments);
} }
}; };
const parentStepList = parentStep ? parentStep.steps : this._steps; const parentStepList = parentStep ? parentStep.steps : this._steps;
@ -380,11 +379,6 @@ export class TestInfoImpl implements TestInfo {
wallTime: Date.now(), wallTime: Date.now(),
laxParent: true, laxParent: true,
}); });
this._attachWithoutStep(attachment);
step.complete({});
}
_attachWithoutStep(attachment: TestInfo['attachments'][0]) {
this._attachmentsPush(attachment); this._attachmentsPush(attachment);
this._onAttach({ this._onAttach({
testId: this._test.id, testId: this._test.id,
@ -393,6 +387,7 @@ export class TestInfoImpl implements TestInfo {
path: attachment.path, path: attachment.path,
body: attachment.body?.toString('base64') body: attachment.body?.toString('base64')
}); });
step.complete({ attachments: [attachment] });
} }
outputPath(...pathSegments: string[]){ outputPath(...pathSegments: string[]){

View file

@ -24,7 +24,7 @@ import { yauzl, yazl } from 'playwright-core/lib/zipBundle';
import type { TestInfo } from '../../types/test'; import type { TestInfo } from '../../types/test';
type Attachment = TestInfo['attachments'][0]; export type Attachment = TestInfo['attachments'][0];
export const testTraceEntryName = 'test.trace'; export const testTraceEntryName = 'test.trace';
export class TestTracing { export class TestTracing {
@ -125,13 +125,13 @@ export class TestTracing {
}); });
} }
appendAfterActionForStep(callId: string, attachments: Attachment[], initialAttachments: Set<Attachment>, error?: SerializedError['error']) { appendAfterActionForStep(callId: string, error?: SerializedError['error'], attachments: Attachment[] = []) {
this._appendTraceEvent({ this._appendTraceEvent({
type: 'after', type: 'after',
callId, callId,
endTime: monotonicTime(), endTime: monotonicTime(),
log: [], log: [],
attachments: serializeAttachments(attachments, initialAttachments), attachments: serializeAttachments(attachments),
error, error,
}); });
} }
@ -143,8 +143,8 @@ export class TestTracing {
} }
} }
function serializeAttachments(attachments: Attachment[], initialAttachments: Set<Attachment>): trace.AfterActionTraceEvent['attachments'] { function serializeAttachments(attachments: Attachment[]): trace.AfterActionTraceEvent['attachments'] {
return attachments.filter(a => a.name !== 'trace' && !initialAttachments.has(a)).map(a => { return attachments.filter(a => a.name !== 'trace').map(a => {
return { return {
name: a.name, name: a.name,
contentType: a.contentType, contentType: a.contentType,