@@ -29,6 +29,11 @@ export interface SpawnOptions {
29
29
*/
30
30
export default class CommandAcceptanceTest {
31
31
32
+ /**
33
+ * Debug mode
34
+ */
35
+ debug : string | boolean ;
36
+
32
37
/**
33
38
* The command to invoke, i.e. 'build' would test the invocation of '$ denali
34
39
* build'
@@ -85,8 +90,12 @@ export default class CommandAcceptanceTest {
85
90
* happening in a CommandAcceptanceTest
86
91
* @param options.populateWithDummy Should the test directory be populated
87
92
* with a copy of the dummy app?
93
+ * @param options.debug If true, DEBUG=* will bet set for the spawned command,
94
+ * and the output of the command will be streamed to the console. You can
95
+ * also supply a string which will be used as the value of DEBUG to reduce
96
+ * the noise.
88
97
*/
89
- constructor ( command : string , options : { dir ?: string , environment ?: string , name ?: string , populateWithDummy ?: boolean } = { } ) {
98
+ constructor ( command : string , options : { dir ?: string , environment ?: string , name ?: string , populateWithDummy ?: boolean , debug ?: boolean | string } = { } ) {
90
99
this . command = command ;
91
100
this . dir = options . dir || ( < any > tmp . dirSync ( {
92
101
dir : 'tmp' ,
@@ -96,6 +105,7 @@ export default class CommandAcceptanceTest {
96
105
unsafeCleanup : ! process . env . DENALI_LEAVE_TMP ,
97
106
prefix : `command-acceptance-test-${ options . name || command } -`
98
107
} ) ) . name ;
108
+ this . debug = options . debug ;
99
109
this . environment = options . environment || 'development' ;
100
110
this . projectRoot = process . cwd ( ) ;
101
111
// We don't use node_modules/.bin/denali because if denali-cli is linked in
@@ -183,10 +193,12 @@ export default class CommandAcceptanceTest {
183
193
async spawn ( options : SpawnOptions & { checkOutput : false | ( ( stdout : string , stderr : string , dir : string ) => boolean ) } ) {
184
194
return < any > new Promise ( ( resolve , reject ) => {
185
195
196
+ let env : { [ key : string ] : string } = { NODE_ENV : this . environment } ;
197
+ if ( this . debug ) {
198
+ env . DEBUG = this . debug === true ? '*' : this . debug ;
199
+ }
186
200
this . spawnedCommand = spawn ( this . denaliPath , this . command . split ( ' ' ) , {
187
- env : Object . assign ( { } , process . env , {
188
- NODE_ENV : this . environment
189
- } , options . env || { } ) ,
201
+ env : Object . assign ( { } , process . env , env , options . env || { } ) ,
190
202
cwd : this . dir ,
191
203
stdio : 'pipe'
192
204
} ) ;
@@ -203,11 +215,17 @@ export default class CommandAcceptanceTest {
203
215
let output = d . toString ( ) ;
204
216
stdoutBuffer += output ;
205
217
combinedBuffer += output ;
218
+ if ( this . debug ) {
219
+ process . stdout . write ( output ) ;
220
+ }
206
221
} ) ;
207
222
this . spawnedCommand . stderr . on ( 'data' , ( d ) => {
208
223
let output = d . toString ( ) ;
209
224
stderrBuffer += output ;
210
225
combinedBuffer += output ;
226
+ if ( this . debug ) {
227
+ process . stderr . write ( output ) ;
228
+ }
211
229
if ( options . failOnStderr && stderrBuffer . match ( / [ A - z 0 - 9 ] / ) ) {
212
230
process . removeListener ( 'exit' , cleanup ) ;
213
231
this . cleanup ( ) ;
0 commit comments