File tree Expand file tree Collapse file tree 3 files changed +51
-12
lines changed
projects/npm-tools/packages/jest-junit-reporter Expand file tree Collapse file tree 3 files changed +51
-12
lines changed Original file line number Diff line number Diff line change @@ -37,18 +37,26 @@ module.exports = (report) => {
3737 } ;
3838
3939 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+ }
49+ else if ( suite . failureMessage ) {
50+ acc . push ( {
51+ duration : 0 ,
52+ failureMessages : [ suite . failureMessage ] ,
53+ fullName : suite . testFilePath ,
54+ testFilePath : suite . testFilePath ,
55+ } ) ;
56+ }
57+
58+ return acc ;
59+ } , [ ] )
5260 . map ( ( testCase ) => {
5361 const results = [
5462 {
Original file line number Diff line number Diff line change @@ -20,6 +20,15 @@ Received: true
2020</testsuite>"
2121`;
2222
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+
2332exports[`@liferay/jest-junit-reporter writes a file for a passing test 1`] = `
2433" <?xml version=\\" 1.0\\" encoding =\\"UTF-8\\"?>
2534<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 = {
3434 ] ,
3535} ;
3636
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+
3751const passedTestReport = {
3852 numFailedTests : 0 ,
3953 numTotalTests : 1 ,
@@ -82,4 +96,12 @@ describe('@liferay/jest-junit-reporter', () => {
8296
8397 expect ( xmlWritten ) . toMatchSnapshot ( ) ;
8498 } ) ;
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+ } ) ;
85107} ) ;
You can’t perform that action at this time.
0 commit comments