@@ -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 ( 'output with 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' ] ] )
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 ( 'output with 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
61
await t . test ( 'pkg has foo script' , async t => {
84
- const logs = mockConsole ( 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 , [ [ '\n> [email protected] foo\n' ] ] )
102
79
t . ok ( spawk . done ( ) )
103
80
} )
104
81
105
82
await t . test ( 'pkg has foo script, with args' , async t => {
106
- const logs = mockConsole ( t )
107
83
spawk . spawn ( 'sh' , a => a . includes ( 'bar a b c' ) )
108
84
await runScript ( {
109
85
event : 'foo' ,
@@ -122,7 +98,7 @@ 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 , [ [ '\n> [email protected] foo\n> bar a b c\n' ] ] )
126
102
t . ok ( spawk . done ( ) )
127
103
} )
128
104
@@ -131,7 +107,6 @@ t.test('run-script-pkg', async t => {
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,7 +121,7 @@ t.test('run-script-pkg', async t => {
146
121
scripts : { } ,
147
122
} ,
148
123
} )
149
- t . strictSame ( logs , [ ] )
124
+ t . strictSame ( output , [ [ '\n> [email protected] install\n' ] ] )
150
125
t . ok ( spawk . done ( ) )
151
126
} )
152
127
0 commit comments