fix(html): encode all stdio attachments (#33950)

This commit is contained in:
Simon Knott 2024-12-13 12:01:20 +01:00 committed by GitHub
parent b0cec5b351
commit dd36de7809
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
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
contentType: 'text/plain',
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);
});
});
}