@@ -23,8 +23,9 @@ const fakeProcess = {
23
23
}
24
24
} ;
25
25
26
+ const logger = require ( '../lib/log' ) ;
27
+
26
28
describe ( 'hexo-log' , ( ) => {
27
- const logger = require ( '../lib/log' ) ;
28
29
let loggerModule ;
29
30
30
31
beforeEach ( ( ) => {
@@ -43,7 +44,7 @@ describe('hexo-log', () => {
43
44
} ) ;
44
45
45
46
it ( 'trace - should call console.trace' , ( ) => {
46
- const spy = sinon . fake ( ) ;
47
+ const spy = sinon . spy ( ) ;
47
48
loggerModule . __set__ ( 'console.trace' , spy ) ;
48
49
49
50
loggerModule . __with__ ( fakeProcess ) ( ( ) => {
@@ -55,7 +56,7 @@ describe('hexo-log', () => {
55
56
} ) ;
56
57
57
58
it ( 'debug - should call console.debug' , ( ) => {
58
- const spy = sinon . fake ( ) ;
59
+ const spy = sinon . spy ( ) ;
59
60
loggerModule . __set__ ( 'console.debug' , spy ) ;
60
61
61
62
loggerModule . __with__ ( fakeProcess ) ( ( ) => {
@@ -67,7 +68,7 @@ describe('hexo-log', () => {
67
68
} ) ;
68
69
69
70
it ( 'info - should call console.info' , ( ) => {
70
- const spy = sinon . fake ( ) ;
71
+ const spy = sinon . spy ( ) ;
71
72
loggerModule . __set__ ( 'console.info' , spy ) ;
72
73
73
74
loggerModule . __with__ ( fakeProcess ) ( ( ) => {
@@ -79,7 +80,7 @@ describe('hexo-log', () => {
79
80
} ) ;
80
81
81
82
it ( 'warn - should call console.warn' , ( ) => {
82
- const spy = sinon . fake ( ) ;
83
+ const spy = sinon . spy ( ) ;
83
84
loggerModule . __set__ ( 'console.warn' , spy ) ;
84
85
85
86
loggerModule . __with__ ( fakeProcess ) ( ( ) => {
@@ -91,7 +92,7 @@ describe('hexo-log', () => {
91
92
} ) ;
92
93
93
94
it ( 'error - should call console.error' , ( ) => {
94
- const spy = sinon . fake ( ) ;
95
+ const spy = sinon . spy ( ) ;
95
96
loggerModule . __set__ ( 'console.error' , spy ) ;
96
97
97
98
loggerModule . __with__ ( fakeProcess ) ( ( ) => {
@@ -103,7 +104,7 @@ describe('hexo-log', () => {
103
104
} ) ;
104
105
105
106
it ( 'fatal - should call console.error' , ( ) => {
106
- const spy = sinon . fake ( ) ;
107
+ const spy = sinon . spy ( ) ;
107
108
loggerModule . __set__ ( 'console.error' , spy ) ;
108
109
109
110
loggerModule . __with__ ( fakeProcess ) ( ( ) => {
@@ -137,11 +138,11 @@ describe('hexo-log', () => {
137
138
} ) ;
138
139
139
140
it ( 'options.silent - should ignore those level lower than warn' , ( ) => {
140
- const consoleTraceSpy = sinon . fake ( ) ;
141
- const consoleDebugSpy = sinon . fake ( ) ;
142
- const consoleInfoSpy = sinon . fake ( ) ;
143
- const consoleWarnSpy = sinon . fake ( ) ;
144
- const consoleErrorSpy = sinon . fake ( ) ;
141
+ const consoleTraceSpy = sinon . spy ( ) ;
142
+ const consoleDebugSpy = sinon . spy ( ) ;
143
+ const consoleInfoSpy = sinon . spy ( ) ;
144
+ const consoleWarnSpy = sinon . spy ( ) ;
145
+ const consoleErrorSpy = sinon . spy ( ) ;
145
146
146
147
loggerModule . __set__ ( 'console.trace' , consoleTraceSpy ) ;
147
148
loggerModule . __set__ ( 'console.debug' , consoleDebugSpy ) ;
@@ -166,3 +167,41 @@ describe('hexo-log', () => {
166
167
consoleErrorSpy . calledTwice . should . be . true ;
167
168
} ) ;
168
169
} ) ;
170
+
171
+ describe ( 'hexo-log example' , ( ) => {
172
+ it ( 'log.trace()' , ( ) => {
173
+ const log = logger ( { debug : true } ) ;
174
+
175
+ log . trace ( 'Hello, World!' ) ;
176
+ } ) ;
177
+
178
+ it ( 'log.debug()' , ( ) => {
179
+ const log = logger ( { debug : true } ) ;
180
+
181
+ log . debug ( 'Hello, World!' ) ;
182
+ } ) ;
183
+
184
+ it ( 'log.info()' , ( ) => {
185
+ const log = logger ( { debug : true } ) ;
186
+
187
+ log . info ( 'Hello, World!' ) ;
188
+ } ) ;
189
+
190
+ it ( 'log.warn()' , ( ) => {
191
+ const log = logger ( { debug : true } ) ;
192
+
193
+ log . warn ( 'Hello, World!' ) ;
194
+ } ) ;
195
+
196
+ it ( 'log.error()' , ( ) => {
197
+ const log = logger ( { debug : true } ) ;
198
+
199
+ log . error ( 'Hello, World!' ) ;
200
+ } ) ;
201
+
202
+ it ( 'log.fatal()' , ( ) => {
203
+ const log = logger ( { debug : true } ) ;
204
+
205
+ log . fatal ( 'Hello, World!' ) ;
206
+ } ) ;
207
+ } ) ;
0 commit comments