1
1
var childProcess = require ( 'child_process' ) ,
2
2
ZipBinary = require ( './ZipBinary' ) ,
3
- Helper = require ( './helper' ) ;
3
+ Helper = require ( './helper' ) ,
4
+ Tail = require ( 'tail' ) . Tail ;
4
5
5
6
function BrowserStackTunnel ( options ) {
6
7
var helper = new Helper . helper ( ) ;
@@ -19,7 +20,11 @@ function BrowserStackTunnel(options) {
19
20
}
20
21
} ,
21
22
doneStop = function ( params ) {
22
- if ( stopCallback !== null ) {
23
+ if ( this . tail ) {
24
+ this . tail . unwatch ( ) ;
25
+ this . tail = null ;
26
+ }
27
+ if ( stopCallback ) {
23
28
stopCallback ( params ) ;
24
29
}
25
30
} ;
@@ -28,6 +33,7 @@ function BrowserStackTunnel(options) {
28
33
29
34
this . stdoutData = '' ;
30
35
this . tunnel = null ;
36
+ this . tail = null ;
31
37
32
38
if ( options . hosts ) {
33
39
params . push ( options . hosts ) ;
@@ -83,7 +89,6 @@ function BrowserStackTunnel(options) {
83
89
} ;
84
90
85
91
this . updateState = function ( data ) {
86
- helper . logBinaryOutput ( data . toString ( ) ) ;
87
92
var state ;
88
93
this . stdoutData += data . toString ( ) ;
89
94
for ( state in this . stateMatchers ) {
@@ -124,6 +129,10 @@ function BrowserStackTunnel(options) {
124
129
this . tunnel . kill ( ) ;
125
130
this . tunnel = null ;
126
131
}
132
+ if ( this . tail ) {
133
+ this . tail . unwatch ( ) ;
134
+ this . tail = null ;
135
+ }
127
136
} ;
128
137
129
138
this . exit = function ( ) {
@@ -142,10 +151,18 @@ function BrowserStackTunnel(options) {
142
151
this . _startTunnel = function ( ) {
143
152
var binaryPath = helper . getBinaryPath ( ) ;
144
153
this . cleanUp ( ) ;
154
+
155
+ var logFilePath = helper . getLogFilePath ( ) ;
156
+ params . push ( '-logFile' , logFilePath ) ;
157
+
145
158
log . info ( 'Local Binary is located at ' + binaryPath ) ;
146
159
log . info ( 'Local started with args: ' + JSON . stringify ( params ) ) ;
160
+
161
+ this . tail = new Tail ( logFilePath ) ;
162
+ this . tail . on ( 'line' , this . updateState . bind ( this ) ) ;
163
+ this . tail . on ( 'error' , this . updateState . bind ( this ) ) ;
164
+
147
165
this . tunnel = childProcess . spawn ( binaryPath , binary . args . concat ( [ options . key ] ) . concat ( params ) ) ;
148
- this . tunnel . stdout . on ( 'data' , this . updateState . bind ( this ) ) ;
149
166
this . tunnel . stderr . on ( 'data' , this . updateState . bind ( this ) ) ;
150
167
this . tunnel . on ( 'error' , this . killTunnel . bind ( this ) ) ;
151
168
this . tunnel . on ( 'exit' , this . exit . bind ( this ) ) ;
@@ -181,6 +198,10 @@ function BrowserStackTunnel(options) {
181
198
stopCallback = callback ;
182
199
} else if ( this . state !== 'started' ) {
183
200
var err = new Error ( 'child not started' ) ;
201
+ if ( this . tail ) {
202
+ this . tail . unwatch ( ) ;
203
+ this . tail = null ;
204
+ }
184
205
callback ( err ) ;
185
206
}
186
207
0 commit comments