@@ -23,6 +23,7 @@ const originalConsole = {
2323} ;
2424
2525let isXUnitDoneCheck = false ;
26+ let isXmlDoneCheck = false ;
2627
2728function proxyMethod ( prefix , func , asJson ) {
2829 return function ( ) {
@@ -42,7 +43,12 @@ function proxyMethod(prefix, func, asJson) {
4243 isXUnitDoneCheck = true ;
4344 }
4445
45- if ( asJson ) {
46+ if ( payload . startsWith ( "STARTRESULTXML" ) ) {
47+ originalConsole . log ( 'Sending RESULTXML' )
48+ isXmlDoneCheck = true ;
49+ func ( payload ) ;
50+ }
51+ else if ( asJson ) {
4652 func ( JSON . stringify ( {
4753 method : prefix ,
4854 payload : payload ,
@@ -66,10 +72,12 @@ function proxyJson(func) {
6672 console [ m ] = proxyMethod ( `console.${ m } ` , func , true ) ;
6773}
6874
75+ let consoleWebSocket ;
76+
6977if ( is_browser ) {
7078 const consoleUrl = `${ window . location . origin } /console` . replace ( 'http://' , 'ws://' ) ;
7179
72- let consoleWebSocket = new WebSocket ( consoleUrl ) ;
80+ consoleWebSocket = new WebSocket ( consoleUrl ) ;
7381 // redirect output so that when emscripten starts it's already redirected
7482 proxyJson ( function ( msg ) {
7583 if ( consoleWebSocket . readyState === WebSocket . OPEN ) {
@@ -238,7 +246,7 @@ function set_exit_code(exit_code, reason) {
238246 }
239247 if ( is_browser ) {
240248 const stack = ( new Error ( ) ) . stack . replace ( / \n / g, "" ) . replace ( / [ ] * a t / g, " at" ) . replace ( / h t t p s ? : \/ \/ [ 0 - 9 . : ] * / g, "" ) . replace ( "Error" , "" ) ;
241- const messsage = `Exit called with ${ exit_code } when isXUnitDoneCheck=${ isXUnitDoneCheck } ${ stack } .` ;
249+ const messsage = `Exit called with ${ exit_code } when isXUnitDoneCheck=${ isXUnitDoneCheck } isXmlDoneCheck= ${ isXmlDoneCheck } WS.bufferedAmount= ${ consoleWebSocket . bufferedAmount } ${ stack } .` ;
242250
243251 // Notify the selenium script
244252 Module . exit_code = exit_code ;
@@ -249,20 +257,20 @@ function set_exit_code(exit_code, reason) {
249257 tests_done_elem . innerHTML = exit_code . toString ( ) ;
250258 document . body . appendChild ( tests_done_elem ) ;
251259
252- // need to flush streams (stdout/stderr)
253- for ( const stream of Module . FS . streams ) {
254- if ( stream && stream . stream_ops && stream . stream_ops . flush ) {
255- stream . stream_ops . flush ( stream ) ;
260+ console . log ( 'WS: ' + messsage ) ;
261+ originalConsole . log ( 'CDP: ' + messsage ) ;
262+ const stop_when_ws_buffer_empty = ( ) => {
263+ if ( consoleWebSocket . bufferedAmount == 0 ) {
264+ // tell xharness WasmTestMessagesProcessor we are done.
265+ // note this sends last few bytes into the same WS
266+ console . log ( "WASM EXIT " + exit_code ) ;
256267 }
257- }
258- console . log ( "Flushed stdout!" ) ;
259-
260- console . log ( '1 ' + messsage ) ;
261- setTimeout ( ( ) => {
262- originalConsole . log ( '2 ' + messsage ) ;
263- // tell xharness WasmTestMessagesProcessor we are done.
264- console . log ( "WASM EXIT " + exit_code ) ;
265- } , 100 ) ;
268+ else {
269+ setTimeout ( stop_when_ws_buffer_empty , 100 ) ;
270+ }
271+ } ;
272+ stop_when_ws_buffer_empty ( ) ;
273+
266274 } else if ( INTERNAL ) {
267275 INTERNAL . mono_wasm_exit ( exit_code ) ;
268276 }
0 commit comments