mirror of
https://github.com/microsoft/playwright.git
synced 2025-06-26 21:40:17 +00:00
fix(test-runner): undefined body crash with manual attachments (#11995)
The new (as of 1.18) `async testInfo.attach(…)` API handles this gracefully (and is part of the reason for the new API's existence). However, for the foreseeable future, it's still possible to manually push onto the attachments array where we can't validate the contents until it's too late, so this change ensures more graceful handling in that case. Fixes #11565
This commit is contained in:
parent
ab1cc0ed89
commit
0d42c16a17
@ -258,8 +258,8 @@ export function formatFailure(config: FullConfig, test: TestCase, options: {inde
|
||||
resultLines.push('');
|
||||
}
|
||||
} else {
|
||||
if (attachment.contentType.startsWith('text/')) {
|
||||
let text = attachment.body!.toString();
|
||||
if (attachment.contentType.startsWith('text/') && attachment.body) {
|
||||
let text = attachment.body.toString();
|
||||
if (text.length > 300)
|
||||
text = text.slice(0, 300) + '...';
|
||||
resultLines.push(colors.cyan(` ${text}`));
|
||||
|
||||
@ -270,3 +270,22 @@ test('should print "no tests found" error', async ({ runInlineTest }) => {
|
||||
expect(result.exitCode).toBe(1);
|
||||
expect(result.output).toContain('no tests found.');
|
||||
});
|
||||
|
||||
test('should not crash on undefined body with manual attachments', async ({ runInlineTest }) => {
|
||||
const result = await runInlineTest({
|
||||
'a.test.js': `
|
||||
const { test } = pwt;
|
||||
test('one', async ({}, testInfo) => {
|
||||
testInfo.attachments.push({
|
||||
name: 'foo.txt',
|
||||
body: undefined,
|
||||
contentType: 'text/plain'
|
||||
});
|
||||
expect(1).toBe(2);
|
||||
});
|
||||
`,
|
||||
});
|
||||
expect(stripAnsi(result.output)).not.toContain('Error in reporter');
|
||||
expect(result.failed).toBe(1);
|
||||
expect(result.exitCode).toBe(1);
|
||||
});
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user