Skip to content

Commit a32a67e

Browse files
committedApr 26, 2020
test: add stderr & stdout related test cases
1 parent b4ce5e1 commit a32a67e

File tree

1 file changed

+144
-0
lines changed

1 file changed

+144
-0
lines changed
 

‎test/index.js

+144
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,30 @@ describe('hexo-log', () => {
5555
spy.called.should.be.true;
5656
});
5757

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+
5882
it('debug - should call console.debug', () => {
5983
const spy = sinon.spy();
6084
loggerModule.__set__('console.debug', spy);
@@ -67,6 +91,30 @@ describe('hexo-log', () => {
6791
spy.called.should.be.true;
6892
});
6993

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+
70118
it('info - should call console.info', () => {
71119
const spy = sinon.spy();
72120
loggerModule.__set__('console.info', spy);
@@ -79,6 +127,30 @@ describe('hexo-log', () => {
79127
spy.called.should.be.true;
80128
});
81129

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+
82154
it('warn - should call console.warn', () => {
83155
const spy = sinon.spy();
84156
loggerModule.__set__('console.warn', spy);
@@ -91,6 +163,30 @@ describe('hexo-log', () => {
91163
spy.called.should.be.true;
92164
});
93165

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+
94190
it('error - should call console.error', () => {
95191
const spy = sinon.spy();
96192
loggerModule.__set__('console.error', spy);
@@ -103,6 +199,30 @@ describe('hexo-log', () => {
103199
spy.called.should.be.true;
104200
});
105201

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+
106226
it('fatal - should call console.error', () => {
107227
const spy = sinon.spy();
108228
loggerModule.__set__('console.error', spy);
@@ -115,6 +235,30 @@ describe('hexo-log', () => {
115235
spy.called.should.be.true;
116236
});
117237

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+
118262
it('options.debug - should display time', () => {
119263
const spy = sinon.spy();
120264
const now = new Date();

0 commit comments

Comments
 (0)
Please sign in to comment.