Skip to content

Commit cac39b1

Browse files
authoredMay 31, 2024
Fix/debug depth (#926)
* fix debug format options ignored * moved sinon to devDependencies
1 parent f66cb2d commit cac39b1

File tree

3 files changed

+44
-3
lines changed

3 files changed

+44
-3
lines changed
 

‎package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
"scripts": {
2727
"lint": "xo",
2828
"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",
3030
"test:browser": "karma start --single-run",
3131
"test:coverage": "cat ./coverage/lcov.info | coveralls"
3232
},
@@ -44,6 +44,7 @@
4444
"karma-mocha": "^1.3.0",
4545
"mocha": "^5.2.0",
4646
"mocha-lcov-reporter": "^1.2.0",
47+
"sinon": "^14.0.0",
4748
"xo": "^0.23.0"
4849
},
4950
"peerDependenciesMeta": {

‎src/node.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -187,11 +187,11 @@ function getDate() {
187187
}
188188

189189
/**
190-
* Invokes `util.format()` with the specified arguments and writes to stderr.
190+
* Invokes `util.formatWithOptions()` with the specified arguments and writes to stderr.
191191
*/
192192

193193
function log(...args) {
194-
return process.stderr.write(util.format(...args) + '\n');
194+
return process.stderr.write(util.formatWithOptions(exports.inspectOpts, ...args) + '\n');
195195
}
196196

197197
/**

‎test.node.js

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
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+
});

0 commit comments

Comments
 (0)
Please sign in to comment.