fix(test): attaching in boxed fixture (#37149)
This commit is contained in:
parent
35cd6fb279
commit
409d13f730
|
|
@ -455,7 +455,10 @@ export class TestInfoImpl implements TestInfo {
|
|||
title: `Attach ${escapeWithQuotes(name, '"')}`,
|
||||
category: 'test.attach',
|
||||
});
|
||||
this._attach(await normalizeAndSaveAttachment(this.outputPath(), name, options), step.stepId);
|
||||
this._attach(
|
||||
await normalizeAndSaveAttachment(this.outputPath(), name, options),
|
||||
step.group ? undefined : step.stepId
|
||||
);
|
||||
step.complete({});
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -322,3 +322,30 @@ test('render text attachment with multiple lines', async ({ runInlineTest }) =>
|
|||
expect(text).toContain(' ────────────────────────────────────────────────────────────────────────────────────────────────');
|
||||
expect(result.exitCode).toBe(1);
|
||||
});
|
||||
|
||||
test('attaching inside boxed fixture should not log error', { annotation: { type: 'issue', description: 'https://github.com/microsoft/playwright/issues/37147' } }, async ({ runInlineTest }) => {
|
||||
const result = await runInlineTest({
|
||||
'a.test.ts': `
|
||||
import { test as base } from '@playwright/test';
|
||||
|
||||
const test = base.extend<{ myFixture: void }>({
|
||||
myFixture: [async ({}, use, testInfo) => {
|
||||
await testInfo.attach('my attachment', {
|
||||
body: 'foo',
|
||||
contentType: 'text/plain',
|
||||
});
|
||||
await use();
|
||||
}, { box: true }],
|
||||
});
|
||||
|
||||
test('my test', ({ myFixture }) => {
|
||||
expect(1).toBe(0);
|
||||
});
|
||||
`,
|
||||
}, { reporter: 'line' }, {});
|
||||
const text = result.output;
|
||||
expect(text).toContain(' attachment #1: my attachment (text/plain) ──────────────────────────────────────────────────────');
|
||||
expect(text).toContain(' foo');
|
||||
expect(text).toContain(' ────────────────────────────────────────────────────────────────────────────────────────────────');
|
||||
expect(result.exitCode).toBe(1);
|
||||
});
|
||||
|
|
|
|||
|
|
@ -173,6 +173,35 @@ test('should link from attachment step to attachments view', async ({ runUITest
|
|||
await expect(attachment).toBeInViewport();
|
||||
});
|
||||
|
||||
test('attachments from inside boxed fixture should be visible', { annotation: { type: 'issue', description: 'https://github.com/microsoft/playwright/issues/37147' } }, async ({ runUITest }) => {
|
||||
const { page } = await runUITest({
|
||||
'a.test.ts': `
|
||||
import { test as base } from '@playwright/test';
|
||||
|
||||
const test = base.extend<{ myFixture: void }>({
|
||||
myFixture: [async ({}, use, testInfo) => {
|
||||
await testInfo.attach('my attachment', {
|
||||
body: 'foo',
|
||||
contentType: 'text/plain',
|
||||
});
|
||||
await use();
|
||||
}, { box: true }],
|
||||
});
|
||||
|
||||
test('my test', ({ myFixture }) => {});
|
||||
`,
|
||||
}, { reporter: 'line' }, {});
|
||||
await page.getByText('my test').click();
|
||||
await page.getByTitle('Run all').click();
|
||||
await expect(page.getByTestId('status-line')).toHaveText('1/1 passed (100%)');
|
||||
|
||||
await page.getByRole('treeitem', { name: 'attach "my attachment"' }).getByLabel('Open Attachment').click();
|
||||
await expect(page.getByRole('tabpanel', { name: 'Attachments' })).toMatchAriaSnapshot(`
|
||||
- tabpanel:
|
||||
- button /my attachment/
|
||||
`);
|
||||
});
|
||||
|
||||
function readAllFromStream(stream: NodeJS.ReadableStream): Promise<Buffer> {
|
||||
return new Promise(resolve => {
|
||||
const chunks: Buffer[] = [];
|
||||
|
|
|
|||
Loading…
Reference in New Issue