@@ -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,15 @@ 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
+ await t . test ( 'pkg has no install or preinstall script, node-gyp files present, stdio pipe ' , async t => {
130
106
const testdir = t . testdir ( {
131
107
'binding.gyp' : 'exists' ,
132
108
} )
133
109
134
- const logs = mockConsole ( t )
135
110
spawk . spawn ( 'sh' , a => a . includes ( 'node-gyp rebuild' ) )
136
111
await runScript ( {
137
112
event : 'install' ,
@@ -146,11 +121,11 @@ t.test('run-script-pkg', async t => {
146
121
scripts : { } ,
147
122
} ,
148
123
} )
149
- t . strictSame ( logs , [ ] )
124
+ t . strictSame ( output , [ ] )
150
125
t . ok ( spawk . done ( ) )
151
126
} )
152
127
153
- t . test ( 'pkg has no install or preinstall script, but gypfile:false' , async t => {
128
+ t . test ( 'pkg has no install or preinstall script, but gypfile:false, stdio pipe ' , async t => {
154
129
const testdir = t . testdir ( {
155
130
'binding.gyp' : 'exists' ,
156
131
} )
@@ -170,6 +145,7 @@ t.test('run-script-pkg', async t => {
170
145
} ,
171
146
} ,
172
147
} )
148
+ t . strictSame ( output , [ ] )
173
149
t . strictSame ( res , { code : 0 , signal : null } )
174
150
} )
175
151
@@ -190,7 +166,7 @@ t.test('run-script-pkg', async t => {
190
166
t . ok ( interceptor . calledWith . stdio [ 0 ] . writableEnded , 'stdin was ended properly' )
191
167
} )
192
168
193
- await t . test ( 'kill process when foreground process ends with signal' , async t => {
169
+ await t . test ( 'kill process when foreground process ends with signal, stdio inherit ' , async t => {
194
170
t . teardown ( ( ) => {
195
171
process . kill = pkill
196
172
} )
@@ -219,14 +195,15 @@ t.test('run-script-pkg', async t => {
219
195
} ,
220
196
} ,
221
197
} ) )
198
+ t . strictSame ( output , [ [ '\n> [email protected] sleep\n> sleep 1000000\n' ] ] )
222
199
t . ok ( spawk . done ( ) )
223
200
if ( ! isWindows ) {
224
201
t . equal ( signal , 'SIGFOO' , 'process.kill got expected signal' )
225
202
t . equal ( pid , process . pid , 'process.kill got expected pid' )
226
203
}
227
204
} )
228
205
229
- await t . test ( 'kill process when foreground process ends with signal' , async t => {
206
+ await t . test ( 'kill process when foreground process ends with signal, stdio inherit ' , async t => {
230
207
t . teardown ( ( ) => {
231
208
process . kill = pkill
232
209
} )
@@ -255,6 +232,7 @@ t.test('run-script-pkg', async t => {
255
232
} ,
256
233
} ,
257
234
} ) )
235
+ t . strictSame ( output , [ [ '\n> [email protected] sleep\n> sleep 1000000\n' ] ] )
258
236
t . ok ( spawk . done ( ) )
259
237
if ( ! isWindows ) {
260
238
t . equal ( signal , 'SIGFOO' , 'process.kill got expected signal' )
@@ -290,6 +268,7 @@ t.test('run-script-pkg', async t => {
290
268
} ,
291
269
} ,
292
270
} ) )
271
+ t . strictSame ( output , [ [ '\n> [email protected] sleep\n> sleep 1000000\n' ] ] )
293
272
t . ok ( spawk . done ( ) )
294
273
if ( ! isWindows ) {
295
274
t . equal ( signal , 'SIGFOO' , 'process.kill got expected signal' )
@@ -314,6 +293,7 @@ t.test('run-script-pkg', async t => {
314
293
} ,
315
294
} ,
316
295
} ) )
296
+ t . strictSame ( output , [ ] )
317
297
t . ok ( spawk . done ( ) )
318
298
} )
319
299
} )
0 commit comments