Skip to content

Commit

Permalink
add spec with enabled namespace
Browse files Browse the repository at this point in the history
  • Loading branch information
donatas committed Jun 13, 2018
1 parent ecc5eaa commit d790954
Showing 1 changed file with 21 additions and 10 deletions.
31 changes: 21 additions & 10 deletions test/debug_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,26 +85,37 @@ describe('debug', function () {
});
});

context('when hiding namespace', function () {
beforeEach(function () {
process.env.DEBUG_HIDE_NAMESPACE = true;
context('toggle namespace in logs', function () {
it('produces the log with namespace (default behavior)', function () {
process.env.DEBUG_HIDE_DATE = true;
withDebug(function(debugInstance) {
debug = debugInstance;
debug.enable('test');
log = debug('test');
debug.enable('some-namespace');
log = debug('some-namespace');
});
});

afterEach(function () {
delete process.env.DEBUG_HIDE_NAMESPACE;
log.log = sinon.spy();
log('some message');
expect(log.log.getCall(0).args[0].trim()).to.match(/some\-namespace/);
expect(log.log.getCall(0).args[0].trim()).to.match(/some message/);
delete process.env.DEBUG_HIDE_DATE;
});

it('produces the log without namespace', function () {
it('produces the log without namespace when DEBUG_HIDE_NAMESPACE is set', function () {
process.env.DEBUG_HIDE_DATE = true;
process.env.DEBUG_HIDE_NAMESPACE = true;

withDebug(function(debugInstance) {
debug = debugInstance;
debug.enable('test');
log = debug('test');
});

log.log = sinon.spy();
log('some message');
expect(log.log.getCall(0).args[0].trim()).to.equal('some message');

delete process.env.DEBUG_HIDE_DATE;
delete process.env.DEBUG_HIDE_NAMESPACE;
});
});
});

0 comments on commit d790954

Please sign in to comment.