Skip to content

Commit

Permalink
change: append namespaces instead of replace
Browse files Browse the repository at this point in the history
in this way `debug` has to keep a track of all namespaces, for #451, i
think this is an expected behaviour.

fix #451
  • Loading branch information
zhuangya committed Nov 6, 2017
1 parent 7116906 commit 439e358
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/common.js
Expand Up @@ -157,8 +157,8 @@ module.exports = function setup(env) {
function enable(namespaces) {
createDebug.save(namespaces);

createDebug.names = [];
createDebug.skips = [];
createDebug.names = createDebug.names || [];
createDebug.skips = createDebug.skips || [];

var i;
var split = (typeof namespaces === 'string' ? namespaces : '').split(/[\s,]+/);
Expand Down Expand Up @@ -187,7 +187,7 @@ module.exports = function setup(env) {
*/

function disable() {
createDebug.enable('');
createDebug.names = [];
}

/**
Expand All @@ -200,7 +200,7 @@ module.exports = function setup(env) {

function enabled(name) {
if (name[name.length - 1] === '*') {
return true;
return createDebug.names.length > 0;
}
var i, len;
for (i = 0, len = createDebug.skips.length; i < len; i++) {
Expand Down
19 changes: 19 additions & 0 deletions test/debug_spec.js
Expand Up @@ -64,4 +64,23 @@ describe('debug', function () {
});
});

context('disable()', function () {
beforeEach(function () {
debug.enable('*');
debug('should disable')
});

it('disable itself', function () {
debug.disable('*');
expect(debug.enabled('*')).to.be.false;
});
});

it('should avoid namespace conflict', function () {
debug.enable('test1*');
debug.enable('test2*');

expect(debug('test1').enabled).to.be.true;
expect(debug('test2').enabled).to.be.true;
});
});

0 comments on commit 439e358

Please sign in to comment.