@@ -55,6 +55,30 @@ describe('hexo-log', () => {
55
55
spy . called . should . be . true ;
56
56
} ) ;
57
57
58
+ it ( 'trace - with stderr and no stdout' , ( ) => {
59
+ const stdoutSpy = sinon . spy ( ) ;
60
+ const stderrSpy = sinon . spy ( ) ;
61
+
62
+ loggerModule . __set__ ( 'console' , fakeConsole ) ;
63
+
64
+ loggerModule . __with__ ( {
65
+ process : {
66
+ stderr : {
67
+ write : stderrSpy
68
+ } ,
69
+ stdout : {
70
+ write : stdoutSpy
71
+ }
72
+ }
73
+ } ) ( ( ) => {
74
+ const log = loggerModule ( { debug : true } ) ;
75
+ log . trace ( 'test' ) ;
76
+ } ) ;
77
+
78
+ stderrSpy . called . should . be . true ;
79
+ stdoutSpy . called . should . be . false ;
80
+ } ) ;
81
+
58
82
it ( 'debug - should call console.debug' , ( ) => {
59
83
const spy = sinon . spy ( ) ;
60
84
loggerModule . __set__ ( 'console.debug' , spy ) ;
@@ -67,6 +91,30 @@ describe('hexo-log', () => {
67
91
spy . called . should . be . true ;
68
92
} ) ;
69
93
94
+ it ( 'debug - with stdout and no stderr' , ( ) => {
95
+ const stdoutSpy = sinon . spy ( ) ;
96
+ const stderrSpy = sinon . spy ( ) ;
97
+
98
+ loggerModule . __set__ ( 'console' , fakeConsole ) ;
99
+
100
+ loggerModule . __with__ ( {
101
+ process : {
102
+ stderr : {
103
+ write : stderrSpy
104
+ } ,
105
+ stdout : {
106
+ write : stdoutSpy
107
+ }
108
+ }
109
+ } ) ( ( ) => {
110
+ const log = loggerModule ( { debug : true } ) ;
111
+ log . debug ( 'test' ) ;
112
+ } ) ;
113
+
114
+ stderrSpy . called . should . be . false ;
115
+ stdoutSpy . called . should . be . true ;
116
+ } ) ;
117
+
70
118
it ( 'info - should call console.info' , ( ) => {
71
119
const spy = sinon . spy ( ) ;
72
120
loggerModule . __set__ ( 'console.info' , spy ) ;
@@ -79,6 +127,30 @@ describe('hexo-log', () => {
79
127
spy . called . should . be . true ;
80
128
} ) ;
81
129
130
+ it ( 'info - with stdout and no stderr' , ( ) => {
131
+ const stdoutSpy = sinon . spy ( ) ;
132
+ const stderrSpy = sinon . spy ( ) ;
133
+
134
+ loggerModule . __set__ ( 'console' , fakeConsole ) ;
135
+
136
+ loggerModule . __with__ ( {
137
+ process : {
138
+ stderr : {
139
+ write : stderrSpy
140
+ } ,
141
+ stdout : {
142
+ write : stdoutSpy
143
+ }
144
+ }
145
+ } ) ( ( ) => {
146
+ const log = loggerModule ( { debug : true } ) ;
147
+ log . info ( 'test' ) ;
148
+ } ) ;
149
+
150
+ stderrSpy . called . should . be . false ;
151
+ stdoutSpy . called . should . be . true ;
152
+ } ) ;
153
+
82
154
it ( 'warn - should call console.warn' , ( ) => {
83
155
const spy = sinon . spy ( ) ;
84
156
loggerModule . __set__ ( 'console.warn' , spy ) ;
@@ -91,6 +163,30 @@ describe('hexo-log', () => {
91
163
spy . called . should . be . true ;
92
164
} ) ;
93
165
166
+ it ( 'warn - with stderr and no stdout' , ( ) => {
167
+ const stdoutSpy = sinon . spy ( ) ;
168
+ const stderrSpy = sinon . spy ( ) ;
169
+
170
+ loggerModule . __set__ ( 'console' , fakeConsole ) ;
171
+
172
+ loggerModule . __with__ ( {
173
+ process : {
174
+ stderr : {
175
+ write : stderrSpy
176
+ } ,
177
+ stdout : {
178
+ write : stdoutSpy
179
+ }
180
+ }
181
+ } ) ( ( ) => {
182
+ const log = loggerModule ( { debug : true } ) ;
183
+ log . warn ( 'test' ) ;
184
+ } ) ;
185
+
186
+ stderrSpy . called . should . be . true ;
187
+ stdoutSpy . called . should . be . false ;
188
+ } ) ;
189
+
94
190
it ( 'error - should call console.error' , ( ) => {
95
191
const spy = sinon . spy ( ) ;
96
192
loggerModule . __set__ ( 'console.error' , spy ) ;
@@ -103,6 +199,30 @@ describe('hexo-log', () => {
103
199
spy . called . should . be . true ;
104
200
} ) ;
105
201
202
+ it ( 'error - with stderr and no stdout' , ( ) => {
203
+ const stdoutSpy = sinon . spy ( ) ;
204
+ const stderrSpy = sinon . spy ( ) ;
205
+
206
+ loggerModule . __set__ ( 'console' , fakeConsole ) ;
207
+
208
+ loggerModule . __with__ ( {
209
+ process : {
210
+ stderr : {
211
+ write : stderrSpy
212
+ } ,
213
+ stdout : {
214
+ write : stdoutSpy
215
+ }
216
+ }
217
+ } ) ( ( ) => {
218
+ const log = loggerModule ( { debug : true } ) ;
219
+ log . error ( 'test' ) ;
220
+ } ) ;
221
+
222
+ stderrSpy . called . should . be . true ;
223
+ stdoutSpy . called . should . be . false ;
224
+ } ) ;
225
+
106
226
it ( 'fatal - should call console.error' , ( ) => {
107
227
const spy = sinon . spy ( ) ;
108
228
loggerModule . __set__ ( 'console.error' , spy ) ;
@@ -115,6 +235,30 @@ describe('hexo-log', () => {
115
235
spy . called . should . be . true ;
116
236
} ) ;
117
237
238
+ it ( 'fatal - with stderr and no stdout' , ( ) => {
239
+ const stdoutSpy = sinon . spy ( ) ;
240
+ const stderrSpy = sinon . spy ( ) ;
241
+
242
+ loggerModule . __set__ ( 'console' , fakeConsole ) ;
243
+
244
+ loggerModule . __with__ ( {
245
+ process : {
246
+ stderr : {
247
+ write : stderrSpy
248
+ } ,
249
+ stdout : {
250
+ write : stdoutSpy
251
+ }
252
+ }
253
+ } ) ( ( ) => {
254
+ const log = loggerModule ( { debug : true } ) ;
255
+ log . fatal ( 'test' ) ;
256
+ } ) ;
257
+
258
+ stderrSpy . called . should . be . true ;
259
+ stdoutSpy . called . should . be . false ;
260
+ } ) ;
261
+
118
262
it ( 'options.debug - should display time' , ( ) => {
119
263
const spy = sinon . spy ( ) ;
120
264
const now = new Date ( ) ;
0 commit comments