chore: do not store empty step.attachments[] in trace (#34579)

This commit is contained in:
Yury Semikhatsky 2025-02-05 08:30:03 -08:00 committed by GitHub
parent cb208836b5
commit f1a392f844
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 4 additions and 2 deletions

View file

@ -256,7 +256,7 @@ export class TeleReporterEmitter implements ReporterV2 {
id: (step as any)[this._idSymbol],
duration: step.duration,
error: step.error,
attachments: step.attachments.map(a => result.attachments.indexOf(a)),
attachments: step.attachments.length ? step.attachments.map(a => result.attachments.indexOf(a)) : undefined,
annotations: step.annotations.length ? step.annotations : undefined,
};
}

View file

@ -278,6 +278,8 @@ export class TestTracing {
}
function serializeAttachments(attachments: Attachment[]): trace.AfterActionTraceEvent['attachments'] {
if (attachments.length === 0)
return undefined;
return attachments.filter(a => a.name !== 'trace').map(a => {
return {
name: a.name,

View file

@ -761,7 +761,7 @@ test('should not throw when screenshot on failure fails', async ({ runInlineTest
expect(result.exitCode).toBe(0);
expect(result.passed).toBe(1);
const trace = await parseTrace(testInfo.outputPath('test-results', 'a-has-download-page', 'trace.zip'));
const attachedScreenshots = trace.actions.flatMap(a => a.attachments);
const attachedScreenshots = trace.actions.filter(a => a.attachments).flatMap(a => a.attachments);
// One screenshot for the page, no screenshot for the download page since it should have failed.
expect(attachedScreenshots.length).toBe(1);
});