Skip to content

Commit ba62e6a

Browse files
Skn0ttmxschmitt
authored andcommitted
cherry-pick(#37149): fix(test): attaching in boxed fixture
1 parent 25bb073 commit ba62e6a

File tree

3 files changed

+60
-1
lines changed

3 files changed

+60
-1
lines changed

packages/playwright/src/worker/testInfo.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,10 @@ export class TestInfoImpl implements TestInfo {
484484
title: `Attach ${escapeWithQuotes(name, '"')}`,
485485
category: 'test.attach',
486486
});
487-
this._attach(await normalizeAndSaveAttachment(this.outputPath(), name, options), step.stepId);
487+
this._attach(
488+
await normalizeAndSaveAttachment(this.outputPath(), name, options),
489+
step.group ? undefined : step.stepId
490+
);
488491
step.complete({});
489492
}
490493

tests/playwright-test/reporter-attachment.spec.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,3 +322,30 @@ test('render text attachment with multiple lines', async ({ runInlineTest }) =>
322322
expect(text).toContain(' ────────────────────────────────────────────────────────────────────────────────────────────────');
323323
expect(result.exitCode).toBe(1);
324324
});
325+
326+
test('attaching inside boxed fixture should not log error', { annotation: { type: 'issue', description: 'https://github.com/microsoft/playwright/issues/37147' } }, async ({ runInlineTest }) => {
327+
const result = await runInlineTest({
328+
'a.test.ts': `
329+
import { test as base } from '@playwright/test';
330+
331+
const test = base.extend<{ myFixture: void }>({
332+
myFixture: [async ({}, use, testInfo) => {
333+
await testInfo.attach('my attachment', {
334+
body: 'foo',
335+
contentType: 'text/plain',
336+
});
337+
await use();
338+
}, { box: true }],
339+
});
340+
341+
test('my test', ({ myFixture }) => {
342+
expect(1).toBe(0);
343+
});
344+
`,
345+
}, { reporter: 'line' }, {});
346+
const text = result.output;
347+
expect(text).toContain(' attachment #1: my attachment (text/plain) ──────────────────────────────────────────────────────');
348+
expect(text).toContain(' foo');
349+
expect(text).toContain(' ────────────────────────────────────────────────────────────────────────────────────────────────');
350+
expect(result.exitCode).toBe(1);
351+
});

tests/playwright-test/ui-mode-test-attachments.spec.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,35 @@ test('should link from attachment step to attachments view', async ({ runUITest
173173
await expect(attachment).toBeInViewport();
174174
});
175175

176+
test('attachments from inside boxed fixture should be visible', { annotation: { type: 'issue', description: 'https://github.com/microsoft/playwright/issues/37147' } }, async ({ runUITest }) => {
177+
const { page } = await runUITest({
178+
'a.test.ts': `
179+
import { test as base } from '@playwright/test';
180+
181+
const test = base.extend<{ myFixture: void }>({
182+
myFixture: [async ({}, use, testInfo) => {
183+
await testInfo.attach('my attachment', {
184+
body: 'foo',
185+
contentType: 'text/plain',
186+
});
187+
await use();
188+
}, { box: true }],
189+
});
190+
191+
test('my test', ({ myFixture }) => {});
192+
`,
193+
}, { reporter: 'line' }, {});
194+
await page.getByText('my test').click();
195+
await page.getByTitle('Run all').click();
196+
await expect(page.getByTestId('status-line')).toHaveText('1/1 passed (100%)');
197+
198+
await page.getByRole('treeitem', { name: 'attach "my attachment"' }).getByLabel('Open Attachment').click();
199+
await expect(page.getByRole('tabpanel', { name: 'Attachments' })).toMatchAriaSnapshot(`
200+
- tabpanel:
201+
- button /my attachment/
202+
`);
203+
});
204+
176205
function readAllFromStream(stream: NodeJS.ReadableStream): Promise<Buffer> {
177206
return new Promise(resolve => {
178207
const chunks: Buffer[] = [];

0 commit comments

Comments
 (0)