1- /* global describe, it, context, beforeEach */
1+ /* eslint-env mocha */
22'use strict' ;
33
44let chai ;
@@ -7,84 +7,76 @@ let expect;
77
88let debug ;
99
10- let sinon ;
11-
12- let sinonChai ;
13-
1410if ( typeof module !== 'undefined' ) {
1511 chai = require ( 'chai' ) ;
1612 expect = chai . expect ;
17-
1813 debug = require ( '../src' ) ;
19- sinon = require ( 'sinon' ) ;
20- sinonChai = require ( 'sinon-chai' ) ;
21- chai . use ( sinonChai ) ;
2214}
2315
2416describe ( 'debug' , ( ) => {
25- let log = debug ( 'test' ) ;
26-
27- log . log = sinon . stub ( ) ;
28-
2917 it ( 'passes a basic sanity check' , ( ) => {
30- expect ( log ( 'hello world' ) ) . to . not . throw ( ) ;
18+ const log = debug ( 'test' ) ;
19+ log . enabled = true ;
20+ log . log = ( ) => { } ;
21+
22+ expect ( ( ) => log ( 'hello world' ) ) . to . not . throw ( ) ;
3123 } ) ;
3224
3325 it ( 'allows namespaces to be a non-string value' , ( ) => {
34- expect ( debug . enable ( true ) ) . to . not . throw ( ) ;
35- } ) ;
26+ const log = debug ( 'test' ) ;
27+ log . enabled = true ;
28+ log . log = ( ) => { } ;
3629
37- context ( 'with log function' , ( ) => {
38- beforeEach ( ( ) => {
39- debug . enable ( 'test' ) ;
40- log = debug ( 'test' ) ;
41- } ) ;
30+ expect ( ( ) => debug . enable ( true ) ) . to . not . throw ( ) ;
31+ } ) ;
4232
43- it ( 'uses it ' , ( ) => {
44- log . log = sinon . stub ( ) ;
45- log ( 'using custom log function' ) ;
33+ it ( 'honors global debug namespace enable calls ' , ( ) => {
34+ expect ( debug ( 'test:12345' ) . enabled ) . to . equal ( false ) ;
35+ expect ( debug ( 'test:67890' ) . enabled ) . to . equal ( false ) ;
4636
47- expect ( log . log ) . to . have . been . calledOnce ( ) ;
48- } ) ;
37+ debug . enable ( 'test:12345' ) ;
38+ expect ( debug ( 'test:12345' ) . enabled ) . to . equal ( true ) ;
39+ expect ( debug ( 'test:67890' ) . enabled ) . to . equal ( false ) ;
4940 } ) ;
5041
51- describe ( 'custom functions' , ( ) => {
52- let log ;
42+ it ( 'uses custom log function' , ( ) => {
43+ const log = debug ( 'test' ) ;
44+ log . enabled = true ;
5345
54- beforeEach ( ( ) => {
55- debug . enable ( 'test' ) ;
56- log = debug ( 'test' ) ;
57- } ) ;
46+ const messages = [ ] ;
47+ log . log = ( ...args ) => messages . push ( args ) ;
5848
59- context ( 'with log function' , ( ) => {
60- it ( 'uses it' , ( ) => {
61- log . log = sinon . spy ( ) ;
62- log ( 'using custom log function' ) ;
49+ log ( 'using custom log function' ) ;
50+ log ( 'using custom log function again' ) ;
51+ log ( '%O' , 12345 ) ;
6352
64- expect ( log . log ) . to . have . been . calledOnce ( ) ;
65- } ) ;
66- } ) ;
53+ expect ( messages . length ) . to . equal ( 3 ) ;
6754 } ) ;
6855
6956 describe ( 'extend namespace' , ( ) => {
70- let log ;
71-
72- beforeEach ( ( ) => {
73- debug . enable ( 'foo' ) ;
74- log = debug ( 'foo' ) ;
75- } ) ;
76-
7757 it ( 'should extend namespace' , ( ) => {
58+ const log = debug ( 'foo' ) ;
59+ log . enabled = true ;
60+ log . log = ( ) => { } ;
61+
7862 const logBar = log . extend ( 'bar' ) ;
7963 expect ( logBar . namespace ) . to . be . equal ( 'foo:bar' ) ;
8064 } ) ;
8165
8266 it ( 'should extend namespace with custom delimiter' , ( ) => {
67+ const log = debug ( 'foo' ) ;
68+ log . enabled = true ;
69+ log . log = ( ) => { } ;
70+
8371 const logBar = log . extend ( 'bar' , '--' ) ;
8472 expect ( logBar . namespace ) . to . be . equal ( 'foo--bar' ) ;
8573 } ) ;
8674
8775 it ( 'should extend namespace with empty delimiter' , ( ) => {
76+ const log = debug ( 'foo' ) ;
77+ log . enabled = true ;
78+ log . log = ( ) => { } ;
79+
8880 const logBar = log . extend ( 'bar' , '' ) ;
8981 expect ( logBar . namespace ) . to . be . equal ( 'foobar' ) ;
9082 } ) ;
0 commit comments