From ed34a67d4a1ef9a52445087934d679f929fced84 Mon Sep 17 00:00:00 2001 From: Dmitry Gozman Date: Mon, 13 Sep 2021 17:50:08 -0700 Subject: [PATCH] fix(junit reporter): put stdio under testcase (#8900) When output happened during test execution, it should be under `...`. --- src/test/reporters/junit.ts | 6 +++--- tests/playwright-test/junit-reporter.spec.ts | 22 ++++++++++---------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/test/reporters/junit.ts b/src/test/reporters/junit.ts index da14fd8135..ef096a9fcb 100644 --- a/src/test/reporters/junit.ts +++ b/src/test/reporters/junit.ts @@ -147,7 +147,7 @@ class JUnitReporter implements Reporter { } for (const result of test.results) { for (const stdout of result.stdout) { - entries.push({ + entry.children.push({ name: 'system-out', text: stdout.toString() }); @@ -155,7 +155,7 @@ class JUnitReporter implements Reporter { for (const attachment of result.attachments) { if (attachment.path) { - entries.push({ + entry.children.push({ name: 'system-out', text: `[[ATTACHMENT|${path.relative(this.config.rootDir, attachment.path)}]]` }); @@ -163,7 +163,7 @@ class JUnitReporter implements Reporter { } for (const stderr of result.stderr) { - entries.push({ + entry.children.push({ name: 'system-err', text: stderr.toString() }); diff --git a/tests/playwright-test/junit-reporter.spec.ts b/tests/playwright-test/junit-reporter.spec.ts index cc12e72a62..22afed280f 100644 --- a/tests/playwright-test/junit-reporter.spec.ts +++ b/tests/playwright-test/junit-reporter.spec.ts @@ -108,11 +108,11 @@ test('should render stdout', async ({ runInlineTest }) => { `, }, { 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]).toContain('Hello world'); - expect(suite['system-out'][0]).not.toContain('u00'); - expect(suite['testcase'][0]['failure'][0]['_']).toContain(`> 9 | test.expect("abc").toBe('abcd');`); + const testcase = xml['testsuites']['testsuite'][0]['testcase'][0]; + expect(testcase['system-out'].length).toBe(1); + expect(testcase['system-out'][0]).toContain('Hello world'); + expect(testcase['system-out'][0]).not.toContain('u00'); + expect(testcase['failure'][0]['_']).toContain(`> 9 | test.expect("abc").toBe('abcd');`); expect(result.exitCode).toBe(1); }); @@ -132,9 +132,9 @@ test('should render stdout without ansi escapes', async ({ runInlineTest }) => { `, }, { reporter: '' }); 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('Hello world'); + const testcase = xml['testsuites']['testsuite'][0]['testcase'][0]; + expect(testcase['system-out'].length).toBe(1); + expect(testcase['system-out'][0].trim()).toBe('Hello world'); expect(result.exitCode).toBe(0); }); @@ -232,9 +232,9 @@ test('should render attachments', async ({ runInlineTest }) => { `, }, { 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]]`); + const testcase = xml['testsuites']['testsuite'][0]['testcase'][0]; + expect(testcase['system-out'].length).toBe(1); + expect(testcase['system-out'][0].trim()).toBe(`[[ATTACHMENT|test-results${path.sep}a-one${path.sep}test-finished-1.png]]`); expect(result.exitCode).toBe(0); });