@@ -23,6 +23,7 @@ const originalConsole = {
23
23
} ;
24
24
25
25
let isXUnitDoneCheck = false ;
26
+ let isXmlDoneCheck = false ;
26
27
27
28
function proxyMethod ( prefix , func , asJson ) {
28
29
return function ( ) {
@@ -42,7 +43,12 @@ function proxyMethod(prefix, func, asJson) {
42
43
isXUnitDoneCheck = true ;
43
44
}
44
45
45
- if ( asJson ) {
46
+ if ( payload . startsWith ( "STARTRESULTXML" ) ) {
47
+ originalConsole . log ( 'Sending RESULTXML' )
48
+ isXmlDoneCheck = true ;
49
+ func ( payload ) ;
50
+ }
51
+ else if ( asJson ) {
46
52
func ( JSON . stringify ( {
47
53
method : prefix ,
48
54
payload : payload ,
@@ -66,10 +72,12 @@ function proxyJson(func) {
66
72
console [ m ] = proxyMethod ( `console.${ m } ` , func , true ) ;
67
73
}
68
74
75
+ let consoleWebSocket ;
76
+
69
77
if ( is_browser ) {
70
78
const consoleUrl = `${ window . location . origin } /console` . replace ( 'http://' , 'ws://' ) ;
71
79
72
- let consoleWebSocket = new WebSocket ( consoleUrl ) ;
80
+ consoleWebSocket = new WebSocket ( consoleUrl ) ;
73
81
// redirect output so that when emscripten starts it's already redirected
74
82
proxyJson ( function ( msg ) {
75
83
if ( consoleWebSocket . readyState === WebSocket . OPEN ) {
@@ -238,7 +246,7 @@ function set_exit_code(exit_code, reason) {
238
246
}
239
247
if ( is_browser ) {
240
248
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 } .` ;
242
250
243
251
// Notify the selenium script
244
252
Module . exit_code = exit_code ;
@@ -249,20 +257,20 @@ function set_exit_code(exit_code, reason) {
249
257
tests_done_elem . innerHTML = exit_code . toString ( ) ;
250
258
document . body . appendChild ( tests_done_elem ) ;
251
259
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 ) ;
256
267
}
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
+
266
274
} else if ( INTERNAL ) {
267
275
INTERNAL . mono_wasm_exit ( exit_code ) ;
268
276
}
0 commit comments