File tree 3 files changed +50
-12
lines changed
projects/npm-tools/packages/jest-junit-reporter
3 files changed +50
-12
lines changed Original file line number Diff line number Diff line change @@ -37,18 +37,25 @@ module.exports = (report) => {
37
37
} ;
38
38
39
39
const testResults = report . testResults
40
- . reduce (
41
- ( results , suite ) =>
42
- suite . testResults . length
43
- ? results . concat (
44
- suite . testResults . map ( ( test ) => ( {
45
- ...test ,
46
- testFilePath : suite . testFilePath ,
47
- } ) )
48
- )
49
- : results ,
50
- [ ]
51
- )
40
+ . reduce ( ( acc , suite ) => {
41
+ if ( suite . testResults . length ) {
42
+ acc . push (
43
+ ...suite . testResults . map ( ( test ) => ( {
44
+ ...test ,
45
+ testFilePath : suite . testFilePath ,
46
+ } ) )
47
+ ) ;
48
+ } else if ( suite . failureMessage ) {
49
+ acc . push ( {
50
+ duration : 0 ,
51
+ failureMessages : [ suite . failureMessage ] ,
52
+ fullName : suite . testFilePath ,
53
+ testFilePath : suite . testFilePath ,
54
+ } ) ;
55
+ }
56
+
57
+ return acc ;
58
+ } , [ ] )
52
59
. map ( ( testCase ) => {
53
60
const results = [
54
61
{
Original file line number Diff line number Diff line change @@ -20,6 +20,15 @@ Received: true
20
20
</testsuite>"
21
21
`;
22
22
23
+ exports[`@liferay/jest-junit-reporter writes a file for a failing test suite 1`] = `
24
+ " <?xml version=\\" 1.0\\" encoding =\\"UTF-8\\"?>
25
+ <testsuite errors =\\"0\\" failures =\\"0\\" hostname =\\"\\" id =\\"0\\" name =\\"Jest\\" package =\\"reporter-tests\\" skipped =\\"0\\" tests =\\"1\\" time =\\"0\\" timestamp =\\"1000\\">
26
+ <testcase classname =\\"test-module.bar\\" name =\\"/foo/bar/liferay-portal/modules/apps/test-module/bar/Baz.js\\" time =\\"0\\">
27
+ <failure message =\\"Test Suite Failed to run\\">Test Suite Failed to run</failure>
28
+ </testcase>
29
+ </testsuite>"
30
+ `;
31
+
23
32
exports[`@liferay/jest-junit-reporter writes a file for a passing test 1`] = `
24
33
" <?xml version=\\" 1.0\\" encoding =\\"UTF-8\\"?>
25
34
<testsuite errors =\\"0\\" failures =\\"0\\" hostname =\\"\\" id =\\"0\\" name =\\"Jest\\" package =\\"reporter-tests\\" skipped =\\"0\\" tests =\\"1\\" time =\\"0\\" timestamp =\\"1000\\">
Original file line number Diff line number Diff line change @@ -34,6 +34,20 @@ const failedTestReport = {
34
34
] ,
35
35
} ;
36
36
37
+ const failedTestSuite = {
38
+ numFailedTests : 0 ,
39
+ numTotalTests : 1 ,
40
+ startTime : 1000 ,
41
+ testResults : [
42
+ {
43
+ failureMessage : 'Test Suite Failed to run' ,
44
+ testFilePath :
45
+ '/foo/bar/liferay-portal/modules/apps/test-module/bar/Baz.js' ,
46
+ testResults : [ ] ,
47
+ } ,
48
+ ] ,
49
+ } ;
50
+
37
51
const passedTestReport = {
38
52
numFailedTests : 0 ,
39
53
numTotalTests : 1 ,
@@ -82,4 +96,12 @@ describe('@liferay/jest-junit-reporter', () => {
82
96
83
97
expect ( xmlWritten ) . toMatchSnapshot ( ) ;
84
98
} ) ;
99
+
100
+ it ( 'writes a file for a failing test suite' , ( ) => {
101
+ reporter ( failedTestSuite ) ;
102
+
103
+ const xmlWritten = fs . writeFileSync . mock . calls [ 0 ] [ 1 ] ;
104
+
105
+ expect ( xmlWritten ) . toMatchSnapshot ( ) ;
106
+ } ) ;
85
107
} ) ;
You can’t perform that action at this time.
0 commit comments