-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
67 lines (50 loc) · 1.59 KB
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
'use strict';
const sinon = require('sinon');
const expect = require('chai').expect;
const logger = require('./logger');
describe('Logger', () => {
// FIXME: Quick tests to provide minimum coverage. Improve.
let cxtLogger;
before(() => {
logger.format = function(context, level, line) {
const now = 'x';
const service = 'y';
const host = 'z';
return `${now} ${service} ${host} ${level} ${context} ${line}`;
};
cxtLogger = logger.for('cxt');
});
beforeEach(() => {
logger.write = sinon.spy();
logger.writeError = sinon.spy();
});
['info', 'warn', 'debug'].forEach((level) => {
describe('.' + level, () => {
it('should write the message in stdout', function() {
const spy = logger.write;
cxtLogger[level]('test');
expect(spy.callCount).to.equal(1);
const param = spy.getCall(0).args[0];
expect(param).to.equal('x y z ' + level.toUpperCase() + ' cxt test');
});
});
});
describe('.error', () => {
it('should write the message in stderr', function() {
const spy = logger.writeError;
cxtLogger.error('test');
expect(spy.callCount).to.equal(1);
const param = spy.getCall(0).args[0];
expect(param).to.equal('x y z ERROR cxt test');
});
});
describe('.fatal', () => {
it('should write the message in stderr', function() {
const spy = logger.writeError;
cxtLogger.fatal('test');
expect(spy.callCount).to.equal(1);
const param = spy.getCall(0).args[0];
expect(param).to.equal('x y z FATAL cxt test');
});
});
});