1
1
/* eslint-env mocha */
2
- 'use strict' ;
3
2
4
- let chai ;
5
-
6
- let expect ;
7
-
8
- let debug ;
9
-
10
- if ( typeof module !== 'undefined' ) {
11
- chai = require ( 'chai' ) ;
12
- expect = chai . expect ;
13
- debug = require ( './src' ) ;
14
- }
3
+ const assert = require ( 'assert' ) ;
4
+ const debug = require ( './src' ) ;
15
5
16
6
describe ( 'debug' , ( ) => {
17
7
it ( 'passes a basic sanity check' , ( ) => {
18
8
const log = debug ( 'test' ) ;
19
9
log . enabled = true ;
20
10
log . log = ( ) => { } ;
21
11
22
- expect ( ( ) => log ( 'hello world' ) ) . to . not . throw ( ) ;
12
+ assert . doesNotThrow ( ( ) => log ( 'hello world' ) ) ;
23
13
} ) ;
24
14
25
15
it ( 'allows namespaces to be a non-string value' , ( ) => {
26
16
const log = debug ( 'test' ) ;
27
17
log . enabled = true ;
28
18
log . log = ( ) => { } ;
29
19
30
- expect ( ( ) => debug . enable ( true ) ) . to . not . throw ( ) ;
20
+ assert . doesNotThrow ( ( ) => debug . enable ( true ) ) ;
31
21
} ) ;
32
22
33
23
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 ) ;
24
+ assert . deepStrictEqual ( debug ( 'test:12345' ) . enabled , false ) ;
25
+ assert . deepStrictEqual ( debug ( 'test:67890' ) . enabled , false ) ;
36
26
37
27
debug . enable ( 'test:12345' ) ;
38
- expect ( debug ( 'test:12345' ) . enabled ) . to . equal ( true ) ;
39
- expect ( debug ( 'test:67890' ) . enabled ) . to . equal ( false ) ;
28
+ assert . deepStrictEqual ( debug ( 'test:12345' ) . enabled , true ) ;
29
+ assert . deepStrictEqual ( debug ( 'test:67890' ) . enabled , false ) ;
40
30
} ) ;
41
31
42
32
it ( 'uses custom log function' , ( ) => {
@@ -50,7 +40,7 @@ describe('debug', () => {
50
40
log ( 'using custom log function again' ) ;
51
41
log ( '%O' , 12345 ) ;
52
42
53
- expect ( messages . length ) . to . equal ( 3 ) ;
43
+ assert . deepStrictEqual ( messages . length , 3 ) ;
54
44
} ) ;
55
45
56
46
describe ( 'extend namespace' , ( ) => {
@@ -60,7 +50,7 @@ describe('debug', () => {
60
50
log . log = ( ) => { } ;
61
51
62
52
const logBar = log . extend ( 'bar' ) ;
63
- expect ( logBar . namespace ) . to . be . equal ( 'foo:bar' ) ;
53
+ assert . deepStrictEqual ( logBar . namespace , 'foo:bar' ) ;
64
54
} ) ;
65
55
66
56
it ( 'should extend namespace with custom delimiter' , ( ) => {
@@ -69,7 +59,7 @@ describe('debug', () => {
69
59
log . log = ( ) => { } ;
70
60
71
61
const logBar = log . extend ( 'bar' , '--' ) ;
72
- expect ( logBar . namespace ) . to . be . equal ( 'foo--bar' ) ;
62
+ assert . deepStrictEqual ( logBar . namespace , 'foo--bar' ) ;
73
63
} ) ;
74
64
75
65
it ( 'should extend namespace with empty delimiter' , ( ) => {
@@ -78,46 +68,46 @@ describe('debug', () => {
78
68
log . log = ( ) => { } ;
79
69
80
70
const logBar = log . extend ( 'bar' , '' ) ;
81
- expect ( logBar . namespace ) . to . be . equal ( 'foobar' ) ;
71
+ assert . deepStrictEqual ( logBar . namespace , 'foobar' ) ;
82
72
} ) ;
83
73
} ) ;
84
74
85
75
describe ( 'rebuild namespaces string (disable)' , ( ) => {
86
76
it ( 'handle names, skips, and wildcards' , ( ) => {
87
77
debug . enable ( 'test,abc*,-abc' ) ;
88
78
const namespaces = debug . disable ( ) ;
89
- expect ( namespaces ) . to . equal ( 'test,abc*,-abc' ) ;
79
+ assert . deepStrictEqual ( namespaces , 'test,abc*,-abc' ) ;
90
80
} ) ;
91
81
92
82
it ( 'handles empty' , ( ) => {
93
83
debug . enable ( '' ) ;
94
84
const namespaces = debug . disable ( ) ;
95
- expect ( namespaces ) . to . equal ( '' ) ;
96
- expect ( debug . names ) . to . deep . equal ( [ ] ) ;
97
- expect ( debug . skips ) . to . deep . equal ( [ ] ) ;
85
+ assert . deepStrictEqual ( namespaces , '' ) ;
86
+ assert . deepStrictEqual ( debug . names , [ ] ) ;
87
+ assert . deepStrictEqual ( debug . skips , [ ] ) ;
98
88
} ) ;
99
89
100
90
it ( 'handles all' , ( ) => {
101
91
debug . enable ( '*' ) ;
102
92
const namespaces = debug . disable ( ) ;
103
- expect ( namespaces ) . to . equal ( '*' ) ;
93
+ assert . deepStrictEqual ( namespaces , '*' ) ;
104
94
} ) ;
105
95
106
96
it ( 'handles skip all' , ( ) => {
107
97
debug . enable ( '-*' ) ;
108
98
const namespaces = debug . disable ( ) ;
109
- expect ( namespaces ) . to . equal ( '-*' ) ;
99
+ assert . deepStrictEqual ( namespaces , '-*' ) ;
110
100
} ) ;
111
101
112
102
it ( 'names+skips same with new string' , ( ) => {
113
103
debug . enable ( 'test,abc*,-abc' ) ;
114
104
const oldNames = [ ...debug . names ] ;
115
105
const oldSkips = [ ...debug . skips ] ;
116
106
const namespaces = debug . disable ( ) ;
117
- expect ( namespaces ) . to . equal ( 'test,abc*,-abc' ) ;
107
+ assert . deepStrictEqual ( namespaces , 'test,abc*,-abc' ) ;
118
108
debug . enable ( namespaces ) ;
119
- expect ( oldNames . map ( String ) ) . to . deep . equal ( debug . names . map ( String ) ) ;
120
- expect ( oldSkips . map ( String ) ) . to . deep . equal ( debug . skips . map ( String ) ) ;
109
+ assert . deepStrictEqual ( oldNames . map ( String ) , debug . names . map ( String ) ) ;
110
+ assert . deepStrictEqual ( oldSkips . map ( String ) , debug . skips . map ( String ) ) ;
121
111
} ) ;
122
112
} ) ;
123
113
} ) ;
1 commit comments
PolGirons commentedon Jan 10, 2022