@@ -15,29 +15,15 @@ const {
1515const { inspectWithNoCustomRetry } = require ( 'internal/errors' ) ;
1616const { hostname } = require ( 'os' ) ;
1717
18- const inspectOptions = {
19- __proto__ : null ,
20- colors : false ,
21- breakLength : Infinity ,
22- } ;
18+ const inspectOptions = { __proto__ : null , colors : false , breakLength : Infinity } ;
2319const HOSTNAME = hostname ( ) ;
2420
2521function escapeAttribute ( s = '' ) {
26- return escapeContent (
27- RegExpPrototypeSymbolReplace (
28- / " / g,
29- RegExpPrototypeSymbolReplace ( / \n / g, s , ' ' ) ,
30- '"' ,
31- ) ,
32- ) ;
22+ return escapeContent ( RegExpPrototypeSymbolReplace ( / " / g, RegExpPrototypeSymbolReplace ( / \n / g, s , ' ' ) , '"' ) ) ;
3323}
3424
3525function escapeContent ( s = '' ) {
36- return RegExpPrototypeSymbolReplace (
37- / < / g,
38- RegExpPrototypeSymbolReplace ( / ( & ) (? ! # \d { 1 , 7 } ; ) / g, s , '&' ) ,
39- '<' ,
40- ) ;
26+ return RegExpPrototypeSymbolReplace ( / < / g, RegExpPrototypeSymbolReplace ( / ( & ) (? ! # \d { 1 , 7 } ; ) / g, s , '&' ) , '<' ) ;
4127}
4228
4329function escapeComment ( s = '' ) {
@@ -48,42 +34,31 @@ function treeToXML(tree) {
4834 if ( typeof tree === 'string' ) {
4935 return `${ escapeContent ( tree ) } \n` ;
5036 }
51- const { tag, attrs, nesting, children, comment } = tree ;
37+ const {
38+ tag, attrs, nesting, children, comment,
39+ } = tree ;
5240 const indent = StringPrototypeRepeat ( '\t' , nesting + 1 ) ;
5341 if ( comment ) {
5442 return `${ indent } <!-- ${ escapeComment ( comment ) } -->\n` ;
5543 }
5644 const attrsString = ArrayPrototypeJoin (
5745 ArrayPrototypeMap (
5846 ObjectEntries ( attrs ) ,
59- ( { 0 : key , 1 : value } ) => `${ key } ="${ escapeAttribute ( String ( value ) ) } "` ,
60- ) ,
61- ' ' ,
62- ) ;
47+ ( { 0 : key , 1 : value } ) => `${ key } ="${ escapeAttribute ( String ( value ) ) } "` ) ,
48+ ' ' ) ;
6349 if ( ! children ?. length ) {
6450 return `${ indent } <${ tag } ${ attrsString } />\n` ;
6551 }
66- const childrenString = ArrayPrototypeJoin (
67- ArrayPrototypeMap ( children ?? [ ] , treeToXML ) ,
68- '' ,
69- ) ;
52+ const childrenString = ArrayPrototypeJoin ( ArrayPrototypeMap ( children ?? [ ] , treeToXML ) , '' ) ;
7053 return `${ indent } <${ tag } ${ attrsString } >\n${ childrenString } ${ indent } </${ tag } >\n` ;
7154}
7255
7356function isFailure ( node ) {
74- return (
75- ( node ?. children &&
76- ArrayPrototypeSome ( node . children , ( c ) => c . tag === 'failure' ) ) ||
77- node ?. attrs ?. failures
78- ) ;
57+ return ( node ?. children && ArrayPrototypeSome ( node . children , ( c ) => c . tag === 'failure' ) ) || node ?. attrs ?. failures ;
7958}
8059
8160function isSkipped ( node ) {
82- return (
83- ( node ?. children &&
84- ArrayPrototypeSome ( node . children , ( c ) => c . tag === 'skipped' ) ) ||
85- node ?. attrs ?. skipped
86- ) ;
61+ return ( node ?. children && ArrayPrototypeSome ( node . children , ( c ) => c . tag === 'skipped' ) ) || node ?. attrs ?. skipped ;
8762}
8863
8964module . exports = async function * junitReporter ( source ) {
@@ -118,42 +93,25 @@ module.exports = async function* junitReporter(source) {
11893 case 'test:pass' :
11994 case 'test:fail' : {
12095 if ( ! currentSuite ) {
121- startTest ( {
122- __proto__ : null ,
123- data : { __proto__ : null , name : 'root' , nesting : 0 } ,
124- } ) ;
96+ startTest ( { __proto__ : null , data : { __proto__ : null , name : 'root' , nesting : 0 } } ) ;
12597 }
126- if (
127- currentSuite . attrs . name !== event . data . name ||
128- currentSuite . nesting !== event . data . nesting
129- ) {
98+ if ( currentSuite . attrs . name !== event . data . name ||
99+ currentSuite . nesting !== event . data . nesting ) {
130100 startTest ( event ) ;
131101 }
132102 const currentTest = currentSuite ;
133103 if ( currentSuite ?. nesting === event . data . nesting ) {
134104 currentSuite = currentSuite . parent ;
135105 }
136- currentTest . attrs . time = NumberPrototypeToFixed (
137- event . data . details . duration_ms / 1000 ,
138- 6 ,
139- ) ;
140- const nonCommentChildren = ArrayPrototypeFilter (
141- currentTest . children ,
142- ( c ) => c . comment == null ,
143- ) ;
106+ currentTest . attrs . time = NumberPrototypeToFixed ( event . data . details . duration_ms / 1000 , 6 ) ;
107+ const nonCommentChildren = ArrayPrototypeFilter ( currentTest . children , ( c ) => c . comment == null ) ;
144108 if ( nonCommentChildren . length > 0 ) {
145109 currentTest . tag = 'testsuite' ;
146110 currentTest . attrs . disabled = 0 ;
147111 currentTest . attrs . errors = 0 ;
148112 currentTest . attrs . tests = nonCommentChildren . length ;
149- currentTest . attrs . failures = ArrayPrototypeFilter (
150- currentTest . children ,
151- isFailure ,
152- ) . length ;
153- currentTest . attrs . skipped = ArrayPrototypeFilter (
154- currentTest . children ,
155- isSkipped ,
156- ) . length ;
113+ currentTest . attrs . failures = ArrayPrototypeFilter ( currentTest . children , isFailure ) . length ;
114+ currentTest . attrs . skipped = ArrayPrototypeFilter ( currentTest . children , isSkipped ) . length ;
157115 currentTest . attrs . hostname = HOSTNAME ;
158116 } else {
159117 currentTest . tag = 'testcase' ;
@@ -163,29 +121,17 @@ module.exports = async function* junitReporter(source) {
163121 }
164122 if ( event . data . skip ) {
165123 ArrayPrototypePush ( currentTest . children , {
166- __proto__ : null ,
167- nesting : event . data . nesting + 1 ,
168- tag : 'skipped' ,
169- attrs : {
170- __proto__ : null ,
171- type : 'skipped' ,
172- message : event . data . skip ,
173- } ,
124+ __proto__ : null , nesting : event . data . nesting + 1 , tag : 'skipped' ,
125+ attrs : { __proto__ : null , type : 'skipped' , message : event . data . skip } ,
174126 } ) ;
175127 }
176128 if ( event . data . todo ) {
177129 ArrayPrototypePush ( currentTest . children , {
178- __proto__ : null ,
179- nesting : event . data . nesting + 1 ,
180- tag : 'skipped' ,
181- attrs : {
182- __proto__ : null ,
183- type : 'todo' ,
184- message : event . data . todo ,
185- } ,
130+ __proto__ : null , nesting : event . data . nesting + 1 , tag : 'skipped' ,
131+ attrs : { __proto__ : null , type : 'todo' , message : event . data . todo } ,
186132 } ) ;
187133 }
188- if ( event . data . flakyRetriedCount > 0 ) {
134+ if ( event . data . retryCount > 0 ) {
189135 ArrayPrototypePush ( currentTest . children , {
190136 __proto__ : null ,
191137 nesting : event . data . nesting + 1 ,
@@ -199,7 +145,7 @@ module.exports = async function* junitReporter(source) {
199145 attrs : {
200146 __proto__ : null ,
201147 name : 'flaky' ,
202- value : `${ event . data . flakyRetriedCount } retries` ,
148+ value : `${ event . data . retryCount } retries` ,
203149 } ,
204150 } ,
205151 ] ,
@@ -211,11 +157,7 @@ module.exports = async function* junitReporter(source) {
211157 __proto__ : null ,
212158 nesting : event . data . nesting + 1 ,
213159 tag : 'failure' ,
214- attrs : {
215- __proto__ : null ,
216- type : error ?. failureType || error ?. code ,
217- message : error ?. message . trim ( ) ?? '' ,
218- } ,
160+ attrs : { __proto__ : null , type : error ?. failureType || error ?. code , message : error ?. message . trim ( ) ?? '' } ,
219161 children : [ inspectWithNoCustomRetry ( error , inspectOptions ) ] ,
220162 } ) ;
221163 currentTest . failures = 1 ;
@@ -227,13 +169,10 @@ module.exports = async function* junitReporter(source) {
227169 case 'test:diagnostic' : {
228170 const parent = currentSuite ?. children ?? roots ;
229171 ArrayPrototypePush ( parent , {
230- __proto__ : null ,
231- nesting : event . data . nesting ,
232- comment : event . data . message ,
172+ __proto__ : null , nesting : event . data . nesting , comment : event . data . message ,
233173 } ) ;
234174 break ;
235- }
236- default :
175+ } default :
237176 break ;
238177 }
239178 }
0 commit comments