test: ensure that attachments are available in onStepEnd (#34590)

This commit is contained in:
Simon Knott 2025-02-03 13:54:28 +01:00 committed by GitHub
parent 4e2d82e6c2
commit ebf82b0854
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 29 additions and 0 deletions

View File

@ -734,3 +734,32 @@ test('step attachments are referentially equal to result attachments', async ({
{ title: 'After Hooks', attachments: [] },
]);
});
test('attachments are reported in onStepEnd', { annotation: { type: 'issue', description: 'https://github.com/microsoft/playwright/issues/14364' } }, async ({ runInlineTest }) => {
class TestReporter implements Reporter {
onStepEnd(test: TestCase, result: TestResult, step: TestStep) {
console.log(`%%${step.title}: ${result.attachments.length} attachments in result`);
}
}
const result = await runInlineTest({
'reporter.ts': `module.exports = ${TestReporter.toString()}`,
'playwright.config.ts': `module.exports = { reporter: './reporter' };`,
'a.spec.ts': `
import { test, expect } from '@playwright/test';
test('test', async ({}, testInfo) => {
await test.step('step', async () => {
testInfo.attachments.push({ name: 'attachment', body: Buffer.from('content') });
});
await testInfo.attach('4', {body:'444'})
});
`,
}, { 'reporter': '', 'workers': 1 });
expect(result.outputLines).toEqual([
'Before Hooks: 0 attachments in result',
'step: 1 attachments in result',
'attach "4": 2 attachments in result',
'After Hooks: 2 attachments in result',
]);
});