@@ -6,18 +6,17 @@ 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
16
- }
10
+ const output = [ ]
11
+ process . on ( 'output' , ( level , ...args ) => {
12
+ if ( level === 'standard' ) {
13
+ output . push ( [ ...args ] )
14
+ }
15
+ } )
16
+ t . afterEach ( ( ) => output . length = 0 )
17
17
18
18
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 )
19
+ await t . test ( 'output with no args and a pkgid' , async t => {
21
20
spawk . spawn ( 'sh' , a => a . includes ( 'bar\nbaz\n' ) )
22
21
await runScript ( {
23
22
event : 'foo' ,
@@ -33,34 +32,15 @@ t.test('run-script-pkg', async t => {
33
32
scripts : { } ,
34
33
} ,
35
34
} )
36
- t . strictSame ( logs , [ [ '\n> [email protected] foo\n> bar\n> baz\n' ] ] )
37
- t . ok ( spawk . done ( ) )
38
- } )
39
-
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 , [ ] )
35
+ t . strictSame ( output , [
36
+ [ '' ] ,
37
+
38
+ [ '' ] ,
39
+ ] )
59
40
t . ok ( spawk . done ( ) )
60
41
} )
61
42
62
- await t . test ( 'do the banner with no pkgid' , async t => {
63
- const logs = mockConsole ( t )
43
+ await t . test ( 'output with args and no pkgid' , async t => {
64
44
spawk . spawn ( 'sh' , a => a . includes ( 'bar baz buzz' ) )
65
45
await runScript ( {
66
46
event : 'foo' ,
@@ -76,12 +56,16 @@ t.test('run-script-pkg', async t => {
76
56
scripts : { } ,
77
57
} ,
78
58
} )
79
- t . strictSame ( logs , [ [ '\n> foo\n> bar baz buzz\n' ] ] )
59
+ t . strictSame ( output , [
60
+ [ '' ] ,
61
+ [ '> foo' ] ,
62
+ [ '> bar baz buzz' ] ,
63
+ [ '' ] ,
64
+ ] )
80
65
t . ok ( spawk . done ( ) )
81
66
} )
82
67
83
68
await t . test ( 'pkg has foo script' , async t => {
84
- const logs = mockConsole ( t )
85
69
spawk . spawn ( 'sh' , a => a . includes ( 'bar' ) )
86
70
await runScript ( {
87
71
event : 'foo' ,
@@ -98,12 +82,15 @@ t.test('run-script-pkg', async t => {
98
82
} ,
99
83
} ,
100
84
} )
101
- t . strictSame ( logs , [ ] )
85
+ t . strictSame ( output , [
86
+ [ '' ] ,
87
+
88
+ [ '' ] ,
89
+ ] )
102
90
t . ok ( spawk . done ( ) )
103
91
} )
104
92
105
93
await t . test ( 'pkg has foo script, with args' , async t => {
106
- const logs = mockConsole ( t )
107
94
spawk . spawn ( 'sh' , a => a . includes ( 'bar a b c' ) )
108
95
await runScript ( {
109
96
event : 'foo' ,
@@ -122,7 +109,12 @@ t.test('run-script-pkg', async t => {
122
109
args : [ 'a' , 'b' , 'c' ] ,
123
110
binPaths : false ,
124
111
} )
125
- t . strictSame ( logs , [ ] )
112
+ t . strictSame ( output , [
113
+ [ '' ] ,
114
+
115
+ [ '> bar a b c' ] ,
116
+ [ '' ] ,
117
+ ] )
126
118
t . ok ( spawk . done ( ) )
127
119
} )
128
120
@@ -131,7 +123,6 @@ t.test('run-script-pkg', async t => {
131
123
'binding.gyp' : 'exists' ,
132
124
} )
133
125
134
- const logs = mockConsole ( t )
135
126
spawk . spawn ( 'sh' , a => a . includes ( 'node-gyp rebuild' ) )
136
127
await runScript ( {
137
128
event : 'install' ,
@@ -146,7 +137,11 @@ t.test('run-script-pkg', async t => {
146
137
scripts : { } ,
147
138
} ,
148
139
} )
149
- t . strictSame ( logs , [ ] )
140
+ t . strictSame ( output , [
141
+ [ '' ] ,
142
+
143
+ [ '' ] ,
144
+ ] )
150
145
t . ok ( spawk . done ( ) )
151
146
} )
152
147
0 commit comments