diff --git a/src/test/reporters/junit.ts b/src/test/reporters/junit.ts index 43ccefe93b..2bebf71bc1 100644 --- a/src/test/reporters/junit.ts +++ b/src/test/reporters/junit.ts @@ -153,6 +153,15 @@ class JUnitReporter implements Reporter { }); } + for (const attachment of result.attachments) { + if (attachment.path) { + entries.push({ + name: 'system-out', + text: `[[ATTACHMENT|${path.relative(this.config.rootDir, attachment.path)}]]` + }); + } + } + for (const stderr of result.stderr) { entries.push({ name: 'system-err', diff --git a/tests/playwright-test/junit-reporter.spec.ts b/tests/playwright-test/junit-reporter.spec.ts index 42f264e7f4..cc12e72a62 100644 --- a/tests/playwright-test/junit-reporter.spec.ts +++ b/tests/playwright-test/junit-reporter.spec.ts @@ -15,6 +15,7 @@ */ import xml2js from 'xml2js'; +import path from 'path'; import { test, expect } from './playwright-test-fixtures'; test('should render expected', async ({ runInlineTest }) => { @@ -220,6 +221,23 @@ test('should render projects', async ({ runInlineTest }) => { expect(result.exitCode).toBe(0); }); +test('should render attachments', async ({ runInlineTest }) => { + const result = await runInlineTest({ + 'a.test.js': ` + const { test } = pwt; + test.use({ screenshot: 'on' }); + test('one', async ({ page }) => { + await page.setContent('hello'); + }); + `, + }, { reporter: 'junit' }); + const xml = parseXML(result.output); + const suite = xml['testsuites']['testsuite'][0]; + expect(suite['system-out'].length).toBe(1); + expect(suite['system-out'][0].trim()).toBe(`[[ATTACHMENT|test-results${path.sep}a-one${path.sep}test-finished-1.png]]`); + expect(result.exitCode).toBe(0); +}); + function parseXML(xml: string): any { let result: any; xml2js.parseString(xml, (err, r) => result = r);