@@ -12,20 +12,26 @@ const durationRegex = /duration_ms\s([\d.]+)/
1212export default async function parseReport ( source ) {
1313 const tests = [ ]
1414 const testStack = [ ]
15-
16- let diagnosticMessage = ''
15+ const allTests = Object . create ( null )
16+ let currentTest
1717 let totalDuration = 0
1818
19- function lastTestInStack ( ) {
20- return testStack . length ? testStack [ testStack . length - 1 ] : null
19+ function testId ( data ) {
20+ return [ data . file , data . line , data . column ] . join ( '\0' )
2121 }
2222
23- function appendDiagnosticMessage ( message ) {
24- diagnosticMessage += ` ${ message } \n`
23+ function lastTestInStack ( ) {
24+ return testStack . length ? testStack [ testStack . length - 1 ] : null
2525 }
2626
27- function resetDiagnosticMessage ( ) {
28- diagnosticMessage = ''
27+ function appendDiagnosticMessage ( data ) {
28+ // currentTest is for diagnostics after all tests are complete
29+ // which do not have a file, line, or column.
30+ const t = allTests [ testId ( data ) ] || currentTest
31+ if ( ! t . diagnostic ) {
32+ t . diagnostic = ''
33+ }
34+ t . diagnostic += `${ data . message } \n`
2935 }
3036
3137 function isFileUrl ( urlString ) {
@@ -52,13 +58,13 @@ export default async function parseReport(source) {
5258 data : { name, file }
5359 } = event
5460
55- resetDiagnosticMessage ( )
56-
57- testStack . push ( {
61+ const t = {
5862 name,
5963 file : parseFilePath ( file ) ,
6064 tests : [ ]
61- } )
65+ }
66+ allTests [ testId ( event . data ) ] = t
67+ testStack . push ( t )
6268
6369 break
6470
@@ -72,7 +78,7 @@ export default async function parseReport(source) {
7278 }
7379 } = event
7480
75- const currentTest = testStack . pop ( )
81+ currentTest = testStack . pop ( )
7682 currentTest . duration = duration
7783 currentTest . skip = skip !== undefined
7884 currentTest . todo = todo !== undefined
@@ -89,10 +95,6 @@ export default async function parseReport(source) {
8995 }
9096 }
9197
92- if ( diagnosticMessage ) {
93- currentTest . diagnostic = diagnosticMessage
94- }
95-
9698 if ( lastTestInStack ( ) ) {
9799 lastTestInStack ( ) . tests . push ( currentTest )
98100 } else {
@@ -111,7 +113,7 @@ export default async function parseReport(source) {
111113 totalDuration = parseFloat ( durationMatch [ 1 ] )
112114 }
113115
114- appendDiagnosticMessage ( message )
116+ appendDiagnosticMessage ( event . data )
115117
116118 break
117119 }
0 commit comments