fix(html): encode all stdio attachments

This commit is contained in:
Simon Knott 2024-12-11 12:48:42 +01:00
parent a14d9750b3
commit 9e6461b2c5
No known key found for this signature in database
GPG key ID: 8CEDC00028084AEC
2 changed files with 20 additions and 9 deletions

View file

@ -602,17 +602,10 @@ type JsonAttachment = {
};
function stdioAttachment(chunk: Buffer | string, type: 'stdout' | 'stderr'): JsonAttachment {
if (typeof chunk === 'string') {
return {
name: type,
contentType: 'text/plain',
body: chunk
};
}
return {
name: type,
contentType: 'application/octet-stream',
body: chunk
body: typeof chunk === 'string' ? chunk : chunk.toString('utf-8')
};
}

View file

@ -2562,6 +2562,24 @@ for (const useIntermediateMergeReport of [true, false] as const) {
- button "tests/b/test.spec.ts"
`);
});
test('execSync doesnt produce a second stdout attachment', { annotation: { type: 'issue', description: 'https://github.com/microsoft/playwright/issues/33886' } }, async ({ runInlineTest, showReport, page }) => {
await runInlineTest({
'a.test.js': `
const { test, expect } = require('@playwright/test');
const { execSync } = require('node:child_process');
test('my test', async ({}) => {
console.log('foo');
execSync('echo bar', { stdio: 'inherit' });
console.log('baz');
});
`,
}, { reporter: 'dot,html' });
await showReport();
await page.getByText('my test').click();
await expect(page.locator('.tree-item', { hasText: 'stdout' })).toHaveCount(1);
});
});
}