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 { getContainedPath, normalizeAndSaveAttachment, serializeError, trimLongString } from '../util';
import { TestTracing } from './testTracing';
import type { Attachment } from './testTracing';
export interface TestStepInternal {
complete(result: { error?: Error | TestInfoError }): void;
complete(result: { error?: Error | TestInfoError, attachments?: Attachment[] }): void;
stepId: string;
title: string;
category: string;
@ -261,8 +262,6 @@ export class TestInfoImpl implements TestInfo {
isLaxParent = !!parentStep;
}
const initialAttachments = new Set(this.attachments);
const step: TestStepInternal = {
stepId,
...data,
@ -304,7 +303,7 @@ export class TestInfoImpl implements TestInfo {
};
this._onStepEnd(payload);
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;
@ -380,11 +379,6 @@ export class TestInfoImpl implements TestInfo {
wallTime: Date.now(),
laxParent: true,
});
this._attachWithoutStep(attachment);
step.complete({});
}
_attachWithoutStep(attachment: TestInfo['attachments'][0]) {
this._attachmentsPush(attachment);
this._onAttach({
testId: this._test.id,
@ -393,6 +387,7 @@ export class TestInfoImpl implements TestInfo {
path: attachment.path,
body: attachment.body?.toString('base64')
});
step.complete({ attachments: [attachment] });
}
outputPath(...pathSegments: string[]){

View File

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