1
1
import { serial as test } from 'ava' ;
2
- import m from '.' ;
2
+ import hookStd from '.' ;
3
3
4
4
const { stdout, stderr} = process ;
5
5
@@ -27,7 +27,7 @@ test.cb('hook stdout & stderr', t => {
27
27
28
28
let i = 0 ;
29
29
30
- const promise = m ( str => {
30
+ const promise = hookStd ( str => {
31
31
if ( str === 'foo' || str === 'bar' ) {
32
32
t . pass ( ) ;
33
33
}
@@ -45,7 +45,7 @@ test.cb('hook stdout & stderr', t => {
45
45
test . cb ( 'hook stdout' , t => {
46
46
t . plan ( 1 ) ;
47
47
48
- const promise = m . stdout ( str => {
48
+ const promise = hookStd . stdout ( str => {
49
49
t . is ( str , 'foo' ) ;
50
50
promise . unhook ( ) ;
51
51
t . end ( ) ;
@@ -57,7 +57,7 @@ test.cb('hook stdout', t => {
57
57
test . cb ( 'hook stderr' , t => {
58
58
t . plan ( 1 ) ;
59
59
60
- const promise = m . stderr ( str => {
60
+ const promise = hookStd . stderr ( str => {
61
61
t . is ( str , 'foo' ) ;
62
62
promise . unhook ( ) ;
63
63
t . end ( ) ;
@@ -72,7 +72,7 @@ test.cb('hook custom stream', t => {
72
72
73
73
let i = 0 ;
74
74
75
- const promise = m ( { streams} , str => {
75
+ const promise = hookStd ( { streams} , str => {
76
76
if ( str === 'foo' ) {
77
77
t . pass ( ) ;
78
78
}
@@ -108,7 +108,7 @@ test('passes through the return value of the underlying write call', t => {
108
108
write : loggingWrite ( log , ( ) => returnValue )
109
109
} ;
110
110
111
- m . stdout ( { silent : false } , str => str ) ;
111
+ hookStd . stdout ( { silent : false } , str => str ) ;
112
112
113
113
t . false ( process . stdout . write ( 'foo' ) ) ;
114
114
returnValue = true ;
@@ -124,7 +124,7 @@ test('if silent, returns true by default', t => {
124
124
write : ( ) => t . fail ( )
125
125
} ;
126
126
127
- m . stdout ( str => {
127
+ hookStd . stdout ( str => {
128
128
log . push ( str ) ;
129
129
return str ;
130
130
} ) ;
@@ -142,7 +142,7 @@ test('if silent, callback can return a boolean', t => {
142
142
write : ( ) => t . fail ( )
143
143
} ;
144
144
145
- m . stdout ( str => {
145
+ hookStd . stdout ( str => {
146
146
log . push ( str ) ;
147
147
return returnValue ;
148
148
} ) ;
@@ -161,7 +161,7 @@ test('callback can return a buffer', t => {
161
161
write : loggingWrite ( log , ( ) => true )
162
162
} ;
163
163
164
- m . stdout ( { silent : false } , str => Buffer . from ( str ) ) ;
164
+ hookStd . stdout ( { silent : false } , str => Buffer . from ( str ) ) ;
165
165
166
166
t . true ( process . stdout . write ( 'foo' ) ) ;
167
167
t . true ( process . stdout . write ( 'bar' ) ) ;
@@ -177,7 +177,7 @@ test('if no options are assigned, behave as silent', t => {
177
177
write : loggingWrite ( log , ( ) => returnValue )
178
178
} ;
179
179
180
- m . stdout ( str => str ) ;
180
+ hookStd . stdout ( str => str ) ;
181
181
182
182
process . stdout . write ( 'foo' ) ;
183
183
returnValue = true ;
@@ -193,7 +193,7 @@ test('if once option is true, only the first write is silent', t => {
193
193
write : loggingWrite ( log , ( ) => returnValue )
194
194
} ;
195
195
196
- m . stdout ( { once : true } , str => str ) ;
196
+ hookStd . stdout ( { once : true } , str => str ) ;
197
197
198
198
process . stdout . write ( 'foo' ) ;
199
199
process . stdout . write ( 'bar' ) ;
@@ -211,7 +211,7 @@ test('if once option is true and silent is false, hook only prints the first wri
211
211
write : loggingWrite ( log , ( ) => true )
212
212
} ;
213
213
214
- m . stdout ( { silent : false , once : true } , str => {
214
+ hookStd . stdout ( { silent : false , once : true } , str => {
215
215
hookReturnValue = str ;
216
216
return str ;
217
217
} ) ;
@@ -231,7 +231,7 @@ test('output is converted to string', t => {
231
231
t . plan ( 4 ) ;
232
232
const log = [ ] ;
233
233
234
- m . stdout ( str => log . push ( str ) ) ;
234
+ hookStd . stdout ( str => log . push ( str ) ) ;
235
235
236
236
process . stdout . write ( 'foo' ) ;
237
237
t . deepEqual ( log , [ 'foo' ] ) ;
@@ -253,7 +253,7 @@ test('string returned by callback is converted to correct encoding', t => {
253
253
write : output => output
254
254
} ;
255
255
256
- m . stdout ( { silent : false } , ( ) => 'tést' ) ;
256
+ hookStd . stdout ( { silent : false } , ( ) => 'tést' ) ;
257
257
258
258
t . is ( process . stdout . write ( 'foo' , 'hex' ) , '74c3a97374' ) ;
259
259
t . is ( process . stdout . write ( 'bar' , 'ascii' ) , 'tC)st' ) ;
@@ -266,7 +266,7 @@ test('string returned by callback is not converted if encoding is invalid', t =>
266
266
write : output => output
267
267
} ;
268
268
269
- m . stdout ( { silent : false } , ( ) => 'tést' ) ;
269
+ hookStd . stdout ( { silent : false } , ( ) => 'tést' ) ;
270
270
271
271
t . is ( process . stdout . write ( 'foo' , 123 ) , 'tést' ) ;
272
272
t . is ( process . stdout . write ( 'bar' , null ) , 'tést' ) ;
@@ -278,7 +278,7 @@ test('promise resolves when stdout & stderr are hooked and released via promise
278
278
t . plan ( 1 ) ;
279
279
const log = [ ] ;
280
280
281
- const promise = m ( str => log . push ( str ) ) ;
281
+ const promise = hookStd ( str => log . push ( str ) ) ;
282
282
283
283
process . stdout . write ( 'foo' ) ;
284
284
process . stderr . write ( 'bar' ) ;
@@ -292,7 +292,7 @@ test('promise resolves when stdout & stderr are hooked and released via callback
292
292
t . plan ( 1 ) ;
293
293
const log = [ ] ;
294
294
295
- const promise = m ( ( str , unhook ) => {
295
+ const promise = hookStd ( ( str , unhook ) => {
296
296
log . push ( str ) ;
297
297
unhook ( ) ;
298
298
} ) ;
@@ -306,7 +306,7 @@ test('promise resolves when stdout & stderr are hooked and released via callback
306
306
307
307
test ( 'promise resolves when stdout is released via promise unhook method' , async t => {
308
308
t . plan ( 1 ) ;
309
- const promise = m . stdout ( str => {
309
+ const promise = hookStd . stdout ( str => {
310
310
t . is ( str , 'foo' ) ;
311
311
} ) ;
312
312
process . stdout . write ( 'foo' ) ;
@@ -316,7 +316,7 @@ test('promise resolves when stdout is released via promise unhook method', async
316
316
317
317
test ( 'promise resolves when stderr is released via promise unhook method' , async t => {
318
318
t . plan ( 1 ) ;
319
- const promise = m . stderr ( str => {
319
+ const promise = hookStd . stderr ( str => {
320
320
t . is ( str , 'foo' ) ;
321
321
} ) ;
322
322
process . stderr . write ( 'foo' ) ;
@@ -329,7 +329,7 @@ test('promise resolves when streams are hooked and released via callback', async
329
329
const log = [ ] ;
330
330
const streams = [ { write : ( ) => { } } , { write : ( ) => { } } ] ;
331
331
332
- const promise = m ( { streams} , ( str , unhook ) => {
332
+ const promise = hookStd ( { streams} , ( str , unhook ) => {
333
333
log . push ( str ) ;
334
334
unhook ( ) ;
335
335
} ) ;
0 commit comments