-
Notifications
You must be signed in to change notification settings - Fork 6
/
log.js
83 lines (67 loc) · 1.8 KB
/
log.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
const assert = require('assert');
const MESSAGE = Symbol.for('message');
module.exports = function (options) {
options = options || {};
var Transport = options.Transport;
var name = Transport.name || options.name;
var construct = options.construct;
var instance;
beforeEach(function () {
var create = typeof construct === 'function'
? construct()
: construct;
instance = new Transport(create);
});
// TODO How to assert that error event is thrown? How to make a transport fail?
describe('.log()', function () {
it('should be present', function () {
assert.ok(instance.log);
assert.equal('function', typeof instance.log);
});
it('(with no callback) should return true', function () {
var info = {
level: 'debug',
message: 'foo'
};
info[MESSAGE] = JSON.stringify(info);
var result = instance.log(info);
assert(true, result);
});
it('(with callback) should return true', function (done) {
var info = {
level: 'debug',
message: 'foo'
};
info[MESSAGE] = JSON.stringify(info);
var result = instance.log(info, function () {
assert(true, result);
done();
});
});
});
describe('events', function () {
it('should emit the "logged" event', function (done) {
instance.once('logged', function (info) {
done()
});
var info = {
level: 'debug',
message: 'foo'
};
info[MESSAGE] = JSON.stringify(info);
instance.log(info);
});
});
afterEach(function (done) {
if (options.afterEach) {
return options.afterEach(options, done);
}
done();
});
after(function (done) {
if (options.afterEach) {
return options.afterEach(options, done);
}
done();
});
};