Skip to content

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.

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

Ross Wollman33f32368e555
diff --git a/packages/playwright-test/src/dispatcher.ts b/packages/playwright-test/src/dispatcher.ts
index cf6514249e..9edccad679 100644
--- a/packages/playwright-test/src/dispatcher.ts
+++ b/packages/playwright-test/src/dispatcher.ts
@@ -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;
diff --git a/tests/playwright-test/reporter-attachment.spec.ts b/tests/playwright-test/reporter-attachment.spec.ts
index 94d6dc0ae5..095f300a7f 100644
--- a/tests/playwright-test/reporter-attachment.spec.ts
+++ b/tests/playwright-test/reporter-attachment.spec.ts
@@ -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);
+});