mirror of
https://github.com/microsoft/playwright.git
synced 2025-06-26 21:40:17 +00:00
fix(tracing): do not throw on missing attachments (#24409)
Fixes #24378.
This commit is contained in:
parent
33d62d9a97
commit
9d0bba9c99
@ -117,15 +117,16 @@ export async function saveTraceFile(fileName: string, traceEvents: TraceEvent[],
|
||||
const sha1s = new Set<string>();
|
||||
for (const event of traceEvents.filter(e => e.type === 'after') as AfterActionTraceEvent[]) {
|
||||
for (const attachment of (event.attachments || [])) {
|
||||
let contentPromise: Promise<Buffer> | undefined;
|
||||
let contentPromise: Promise<Buffer | undefined> | undefined;
|
||||
if (attachment.path)
|
||||
contentPromise = fs.promises.readFile(attachment.path);
|
||||
contentPromise = fs.promises.readFile(attachment.path).catch(() => undefined);
|
||||
else if (attachment.base64)
|
||||
contentPromise = Promise.resolve(Buffer.from(attachment.base64, 'base64'));
|
||||
if (!contentPromise)
|
||||
continue;
|
||||
|
||||
const content = await contentPromise;
|
||||
if (content === undefined)
|
||||
continue;
|
||||
|
||||
const sha1 = calculateSha1(content);
|
||||
attachment.sha1 = sha1;
|
||||
delete attachment.path;
|
||||
|
@ -68,13 +68,7 @@ export const AttachmentsSection: React.FunctionComponent<{
|
||||
</>;
|
||||
};
|
||||
|
||||
function attachmentURL(traceUrl: string, attachment: {
|
||||
name: string;
|
||||
contentType: string;
|
||||
path?: string;
|
||||
sha1?: string;
|
||||
body?: string;
|
||||
}) {
|
||||
function attachmentURL(traceUrl: string, attachment: NonNullable<ActionTraceEventInContext['attachments']>[0]) {
|
||||
if (attachment.sha1)
|
||||
return 'sha1/' + attachment.sha1 + '?trace=' + encodeURIComponent(traceUrl);
|
||||
return 'file?path=' + encodeURIComponent(attachment.path!);
|
||||
|
@ -686,3 +686,22 @@ test('should show non-expect error in trace', async ({ runInlineTest }, testInfo
|
||||
' fixture: context',
|
||||
]);
|
||||
});
|
||||
|
||||
test('should not throw when attachment is missing', async ({ runInlineTest }, testInfo) => {
|
||||
const result = await runInlineTest({
|
||||
'playwright.config.ts': `
|
||||
module.exports = { use: { trace: 'on' } };
|
||||
`,
|
||||
'a.spec.ts': `
|
||||
import { test, expect } from '@playwright/test';
|
||||
test('passes', async ({}) => {
|
||||
test.info().attachments.push({ name: 'screenshot', path: 'nothing-to-see-here', contentType: 'image/png' });
|
||||
});
|
||||
`,
|
||||
}, { workers: 1 });
|
||||
|
||||
expect(result.exitCode).toBe(0);
|
||||
expect(result.passed).toBe(1);
|
||||
const trace = await parseTrace(testInfo.outputPath('test-results', 'a-passes', 'trace.zip'));
|
||||
expect(trace.actionTree).toContain('attach "screenshot"');
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user