File tree 3 files changed +44
-3
lines changed
3 files changed +44
-3
lines changed Original file line number Diff line number Diff line change 26
26
"scripts" : {
27
27
"lint" : " xo" ,
28
28
"test" : " npm run test:node && npm run test:browser && npm run lint" ,
29
- "test:node" : " istanbul cover _mocha -- test.js" ,
29
+ "test:node" : " istanbul cover _mocha -- test.js test.node.js " ,
30
30
"test:browser" : " karma start --single-run" ,
31
31
"test:coverage" : " cat ./coverage/lcov.info | coveralls"
32
32
},
44
44
"karma-mocha" : " ^1.3.0" ,
45
45
"mocha" : " ^5.2.0" ,
46
46
"mocha-lcov-reporter" : " ^1.2.0" ,
47
+ "sinon" : " ^14.0.0" ,
47
48
"xo" : " ^0.23.0"
48
49
},
49
50
"peerDependenciesMeta" : {
Original file line number Diff line number Diff line change @@ -187,11 +187,11 @@ function getDate() {
187
187
}
188
188
189
189
/**
190
- * Invokes `util.format ()` with the specified arguments and writes to stderr.
190
+ * Invokes `util.formatWithOptions ()` with the specified arguments and writes to stderr.
191
191
*/
192
192
193
193
function log ( ...args ) {
194
- return process . stderr . write ( util . format ( ...args ) + '\n' ) ;
194
+ return process . stderr . write ( util . formatWithOptions ( exports . inspectOpts , ...args ) + '\n' ) ;
195
195
}
196
196
197
197
/**
Original file line number Diff line number Diff line change
1
+ /* eslint-env mocha */
2
+
3
+ const assert = require ( 'assert' ) ;
4
+ const util = require ( 'util' ) ;
5
+ const sinon = require ( 'sinon' ) ;
6
+ const debug = require ( './src/node' ) ;
7
+
8
+ const formatWithOptionsSpy = sinon . spy ( util , 'formatWithOptions' ) ;
9
+ beforeEach ( ( ) => {
10
+ formatWithOptionsSpy . resetHistory ( ) ;
11
+ } ) ;
12
+
13
+ describe ( 'debug node' , ( ) => {
14
+ describe ( 'formatting options' , ( ) => {
15
+ it ( 'calls util.formatWithOptions' , ( ) => {
16
+ debug . enable ( '*' ) ;
17
+ const stdErrWriteStub = sinon . stub ( process . stderr , 'write' ) ;
18
+ const log = debug ( 'formatting options' ) ;
19
+ log ( 'hello world' ) ;
20
+ assert ( util . formatWithOptions . callCount === 1 ) ;
21
+ stdErrWriteStub . restore ( ) ;
22
+ } ) ;
23
+
24
+ it ( 'calls util.formatWithOptions with inspectOpts' , ( ) => {
25
+ debug . enable ( '*' ) ;
26
+ const options = {
27
+ hideDate : true ,
28
+ colors : true ,
29
+ depth : 10 ,
30
+ showHidden : true
31
+ } ;
32
+ Object . assign ( debug . inspectOpts , options ) ;
33
+ const stdErrWriteStub = sinon . stub ( process . stderr , 'write' ) ;
34
+ const log = debug ( 'format with inspectOpts' ) ;
35
+ log ( 'hello world2' ) ;
36
+ assert . deepStrictEqual ( util . formatWithOptions . getCall ( 0 ) . args [ 0 ] , options ) ;
37
+ stdErrWriteStub . restore ( ) ;
38
+ } ) ;
39
+ } ) ;
40
+ } ) ;
You can’t perform that action at this time.
0 commit comments