@@ -6,18 +6,19 @@ const isWindows = process.platform === 'win32'
6
6
const emptyDir = t . testdir ( { } )
7
7
8
8
const pkill = process . kill
9
- const consoleLog = console . log
10
9
11
- const mockConsole = t => {
12
- const logs = [ ]
13
- console . log = ( ... args ) => logs . push ( args )
14
- t . teardown ( ( ) => console . log = consoleLog )
15
- return logs
10
+ const output = [ ]
11
+ const appendOutput = ( level , ... args ) => {
12
+ if ( level === 'standard' ) {
13
+ output . push ( [ ... args ] )
14
+ }
16
15
}
16
+ process . on ( 'output' , appendOutput )
17
+ t . afterEach ( ( ) => output . length = 0 )
18
+ t . teardown ( ( ) => process . removeListener ( 'output' , appendOutput ) )
17
19
18
20
t . test ( 'run-script-pkg' , async t => {
19
- await t . test ( 'do the banner when stdio is inherited, handle line breaks' , async t => {
20
- const logs = mockConsole ( t )
21
+ await t . test ( 'stdio inherit no args and a pkgid' , async t => {
21
22
spawk . spawn ( 'sh' , a => a . includes ( 'bar\nbaz\n' ) )
22
23
await runScript ( {
23
24
event : 'foo' ,
@@ -33,34 +34,11 @@ t.test('run-script-pkg', async t => {
33
34
scripts : { } ,
34
35
} ,
35
36
} )
36
- t . strictSame ( logs , [ [ '\n> [email protected] foo\n> bar\n> baz\n' ] ] )
37
+ t . strictSame ( output , [ [ '\n> [email protected] foo\n> bar\n> baz\n' ] ] )
37
38
t . ok ( spawk . done ( ) )
38
39
} )
39
40
40
- await t . test ( 'do not show banner when stdio is inherited, if suppressed' , async t => {
41
- const logs = mockConsole ( t )
42
- spawk . spawn ( 'sh' , a => a . includes ( 'bar' ) )
43
- await runScript ( {
44
- event : 'foo' ,
45
- path : emptyDir ,
46
- scriptShell : 'sh' ,
47
- env : {
48
- environ : 'value' ,
49
- } ,
50
- stdio : 'inherit' ,
51
- cmd : 'bar' ,
52
- pkg : {
53
-
54
- scripts : { } ,
55
- } ,
56
- banner : false ,
57
- } )
58
- t . strictSame ( logs , [ ] )
59
- t . ok ( spawk . done ( ) )
60
- } )
61
-
62
- await t . test ( 'do the banner with no pkgid' , async t => {
63
- const logs = mockConsole ( t )
41
+ await t . test ( 'stdio inherit args and no pkgid' , async t => {
64
42
spawk . spawn ( 'sh' , a => a . includes ( 'bar baz buzz' ) )
65
43
await runScript ( {
66
44
event : 'foo' ,
@@ -76,12 +54,11 @@ t.test('run-script-pkg', async t => {
76
54
scripts : { } ,
77
55
} ,
78
56
} )
79
- t . strictSame ( logs , [ [ '\n> foo\n> bar baz buzz\n' ] ] )
57
+ t . strictSame ( output , [ [ '\n> foo\n> bar baz buzz\n' ] ] )
80
58
t . ok ( spawk . done ( ) )
81
59
} )
82
60
83
- await t . test ( 'pkg has foo script' , async t => {
84
- const logs = mockConsole ( t )
61
+ await t . test ( 'pkg has foo script, with stdio pipe' , async t => {
85
62
spawk . spawn ( 'sh' , a => a . includes ( 'bar' ) )
86
63
await runScript ( {
87
64
event : 'foo' ,
@@ -98,12 +75,11 @@ t.test('run-script-pkg', async t => {
98
75
} ,
99
76
} ,
100
77
} )
101
- t . strictSame ( logs , [ ] )
78
+ t . strictSame ( output , [ ] )
102
79
t . ok ( spawk . done ( ) )
103
80
} )
104
81
105
- await t . test ( 'pkg has foo script, with args' , async t => {
106
- const logs = mockConsole ( t )
82
+ await t . test ( 'pkg has foo script, with stdio pipe and args' , async t => {
107
83
spawk . spawn ( 'sh' , a => a . includes ( 'bar a b c' ) )
108
84
await runScript ( {
109
85
event : 'foo' ,
@@ -122,16 +98,16 @@ t.test('run-script-pkg', async t => {
122
98
args : [ 'a' , 'b' , 'c' ] ,
123
99
binPaths : false ,
124
100
} )
125
- t . strictSame ( logs , [ ] )
101
+ t . strictSame ( output , [ ] )
126
102
t . ok ( spawk . done ( ) )
127
103
} )
128
104
129
- await t . test ( 'pkg has no install or preinstall script, node-gyp files present' , async t => {
105
+ /* eslint-disable-next-line max-len */
106
+ await t . test ( 'pkg has no install or preinstall script, node-gyp files present, stdio pipe' , async t => {
130
107
const testdir = t . testdir ( {
131
108
'binding.gyp' : 'exists' ,
132
109
} )
133
110
134
- const logs = mockConsole ( t )
135
111
spawk . spawn ( 'sh' , a => a . includes ( 'node-gyp rebuild' ) )
136
112
await runScript ( {
137
113
event : 'install' ,
@@ -146,11 +122,11 @@ t.test('run-script-pkg', async t => {
146
122
scripts : { } ,
147
123
} ,
148
124
} )
149
- t . strictSame ( logs , [ ] )
125
+ t . strictSame ( output , [ ] )
150
126
t . ok ( spawk . done ( ) )
151
127
} )
152
128
153
- t . test ( 'pkg has no install or preinstall script, but gypfile:false' , async t => {
129
+ t . test ( 'pkg has no install or preinstall script, but gypfile:false, stdio pipe ' , async t => {
154
130
const testdir = t . testdir ( {
155
131
'binding.gyp' : 'exists' ,
156
132
} )
@@ -170,6 +146,7 @@ t.test('run-script-pkg', async t => {
170
146
} ,
171
147
} ,
172
148
} )
149
+ t . strictSame ( output , [ ] )
173
150
t . strictSame ( res , { code : 0 , signal : null } )
174
151
} )
175
152
@@ -190,7 +167,7 @@ t.test('run-script-pkg', async t => {
190
167
t . ok ( interceptor . calledWith . stdio [ 0 ] . writableEnded , 'stdin was ended properly' )
191
168
} )
192
169
193
- await t . test ( 'kill process when foreground process ends with signal' , async t => {
170
+ await t . test ( 'kill process when foreground process ends with signal, stdio inherit ' , async t => {
194
171
t . teardown ( ( ) => {
195
172
process . kill = pkill
196
173
} )
@@ -219,14 +196,15 @@ t.test('run-script-pkg', async t => {
219
196
} ,
220
197
} ,
221
198
} ) )
199
+ t . strictSame ( output , [ [ '\n> [email protected] sleep\n> sleep 1000000\n' ] ] )
222
200
t . ok ( spawk . done ( ) )
223
201
if ( ! isWindows ) {
224
202
t . equal ( signal , 'SIGFOO' , 'process.kill got expected signal' )
225
203
t . equal ( pid , process . pid , 'process.kill got expected pid' )
226
204
}
227
205
} )
228
206
229
- await t . test ( 'kill process when foreground process ends with signal' , async t => {
207
+ await t . test ( 'kill process when foreground process ends with signal, stdio inherit ' , async t => {
230
208
t . teardown ( ( ) => {
231
209
process . kill = pkill
232
210
} )
@@ -255,14 +233,15 @@ t.test('run-script-pkg', async t => {
255
233
} ,
256
234
} ,
257
235
} ) )
236
+ t . strictSame ( output , [ [ '\n> [email protected] sleep\n> sleep 1000000\n' ] ] )
258
237
t . ok ( spawk . done ( ) )
259
238
if ( ! isWindows ) {
260
239
t . equal ( signal , 'SIGFOO' , 'process.kill got expected signal' )
261
240
t . equal ( pid , process . pid , 'process.kill got expected pid' )
262
241
}
263
242
} )
264
243
265
- t . test ( 'rejects if process.kill fails to end process' , async t => {
244
+ t . test ( 'rejects if process.kill fails to end process, stdio inherit ' , async t => {
266
245
t . teardown ( ( ) => {
267
246
process . kill = pkill
268
247
} )
@@ -290,6 +269,7 @@ t.test('run-script-pkg', async t => {
290
269
} ,
291
270
} ,
292
271
} ) )
272
+ t . strictSame ( output , [ [ '\n> [email protected] sleep\n> sleep 1000000\n' ] ] )
293
273
t . ok ( spawk . done ( ) )
294
274
if ( ! isWindows ) {
295
275
t . equal ( signal , 'SIGFOO' , 'process.kill got expected signal' )
@@ -314,6 +294,7 @@ t.test('run-script-pkg', async t => {
314
294
} ,
315
295
} ,
316
296
} ) )
297
+ t . strictSame ( output , [ ] )
317
298
t . ok ( spawk . done ( ) )
318
299
} )
319
300
} )
0 commit comments