Skip to content

Commit

Permalink
Fix/debug depth (#926)
Browse files Browse the repository at this point in the history
* fix debug format options ignored

* moved sinon to devDependencies
  • Loading branch information
calvintwr committed May 31, 2024
1 parent f66cb2d commit cac39b1
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 3 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"scripts": {
"lint": "xo",
"test": "npm run test:node && npm run test:browser && npm run lint",
"test:node": "istanbul cover _mocha -- test.js",
"test:node": "istanbul cover _mocha -- test.js test.node.js",
"test:browser": "karma start --single-run",
"test:coverage": "cat ./coverage/lcov.info | coveralls"
},
Expand All @@ -44,6 +44,7 @@
"karma-mocha": "^1.3.0",
"mocha": "^5.2.0",
"mocha-lcov-reporter": "^1.2.0",
"sinon": "^14.0.0",
"xo": "^0.23.0"
},
"peerDependenciesMeta": {
Expand Down
4 changes: 2 additions & 2 deletions src/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,11 +187,11 @@ function getDate() {
}

/**
* Invokes `util.format()` with the specified arguments and writes to stderr.
* Invokes `util.formatWithOptions()` with the specified arguments and writes to stderr.
*/

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

/**
Expand Down
40 changes: 40 additions & 0 deletions test.node.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/* eslint-env mocha */

const assert = require('assert');
const util = require('util');
const sinon = require('sinon');
const debug = require('./src/node');

const formatWithOptionsSpy = sinon.spy(util, 'formatWithOptions');
beforeEach(() => {
formatWithOptionsSpy.resetHistory();
});

describe('debug node', () => {
describe('formatting options', () => {
it('calls util.formatWithOptions', () => {
debug.enable('*');
const stdErrWriteStub = sinon.stub(process.stderr, 'write');
const log = debug('formatting options');
log('hello world');
assert(util.formatWithOptions.callCount === 1);
stdErrWriteStub.restore();
});

it('calls util.formatWithOptions with inspectOpts', () => {
debug.enable('*');
const options = {
hideDate: true,
colors: true,
depth: 10,
showHidden: true
};
Object.assign(debug.inspectOpts, options);
const stdErrWriteStub = sinon.stub(process.stderr, 'write');
const log = debug('format with inspectOpts');
log('hello world2');
assert.deepStrictEqual(util.formatWithOptions.getCall(0).args[0], options);
stdErrWriteStub.restore();
});
});
});

0 comments on commit cac39b1

Please sign in to comment.