| 1 |
const assert = require('assert'); |
| 2 |
const MESSAGE = Symbol.for('message'); |
| 3 |
|
| 4 |
module.exports = function (options) { |
| 5 |
options = options || {}; |
| 6 |
|
| 7 |
var Transport = options.Transport; |
| 8 |
var name = Transport.name || options.name; |
| 9 |
var construct = options.construct; |
| 10 |
var instance; |
| 11 |
|
| 12 |
beforeEach(function () { |
| 13 |
var create = typeof construct === 'function' |
| 14 |
? construct() |
| 15 |
: construct; |
| 16 |
|
| 17 |
instance = new Transport(create); |
| 18 |
}); |
| 19 |
|
| 20 |
// TODO How to assert that error event is thrown? How to make a transport fail? |
| 21 |
describe('.log()', function () { |
| 22 |
it('should be present', function () { |
| 23 |
assert.ok(instance.log); |
| 24 |
assert.equal('function', typeof instance.log); |
| 25 |
}); |
| 26 |
|
| 27 |
it('(with no callback) should return true', function () { |
| 28 |
var info = { |
| 29 |
level: 'debug', |
| 30 |
message: 'foo' |
| 31 |
}; |
| 32 |
|
| 33 |
info[MESSAGE] = JSON.stringify(info); |
| 34 |
var result = instance.log(info); |
| 35 |
assert(true, result); |
| 36 |
}); |
| 37 |
|
| 38 |
it('(with callback) should return true', function (done) { |
| 39 |
var info = { |
| 40 |
level: 'debug', |
| 41 |
message: 'foo' |
| 42 |
}; |
| 43 |
|
| 44 |
info[MESSAGE] = JSON.stringify(info); |
| 45 |
var result = instance.log(info, function () { |
| 46 |
assert(true, result); |
| 47 |
done(); |
| 48 |
}); |
| 49 |
}); |
| 50 |
}); |
| 51 |
|
| 52 |
describe('events', function () { |
| 53 |
it('should emit the "logged" event', function (done) { |
| 54 |
instance.once('logged', function (info) { |
| 55 |
done() |
| 56 |
}); |
| 57 |
|
| 58 |
var info = { |
| 59 |
level: 'debug', |
| 60 |
message: 'foo' |
| 61 |
}; |
| 62 |
|
| 63 |
info[MESSAGE] = JSON.stringify(info); |
| 64 |
instance.log(info); |
| 65 |
}); |
| 66 |
}); |
| 67 |
|
| 68 |
afterEach(function (done) { |
| 69 |
if (options.afterEach) { |
| 70 |
return options.afterEach(options, done); |
| 71 |
} |
| 72 |
|
| 73 |
done(); |
| 74 |
}); |
| 75 |
|
| 76 |
after(function (done) { |
| 77 |
if (options.afterEach) { |
| 78 |
return options.afterEach(options, done); |
| 79 |
} |
| 80 |
|
| 81 |
done(); |
| 82 |
}); |
| 83 |
}; |