fix(test runner): dispatcher transformation of empty attachments (#11414)

This commit is contained in:
Ross Wollman 2022-01-17 18:47:24 -08:00 committed by GitHub
parent 59b677139e
commit 33f32368e5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 31 additions and 1 deletions

View file

@ -204,7 +204,7 @@ export class Dispatcher {
name: a.name,
path: a.path,
contentType: a.contentType,
body: a.body ? Buffer.from(a.body, 'base64') : undefined
body: typeof a.body !== 'undefined' ? Buffer.from(a.body, 'base64') : undefined
}));
result.status = params.status;
test.expectedStatus = params.expectedStatus;

View file

@ -143,3 +143,33 @@ test(`testInfo.attach success in fixture`, async ({ runInlineTest }) => {
expect(result.failed).toBe(1);
expect(stripAscii(result.output)).toContain('attachment #1: name (text/plain)');
});
test(`testInfo.attach allow empty string body`, async ({ runInlineTest }) => {
const result = await runInlineTest({
'a.test.js': `
const { test } = pwt;
test('success', async ({}, testInfo) => {
await testInfo.attach('name', { body: '', contentType: 'text/plain' });
expect(0).toBe(1);
});
`,
});
expect(result.exitCode).toBe(1);
expect(result.failed).toBe(1);
expect(stripAscii(result.output)).toMatch(/^.*attachment #1: name \(text\/plain\).*\n.*\n.*------/gm);
});
test(`testInfo.attach allow empty buffer body`, async ({ runInlineTest }) => {
const result = await runInlineTest({
'a.test.js': `
const { test } = pwt;
test('success', async ({}, testInfo) => {
await testInfo.attach('name', { body: Buffer.from(''), contentType: 'text/plain' });
expect(0).toBe(1);
});
`,
});
expect(result.exitCode).toBe(1);
expect(result.failed).toBe(1);
expect(stripAscii(result.output)).toMatch(/^.*attachment #1: name \(text\/plain\).*\n.*\n.*------/gm);
});