debug/test.node.js
calvintwr cac39b1c5b
Fix/debug depth (#926)
* fix debug format options ignored

* moved sinon to devDependencies
2024-05-31 13:34:49 +02:00

41 lines
1.1 KiB
JavaScript

/* 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();
});
});
});