@@ -20,7 +20,6 @@ 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' ) ;
24
23
25
24
const YELLOW_COLOR = '\x1b[33m' ;
26
25
const RESET_COLOR = '\x1b[0m' ;
@@ -104,8 +103,6 @@ module.exports.describe = ({testRunner, product, playwrightPath}) => {
104
103
beforeAll ( async state => {
105
104
state . browser = await browserType . launch ( defaultBrowserOptions ) ;
106
105
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 } ) ;
109
106
} ) ;
110
107
111
108
afterAll ( async state => {
@@ -115,18 +112,22 @@ module.exports.describe = ({testRunner, product, playwrightPath}) => {
115
112
} ) ;
116
113
117
114
beforeEach ( async ( state , test ) => {
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 ) ;
115
+ const onLine = ( line ) => test . output += line + '\n' ;
123
116
if ( dumpProtocolOnFailure )
124
- state . browser . _setDebugFunction ( data => test . output . push ( `\x1b[32m[pw:protocol]\x1b[0m ${ data } ` ) ) ;
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
+
125
126
state . tearDown = async ( ) => {
126
- state . _stdout . off ( 'line' , dumpout ) ;
127
- state . _stderr . off ( 'line' , dumperr ) ;
128
- state . _stdout . close ( ) ;
129
- state . _stderr . close ( ) ;
127
+ if ( rl ) {
128
+ rl . removeListener ( 'line' , onLine ) ;
129
+ rl . close ( ) ;
130
+ }
130
131
if ( dumpProtocolOnFailure )
131
132
state . browser . _setDebugFunction ( ( ) => void 0 ) ;
132
133
} ;
0 commit comments