Skip to content

Commit b8f2857

Browse files
authored
fix(html): handle user attachments named stdout and stderr (#43576)
user attachments can have a `Buffer` body or only a path, which crashes HTML report generation when named `stdout` or `stderr` only merge and strip ANSI escapes from captured output with a string body fixes <#43555>
1 parent 20a2087 commit b8f2857

2 files changed

Lines changed: 15 additions & 3 deletions

File tree

‎packages/playwright/src/reporters/html.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -566,7 +566,7 @@ class HtmlBuilder {
566566
if (a.name === 'trace')
567567
this._hasTraces = true;
568568

569-
if ((a.name === 'stdout' || a.name === 'stderr') && a.contentType === 'text/plain') {
569+
if ((a.name === 'stdout' || a.name === 'stderr') && a.contentType === 'text/plain' && typeof a.body === 'string') {
570570
if (lastAttachment &&
571571
lastAttachment.name === a.name &&
572572
lastAttachment.contentType === a.contentType) {

‎tests/playwright-test/reporter-html.spec.ts‎

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1179,8 +1179,11 @@ for (const useIntermediateMergeReport of [true, false] as const) {
11791179
expect(popup.url()).toBe(server.EMPTY_PAGE);
11801180
});
11811181

1182-
test('should render text attachments as text', async ({ runInlineTest, page, showReport }) => {
1182+
test('should render text attachments as text', {
1183+
annotation: { type: 'issue', description: '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/microsoft/playwright/issues/43555' },
1184+
}, async ({ runInlineTest, page, showReport }) => {
11831185
const result = await runInlineTest({
1186+
'log.txt': 'stderr attachment',
11841187
'a.test.js': `
11851188
import { test, expect } from '@playwright/test';
11861189
test('passing', async ({ page }, testInfo) => {
@@ -1207,6 +1210,9 @@ for (const useIntermediateMergeReport of [true, false] as const) {
12071210
contentType: 'text/plain, charset=utf16le',
12081211
body: null,
12091212
});
1213+
1214+
await testInfo.attach('stdout', { body: 'stdout attachment' });
1215+
await testInfo.attach('stderr', { path: 'log.txt' });
12101216
});
12111217
`,
12121218
}, { reporter: 'dot,html' }, { PLAYWRIGHT_HTML_OPEN: 'never' });
@@ -1217,7 +1223,13 @@ for (const useIntermediateMergeReport of [true, false] as const) {
12171223
await page.getByText('example.txt', { exact: true }).click();
12181224
await page.getByText('example.json', { exact: true }).click();
12191225
await page.getByText('example-utf16.txt', { exact: true }).click();
1220-
await expect(page.locator('.attachment-body')).toHaveText(['foo', '{"foo":1}', 'utf16 encoded']);
1226+
await page.getByText('stdout', { exact: true }).click();
1227+
await expect(page.locator('.attachment-body')).toHaveText(['foo', '{"foo":1}', 'utf16 encoded', 'stdout attachment']);
1228+
1229+
const downloadPromise = page.waitForEvent('download');
1230+
await page.getByRole('link', { name: 'stderr', exact: true }).click();
1231+
const download = await downloadPromise;
1232+
expect(await readAllFromStream(await download.createReadStream())).toEqual(Buffer.from('stderr attachment'));
12211233
});
12221234

12231235
test('should have link for opening HTML attachments in new tab', async ({ runInlineTest, page, showReport }) => {

0 commit comments

Comments
 (0)