@@ -20,6 +20,7 @@ const os = require('os');
20
20
const rm = require ( 'rimraf' ) . sync ;
21
21
const GoldenUtils = require ( './golden-utils' ) ;
22
22
const { Matchers} = require ( '../utils/testrunner/' ) ;
23
+ const readline = require ( 'readline' ) ;
23
24
24
25
const YELLOW_COLOR = '\x1b[33m' ;
25
26
const RESET_COLOR = '\x1b[0m' ;
@@ -103,6 +104,8 @@ module.exports.describe = ({testRunner, product, playwrightPath}) => {
103
104
beforeAll ( async state => {
104
105
state . browser = await browserType . launch ( defaultBrowserOptions ) ;
105
106
state . browserServer = state . browser . __server__ ;
107
+ state . _stdout = readline . createInterface ( { input : state . browserServer . process ( ) . stdout } ) ;
108
+ state . _stderr = readline . createInterface ( { input : state . browserServer . process ( ) . stderr } ) ;
106
109
} ) ;
107
110
108
111
afterAll ( async state => {
@@ -112,22 +115,16 @@ module.exports.describe = ({testRunner, product, playwrightPath}) => {
112
115
} ) ;
113
116
114
117
beforeEach ( async ( state , test ) => {
115
- const onLine = ( line ) => test . output += line + '\n' ;
118
+ test . output = [ ] ;
119
+ const dumpout = data => test . output . push ( `\x1b[33m[pw:stdio:out]\x1b[0m ${ data } ` ) ;
120
+ const dumperr = data => test . output . push ( `\x1b[31m[pw:stdio:err]\x1b[0m ${ data } ` ) ;
121
+ state . _stdout . on ( 'line' , dumpout ) ;
122
+ state . _stderr . on ( 'line' , dumperr ) ;
116
123
if ( dumpProtocolOnFailure )
117
- state . browser . _setDebugFunction ( onLine ) ;
118
-
119
- let rl ;
120
- if ( state . browserServer . process ( ) . stderr ) {
121
- rl = require ( 'readline' ) . createInterface ( { input : state . browserServer . process ( ) . stderr } ) ;
122
- test . output = '' ;
123
- rl . on ( 'line' , onLine ) ;
124
- }
125
-
124
+ state . browser . _setDebugFunction ( data => test . output . push ( `\x1b[32m[pw:protocol]\x1b[0m ${ data } ` ) ) ;
126
125
state . tearDown = async ( ) => {
127
- if ( rl ) {
128
- rl . removeListener ( 'line' , onLine ) ;
129
- rl . close ( ) ;
130
- }
126
+ state . _stdout . off ( 'line' , dumpout ) ;
127
+ state . _stderr . off ( 'line' , dumperr ) ;
131
128
if ( dumpProtocolOnFailure )
132
129
state . browser . _setDebugFunction ( ( ) => void 0 ) ;
133
130
} ;
0 commit comments