@@ -6,18 +6,19 @@ const isWindows = process.platform === 'win32'
66const emptyDir = t . testdir ( { } )
77
88const pkill = process . kill
9- const consoleLog = console . log
109
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+ }
1615}
16+ process . on ( 'output' , appendOutput )
17+ t . afterEach ( ( ) => output . length = 0 )
18+ t . teardown ( ( ) => process . removeListener ( 'output' , appendOutput ) )
1719
1820t . 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 => {
2122 spawk . spawn ( 'sh' , a => a . includes ( 'bar\nbaz\n' ) )
2223 await runScript ( {
2324 event : 'foo' ,
@@ -33,34 +34,11 @@ t.test('run-script-pkg', async t => {
3334 scripts : { } ,
3435 } ,
3536 } )
36- t . strictSame ( logs , [ [ '\n> foo@1.2.3 foo\n> bar\n> baz\n' ] ] )
37+ t . strictSame ( output , [ [ '\n> foo@1.2.3 foo\n> bar\n> baz\n' ] ] )
3738 t . ok ( spawk . done ( ) )
3839 } )
3940
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- _id : 'foo@1.2.3' ,
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 => {
6442 spawk . spawn ( 'sh' , a => a . includes ( 'bar baz buzz' ) )
6543 await runScript ( {
6644 event : 'foo' ,
@@ -76,12 +54,11 @@ t.test('run-script-pkg', async t => {
7654 scripts : { } ,
7755 } ,
7856 } )
79- t . strictSame ( logs , [ [ '\n> foo\n> bar baz buzz\n' ] ] )
57+ t . strictSame ( output , [ [ '\n> foo\n> bar baz buzz\n' ] ] )
8058 t . ok ( spawk . done ( ) )
8159 } )
8260
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 => {
8562 spawk . spawn ( 'sh' , a => a . includes ( 'bar' ) )
8663 await runScript ( {
8764 event : 'foo' ,
@@ -98,12 +75,11 @@ t.test('run-script-pkg', async t => {
9875 } ,
9976 } ,
10077 } )
101- t . strictSame ( logs , [ ] )
78+ t . strictSame ( output , [ ] )
10279 t . ok ( spawk . done ( ) )
10380 } )
10481
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 => {
10783 spawk . spawn ( 'sh' , a => a . includes ( 'bar a b c' ) )
10884 await runScript ( {
10985 event : 'foo' ,
@@ -122,16 +98,16 @@ t.test('run-script-pkg', async t => {
12298 args : [ 'a' , 'b' , 'c' ] ,
12399 binPaths : false ,
124100 } )
125- t . strictSame ( logs , [ ] )
101+ t . strictSame ( output , [ ] )
126102 t . ok ( spawk . done ( ) )
127103 } )
128104
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 => {
130107 const testdir = t . testdir ( {
131108 'binding.gyp' : 'exists' ,
132109 } )
133110
134- const logs = mockConsole ( t )
135111 spawk . spawn ( 'sh' , a => a . includes ( 'node-gyp rebuild' ) )
136112 await runScript ( {
137113 event : 'install' ,
@@ -146,11 +122,11 @@ t.test('run-script-pkg', async t => {
146122 scripts : { } ,
147123 } ,
148124 } )
149- t . strictSame ( logs , [ ] )
125+ t . strictSame ( output , [ ] )
150126 t . ok ( spawk . done ( ) )
151127 } )
152128
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 => {
154130 const testdir = t . testdir ( {
155131 'binding.gyp' : 'exists' ,
156132 } )
@@ -170,6 +146,7 @@ t.test('run-script-pkg', async t => {
170146 } ,
171147 } ,
172148 } )
149+ t . strictSame ( output , [ ] )
173150 t . strictSame ( res , { code : 0 , signal : null } )
174151 } )
175152
@@ -190,7 +167,7 @@ t.test('run-script-pkg', async t => {
190167 t . ok ( interceptor . calledWith . stdio [ 0 ] . writableEnded , 'stdin was ended properly' )
191168 } )
192169
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 => {
194171 t . teardown ( ( ) => {
195172 process . kill = pkill
196173 } )
@@ -219,14 +196,15 @@ t.test('run-script-pkg', async t => {
219196 } ,
220197 } ,
221198 } ) )
199+ t . strictSame ( output , [ [ '\n> husky@1.2.3 sleep\n> sleep 1000000\n' ] ] )
222200 t . ok ( spawk . done ( ) )
223201 if ( ! isWindows ) {
224202 t . equal ( signal , 'SIGFOO' , 'process.kill got expected signal' )
225203 t . equal ( pid , process . pid , 'process.kill got expected pid' )
226204 }
227205 } )
228206
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 => {
230208 t . teardown ( ( ) => {
231209 process . kill = pkill
232210 } )
@@ -255,14 +233,15 @@ t.test('run-script-pkg', async t => {
255233 } ,
256234 } ,
257235 } ) )
236+ t . strictSame ( output , [ [ '\n> husky@1.2.3 sleep\n> sleep 1000000\n' ] ] )
258237 t . ok ( spawk . done ( ) )
259238 if ( ! isWindows ) {
260239 t . equal ( signal , 'SIGFOO' , 'process.kill got expected signal' )
261240 t . equal ( pid , process . pid , 'process.kill got expected pid' )
262241 }
263242 } )
264243
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 => {
266245 t . teardown ( ( ) => {
267246 process . kill = pkill
268247 } )
@@ -290,6 +269,7 @@ t.test('run-script-pkg', async t => {
290269 } ,
291270 } ,
292271 } ) )
272+ t . strictSame ( output , [ [ '\n> husky@1.2.3 sleep\n> sleep 1000000\n' ] ] )
293273 t . ok ( spawk . done ( ) )
294274 if ( ! isWindows ) {
295275 t . equal ( signal , 'SIGFOO' , 'process.kill got expected signal' )
@@ -314,6 +294,7 @@ t.test('run-script-pkg', async t => {
314294 } ,
315295 } ,
316296 } ) )
297+ t . strictSame ( output , [ ] )
317298 t . ok ( spawk . done ( ) )
318299 } )
319300} )
0 commit comments