feat(junit reporter): add attachments to stdout (#8059)

`JUnitReporter` follows the common format for attachments in JUnit reports,
recognized by GitLab and Jenkins among others.
This commit is contained in:
Dmitry Gozman 2021-08-06 15:47:54 -07:00 committed by GitHub
parent 79e8592146
commit 5f297b6894
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 27 additions and 0 deletions

View file

@ -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',

View file

@ -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);