@@ -29,58 +29,66 @@ const ansiRegex = new RegExp(`${ESC}\\[[0-?]*[ -/]*[@-~]`, 'g');
2929
3030const stripAnsi = str => str . replace ( ansiRegex , '' ) ;
3131
32- for ( const suite of report . suites ) {
33- for ( const spec of suite . specs ) {
34- for ( const test of spec . tests ) {
35- const title = `${ spec . title } (tags: ${ spec . tags . join ( ', ' ) } )` ;
36- const specLocation = `${ spec . file } :${ spec . line } ` ;
37- const retries = test . results . length - 1 ;
38- const hasPassed = test . results . some ( r => r . status === 'passed' ) ;
39- const hasRetries = retries > 0 ;
40-
41- // Only include in failures if no retries succeeded
42- if ( ! hasPassed ) {
43- const lastResult = test . results [ test . results . length - 1 ] ;
44-
45- if ( lastResult . status !== 'passed' && lastResult . status !== 'skipped' ) {
46- // Show only the last (final) failure
47- let failureInfo = `<details> \n <summary> ❌ ${ title } </summary><br> \n\n Location: **${ specLocation } **\n Duration: **${ lastResult . duration } ms**\n` ;
48-
49- if ( lastResult . errors ?. length ) {
50- failureInfo += `\n**Errors:**\n` ;
51- lastResult . errors . forEach ( e => {
52- failureInfo += `\n\`\`\`\n${ stripAnsi ( e . message ) } \n\`\`\`` ;
53- } ) ;
54- }
55-
56- failureInfo += `\n</details>` ;
57- failures . push ( failureInfo ) ;
32+ // Recursively get all specs no matter in how many suites they are nested
33+ const getSpecs = suite => {
34+ if ( suite . suites ?. length ) {
35+ return [ ...suite . suites . flatMap ( suite => getSpecs ( suite ) ) , ...( suite . specs ?? [ ] ) ] ;
36+ } else {
37+ return suite . specs ?? [ ] ;
38+ }
39+ } ;
40+
41+ const specs = getSpecs ( report ) ;
42+ for ( const spec of specs ) {
43+ for ( const test of spec . tests ) {
44+ const title = `${ spec . title } (tags: ${ spec . tags . join ( ', ' ) } )` ;
45+ const specLocation = `${ spec . file } :${ spec . line } ` ;
46+ const retries = test . results . length - 1 ;
47+ const hasPassed = test . results . some ( r => r . status === 'passed' ) ;
48+ const hasRetries = retries > 0 ;
49+
50+ // Only include in failures if no retries succeeded
51+ if ( ! hasPassed ) {
52+ const lastResult = test . results [ test . results . length - 1 ] ;
53+
54+ if ( lastResult . status !== 'passed' && lastResult . status !== 'skipped' ) {
55+ // Show only the last (final) failure
56+ let failureInfo = `<details> \n <summary> ❌ ${ title } </summary><br> \n\n Location: **${ specLocation } **\n Duration: **${ lastResult . duration } ms**\n` ;
57+
58+ if ( lastResult . errors ?. length ) {
59+ failureInfo += `\n**Errors:**\n` ;
60+ lastResult . errors . forEach ( e => {
61+ failureInfo += `\n\`\`\`\n${ stripAnsi ( e . message ) } \n\`\`\`` ;
62+ } ) ;
5863 }
59- }
6064
61- // Test is flaky if it passed after retries
62- if ( hasRetries && hasPassed ) {
63- const retryDetails = test . results
64- . map ( ( result , index ) => {
65- const errors = ( result . errors || [ ] )
66- . map ( ( err , i ) => {
67- const clean = stripAnsi ( err . message || '' ) ;
68- return `\n\`\`\`\n${ clean } \n\`\`\`` ;
69- } )
70- . join ( '\n\n' ) ;
71-
72- if ( ! errors ) {
73- return `**Attempt ${ index + 1 } ** \n Result: ✅ **Passed** \n Duration: **${ result . duration } ms**` ;
74- }
75- return `**Attempt ${ index + 1 } ** \n Result: ❌ **Failed** \n Duration: **${ result . duration } ms** \n\n **Errors:** \n ${ errors } ` . trim ( ) ;
76- } )
77- . join ( '\n\n' ) ;
78-
79- flakyTests . push (
80- `<details> \n <summary> ⚠️ ${ title } </summary><br> \n\n Location: **${ specLocation } **\n\n${ retryDetails } \n</details>` ,
81- ) ;
65+ failureInfo += `\n</details>` ;
66+ failures . push ( failureInfo ) ;
8267 }
8368 }
69+
70+ // Test is flaky if it passed after retries
71+ if ( hasRetries && hasPassed ) {
72+ const retryDetails = test . results
73+ . map ( ( result , index ) => {
74+ const errors = ( result . errors || [ ] )
75+ . map ( ( err , i ) => {
76+ const clean = stripAnsi ( err . message || '' ) ;
77+ return `\n\`\`\`\n${ clean } \n\`\`\`` ;
78+ } )
79+ . join ( '\n\n' ) ;
80+
81+ if ( ! errors ) {
82+ return `**Attempt ${ index + 1 } ** \n Result: ✅ **Passed** \n Duration: **${ result . duration } ms**` ;
83+ }
84+ return `**Attempt ${ index + 1 } ** \n Result: ❌ **Failed** \n Duration: **${ result . duration } ms** \n\n **Errors:** \n ${ errors } ` . trim ( ) ;
85+ } )
86+ . join ( '\n\n' ) ;
87+
88+ flakyTests . push (
89+ `<details> \n <summary> ⚠️ ${ title } </summary><br> \n\n Location: **${ specLocation } **\n\n${ retryDetails } \n</details>` ,
90+ ) ;
91+ }
8492 }
8593}
8694
0 commit comments