Skip to content

Commit b4ce5e1

Browse files
committedApr 26, 2020
test: bring up examples
1 parent 316aff3 commit b4ce5e1

File tree

1 file changed

+51
-12
lines changed

1 file changed

+51
-12
lines changed
 

‎test/index.js

+51-12
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,9 @@ const fakeProcess = {
2323
}
2424
};
2525

26+
const logger = require('../lib/log');
27+
2628
describe('hexo-log', () => {
27-
const logger = require('../lib/log');
2829
let loggerModule;
2930

3031
beforeEach(() => {
@@ -43,7 +44,7 @@ describe('hexo-log', () => {
4344
});
4445

4546
it('trace - should call console.trace', () => {
46-
const spy = sinon.fake();
47+
const spy = sinon.spy();
4748
loggerModule.__set__('console.trace', spy);
4849

4950
loggerModule.__with__(fakeProcess)(() => {
@@ -55,7 +56,7 @@ describe('hexo-log', () => {
5556
});
5657

5758
it('debug - should call console.debug', () => {
58-
const spy = sinon.fake();
59+
const spy = sinon.spy();
5960
loggerModule.__set__('console.debug', spy);
6061

6162
loggerModule.__with__(fakeProcess)(() => {
@@ -67,7 +68,7 @@ describe('hexo-log', () => {
6768
});
6869

6970
it('info - should call console.info', () => {
70-
const spy = sinon.fake();
71+
const spy = sinon.spy();
7172
loggerModule.__set__('console.info', spy);
7273

7374
loggerModule.__with__(fakeProcess)(() => {
@@ -79,7 +80,7 @@ describe('hexo-log', () => {
7980
});
8081

8182
it('warn - should call console.warn', () => {
82-
const spy = sinon.fake();
83+
const spy = sinon.spy();
8384
loggerModule.__set__('console.warn', spy);
8485

8586
loggerModule.__with__(fakeProcess)(() => {
@@ -91,7 +92,7 @@ describe('hexo-log', () => {
9192
});
9293

9394
it('error - should call console.error', () => {
94-
const spy = sinon.fake();
95+
const spy = sinon.spy();
9596
loggerModule.__set__('console.error', spy);
9697

9798
loggerModule.__with__(fakeProcess)(() => {
@@ -103,7 +104,7 @@ describe('hexo-log', () => {
103104
});
104105

105106
it('fatal - should call console.error', () => {
106-
const spy = sinon.fake();
107+
const spy = sinon.spy();
107108
loggerModule.__set__('console.error', spy);
108109

109110
loggerModule.__with__(fakeProcess)(() => {
@@ -137,11 +138,11 @@ describe('hexo-log', () => {
137138
});
138139

139140
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();
145146

146147
loggerModule.__set__('console.trace', consoleTraceSpy);
147148
loggerModule.__set__('console.debug', consoleDebugSpy);
@@ -166,3 +167,41 @@ describe('hexo-log', () => {
166167
consoleErrorSpy.calledTwice.should.be.true;
167168
});
168169
});
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

Comments
 (0)
Please sign in to comment.