test referential equality

This commit is contained in:
Simon Knott 2024-10-22 13:35:13 +02:00
parent 339af16429
commit 3610bc4359
No known key found for this signature in database
GPG key ID: 8CEDC00028084AEC

View file

@ -14,6 +14,7 @@
* limitations under the License.
*/
import type { Reporter, TestCase, TestResult, TestStep } from 'packages/playwright-test/reporter';
import { test, expect } from './playwright-test-fixtures';
const smallReporterJS = `
@ -703,3 +704,33 @@ onEnd
onExit
`);
});
test('step attachments are referentially equal to result attachments', async ({ runInlineTest }) => {
class TestReporter implements Reporter {
onStepEnd(test: TestCase, result: TestResult, step: TestStep) {
console.log('%%%', JSON.stringify({
title: step.title,
attachments: step.attachments.map(a => result.attachments.indexOf(a)),
}));
}
}
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') });
});
});
`,
}, { 'reporter': '', 'workers': 1 });
const steps = result.outputLines.map(line => JSON.parse(line));
expect(steps).toEqual([
{ title: 'Before Hooks', attachments: [] },
{ title: 'step', attachments: [0] },
{ title: 'After Hooks', attachments: [] },
]);
});