Commit 6d6ee2b 1 parent 985cb56 commit 6d6ee2b Copy full SHA for 6d6ee2b
File tree 7 files changed +103
-3
lines changed
packages/test-runner-junit-reporter
7 files changed +103
-3
lines changed Original file line number Diff line number Diff line change
1
+ ---
2
+ ' @web/test-runner-junit-reporter ' : minor
3
+ ---
4
+
5
+ chore: Add support for flat test files to junit reporter
Original file line number Diff line number Diff line change @@ -69,7 +69,7 @@ interface TestSuiteXMLAttributes {
69
69
const assignSessionAndSuitePropertiesToTests = ( {
70
70
testResults,
71
71
...rest
72
- } : TestSession ) : TestResultWithMetadata [ ] => {
72
+ } : TestSession , rootDir : string ) : TestResultWithMetadata [ ] => {
73
73
const assignToTest =
74
74
( parentSuiteName : string ) =>
75
75
( test : TestResult ) : TestResultWithMetadata => {
@@ -87,7 +87,11 @@ const assignSessionAndSuitePropertiesToTests = ({
87
87
88
88
const suites = testResults ?. suites ?? [ ] ;
89
89
90
- return suites . flatMap ( assignToSuite ( '' ) ) ;
90
+ const testsWithoutSuite = testResults ?. tests ?? [ ] ;
91
+
92
+ const suiteName = `${ rest . browser . name } _${ rest . browser . type } _${ rest . testFile . replace ( rootDir , '' ) } ` ;
93
+
94
+ return [ ...suites . flatMap ( assignToSuite ( '' ) ) , ...testsWithoutSuite . flatMap ( assignToTest ( suiteName ) ) ] ;
91
95
} ;
92
96
93
97
const toResultsWithMetadataByBrowserTestFileName = (
@@ -291,7 +295,7 @@ function getTestRunXML({
291
295
} ) : string {
292
296
const testsuites = Object . entries (
293
297
sessions
294
- . flatMap ( assignSessionAndSuitePropertiesToTests )
298
+ . flatMap ( s => assignSessionAndSuitePropertiesToTests ( s , rootDir ) )
295
299
. reduce (
296
300
toResultsWithMetadataByBrowserTestFileName ,
297
301
{ } as TestResultsWithMetadataByBrowserTestFileName ,
Original file line number Diff line number Diff line change
1
+ <?xml version =" 1.0" encoding =" UTF-8" ?>
2
+ <testsuites >
3
+ <testsuite name =" Chrome_puppeteer_/packages/test-runner-junit-reporter/test/fixtures/flat/flat-test.js" id =" 0" tests =" 5" skipped =" 1" errors =" 1" failures =" 1" time =" <<computed>>" >
4
+ <properties >
5
+ <property name =" test.fileName" value =" packages/test-runner-junit-reporter/test/fixtures/flat/flat-test.js" />
6
+ <property name =" browser.name" value =" Chrome" />
7
+ <property name =" browser.launcher" value =" puppeteer" />
8
+ </properties >
9
+ <testcase name =" under addition" time =" <<computed>>" classname =" Chrome_puppeteer_/packages/test-runner-junit-reporter/test/fixtures/flat/flat-test.js" file =" packages/test-runner-junit-reporter/test/fixtures/flat/flat-test.js" />
10
+ <testcase name =" null hypothesis" time =" <<computed>>" classname =" Chrome_puppeteer_/packages/test-runner-junit-reporter/test/fixtures/flat/flat-test.js" file =" packages/test-runner-junit-reporter/test/fixtures/flat/flat-test.js" />
11
+ <testcase name =" asserts error" time =" <<computed>>" classname =" Chrome_puppeteer_/packages/test-runner-junit-reporter/test/fixtures/flat/flat-test.js" file =" packages/test-runner-junit-reporter/test/fixtures/flat/flat-test.js" line =" 12" >
12
+ <failure message =" expected false to be true" type =" AssertionError" ><![CDATA[ AssertionError: expected false to be true
13
+ at <<anonymous>> (packages/test-runner-junit-reporter/test/fixtures/flat/flat-test.js:12:27)]]> </failure >
14
+ </testcase >
15
+ <testcase name =" tbd: confirm true positive" time =" <<computed>>" classname =" Chrome_puppeteer_/packages/test-runner-junit-reporter/test/fixtures/flat/flat-test.js" file =" packages/test-runner-junit-reporter/test/fixtures/flat/flat-test.js" >
16
+ <skipped />
17
+ </testcase >
18
+ <testcase name =" reports logs to JUnit" time =" <<computed>>" classname =" Chrome_puppeteer_/packages/test-runner-junit-reporter/test/fixtures/flat/flat-test.js" file =" packages/test-runner-junit-reporter/test/fixtures/flat/flat-test.js" />
19
+ </testsuite >
20
+ </testsuites >
Original file line number Diff line number Diff line change
1
+ import '../../../../../node_modules/chai/chai.js' ;
2
+
3
+ it ( 'under addition' , function ( ) {
4
+ chai . expect ( 1 + 1 ) . to . equal ( 2 ) ;
5
+ } ) ;
6
+
7
+ it ( 'null hypothesis' , function ( ) {
8
+ chai . expect ( true ) . to . be . true ;
9
+ } ) ;
10
+
11
+ it ( 'asserts error' , function ( ) {
12
+ chai . expect ( false ) . to . be . true ;
13
+ } ) ;
14
+
15
+ it . skip ( 'tbd: confirm true positive' , function ( ) {
16
+ chai . expect ( false ) . to . be . false ;
17
+ } ) ;
18
+
19
+ it ( 'reports logs to JUnit' , function ( ) {
20
+ const actual = '🤷♂️' ;
21
+ console . log ( 'actual is ' , actual ) ;
22
+ chai . expect ( typeof actual ) . to . equal ( 'string' ) ;
23
+ } ) ;
Original file line number Diff line number Diff line change 1
1
<?xml version =" 1.0" encoding =" UTF-8" ?>
2
2
<testsuites >
3
+ <testsuite name =" Chrome_puppeteer_/packages/test-runner-junit-reporter/test/fixtures/multiple/flat-test.js" id =" 0" tests =" 5" skipped =" 1" errors =" 1" failures =" 1" time =" <<computed>>" >
4
+ <properties >
5
+ <property name =" test.fileName" value =" packages/test-runner-junit-reporter/test/fixtures/multiple/flat-test.js" />
6
+ <property name =" browser.name" value =" Chrome" />
7
+ <property name =" browser.launcher" value =" puppeteer" />
8
+ </properties >
9
+ <testcase name =" under addition" time =" <<computed>>" classname =" Chrome_puppeteer_/packages/test-runner-junit-reporter/test/fixtures/multiple/flat-test.js" file =" packages/test-runner-junit-reporter/test/fixtures/multiple/flat-test.js" />
10
+ <testcase name =" null hypothesis" time =" <<computed>>" classname =" Chrome_puppeteer_/packages/test-runner-junit-reporter/test/fixtures/multiple/flat-test.js" file =" packages/test-runner-junit-reporter/test/fixtures/multiple/flat-test.js" />
11
+ <testcase name =" asserts error" time =" <<computed>>" classname =" Chrome_puppeteer_/packages/test-runner-junit-reporter/test/fixtures/multiple/flat-test.js" file =" packages/test-runner-junit-reporter/test/fixtures/multiple/flat-test.js" line =" 12" >
12
+ <failure message =" expected false to be true" type =" AssertionError" ><![CDATA[ AssertionError: expected false to be true
13
+ at <<anonymous>> (packages/test-runner-junit-reporter/test/fixtures/multiple/flat-test.js:12:27)]]> </failure >
14
+ </testcase >
15
+ <testcase name =" tbd: confirm true positive" time =" <<computed>>" classname =" Chrome_puppeteer_/packages/test-runner-junit-reporter/test/fixtures/multiple/flat-test.js" file =" packages/test-runner-junit-reporter/test/fixtures/multiple/flat-test.js" >
16
+ <skipped />
17
+ </testcase >
18
+ <testcase name =" reports logs to JUnit" time =" <<computed>>" classname =" Chrome_puppeteer_/packages/test-runner-junit-reporter/test/fixtures/multiple/flat-test.js" file =" packages/test-runner-junit-reporter/test/fixtures/multiple/flat-test.js" />
19
+ </testsuite >
3
20
<testsuite name =" Chrome_puppeteer_/packages/test-runner-junit-reporter/test/fixtures/multiple/nested-test.js" id =" 0" tests =" 1" skipped =" 0" errors =" 0" failures =" 0" time =" <<computed>>" >
4
21
<properties >
5
22
<property name =" test.fileName" value =" packages/test-runner-junit-reporter/test/fixtures/multiple/nested-test.js" />
Original file line number Diff line number Diff line change
1
+ import '../../../../../node_modules/chai/chai.js' ;
2
+
3
+ it ( 'under addition' , function ( ) {
4
+ chai . expect ( 1 + 1 ) . to . equal ( 2 ) ;
5
+ } ) ;
6
+
7
+ it ( 'null hypothesis' , function ( ) {
8
+ chai . expect ( true ) . to . be . true ;
9
+ } ) ;
10
+
11
+ it ( 'asserts error' , function ( ) {
12
+ chai . expect ( false ) . to . be . true ;
13
+ } ) ;
14
+
15
+ it . skip ( 'tbd: confirm true positive' , function ( ) {
16
+ chai . expect ( false ) . to . be . false ;
17
+ } ) ;
18
+
19
+ it ( 'reports logs to JUnit' , function ( ) {
20
+ const actual = '🤷♂️' ;
21
+ console . log ( 'actual is ' , actual ) ;
22
+ chai . expect ( typeof actual ) . to . equal ( 'string' ) ;
23
+ } ) ;
Original file line number Diff line number Diff line change @@ -95,4 +95,12 @@ describe('junitReporter', function () {
95
95
expect ( actual ) . to . equal ( expected ) ;
96
96
} ) ;
97
97
} ) ;
98
+
99
+ describe ( 'for flat test files' , function ( ) {
100
+ const fixtureDir = path . join ( __dirname , 'fixtures/flat' ) ;
101
+ it ( 'produces expected results' , async function ( ) {
102
+ const { actual, expected } = await run ( fixtureDir ) ;
103
+ expect ( actual ) . to . equal ( expected ) ;
104
+ } ) ;
105
+ } ) ;
98
106
} ) ;
You can’t perform that action at this time.
0 commit comments