@@ -8,16 +8,9 @@ var CommandlineTest = function(command) {
8
8
var self = this ;
9
9
this . command_ = command ;
10
10
this . expectedExitCode_ = 0 ;
11
- this . stdioOnlyOnFailures_ = true ;
12
11
this . expectedErrors_ = [ ] ;
13
12
this . assertExitCodeOnly_ = false ;
14
-
15
- // If stdioOnlyOnFailures_ is true, do not stream stdio unless test failed.
16
- // This is to prevent tests with expected failures from polluting the output.
17
- this . alwaysEnableStdio = function ( ) {
18
- self . stdioOnlyOnFailures_ = false ;
19
- return self ;
20
- } ;
13
+ this . testLogStream = undefined ;
21
14
22
15
// Only assert the exit code and not failures.
23
16
// This must be true if the command you're running does not support
@@ -27,6 +20,10 @@ var CommandlineTest = function(command) {
27
20
return self ;
28
21
} ;
29
22
23
+ this . setTestLogFile = function ( filename ) {
24
+ self . testLogStream = fs . createWriteStream ( filename , { flags : 'a' } ) ;
25
+ } ;
26
+
30
27
// Set the expected exit code for the test command.
31
28
this . expectExitCode = function ( exitCode ) {
32
29
self . expectedExitCode_ = exitCode ;
@@ -75,22 +72,18 @@ var CommandlineTest = function(command) {
75
72
76
73
var test_process ;
77
74
78
- if ( self . stdioOnlyOnFailures_ ) {
79
- test_process = child_process . spawn ( args [ 0 ] , args . slice ( 1 ) ) ;
75
+ test_process = child_process . spawn ( args [ 0 ] , args . slice ( 1 ) ) ;
80
76
81
- test_process . stdout . on ( 'data' , function ( data ) {
82
- process . stdout . write ( '.' ) ;
83
- output += data ;
84
- } ) ;
77
+ var processData = function ( data ) {
78
+ process . stdout . write ( '.' ) ;
79
+ output += data ;
80
+ if ( self . testLogStream ) {
81
+ self . testLogStream . write ( data ) ;
82
+ }
83
+ } ;
85
84
86
- test_process . stderr . on ( 'data' , function ( data ) {
87
- process . stdout . write ( '.' ) ;
88
- output += data ;
89
- } ) ;
90
- } else {
91
- test_process = child_process
92
- . spawn ( args [ 0 ] , args . slice ( 1 ) , { stdio : 'inherit' , stderr : 'inherit' } ) ;
93
- }
85
+ test_process . stdout . on ( 'data' , processData ) ;
86
+ test_process . stderr . on ( 'data' , processData ) ;
94
87
95
88
test_process . on ( 'error' , function ( err ) {
96
89
reject ( err ) ;
@@ -105,6 +98,10 @@ var CommandlineTest = function(command) {
105
98
', actual: ' + exitCode ) ;
106
99
}
107
100
101
+ if ( self . testLogStream ) {
102
+ self . testLogStream . end ( ) ;
103
+ }
104
+
108
105
// Skip the rest if we are only verify exit code.
109
106
// Note: we're expecting a file populated by '--resultJsonOutputFile' after
110
107
// this point.
@@ -205,12 +202,15 @@ exports.Executor = function() {
205
202
return test ;
206
203
} ;
207
204
208
- this . execute = function ( ) {
205
+ this . execute = function ( logFile ) {
209
206
var failed = false ;
210
207
211
208
( function runTests ( i ) {
212
209
if ( i < tests . length ) {
213
210
console . log ( 'running: ' + tests [ i ] . command_ ) ;
211
+ if ( logFile ) {
212
+ tests [ i ] . setTestLogFile ( logFile ) ;
213
+ }
214
214
tests [ i ] . run ( ) . then ( function ( ) {
215
215
console . log ( '\n>>> \033[1;32mpass\033[0m' ) ;
216
216
} , function ( err ) {
0 commit comments