1
|
|
|
/* eslint-env mocha */ |
2
|
|
|
/* eslint-disable no-unused-expressions */ |
3
|
|
|
|
4
|
|
|
var Sinon = require('sinon') |
5
|
|
|
var Chai = require('chai') |
6
|
|
|
var expect = Chai.expect |
7
|
|
|
|
8
|
|
|
var Logger = require('../../../../lib/Stub/Logger').Logger |
9
|
|
|
|
10
|
|
|
describe('Acceptance', function () { |
11
|
|
|
describe('/Stub', function () { |
12
|
|
|
describe('/Logger.js', function () { |
13
|
|
|
describe('.Logger', function () { |
14
|
|
|
var instance |
15
|
|
|
var allure |
16
|
|
|
|
17
|
|
|
beforeEach(function () { |
18
|
|
|
allure = global.allure |
19
|
|
|
global.allure = { |
20
|
|
|
createAttachment: Sinon.stub() |
21
|
|
|
} |
22
|
|
|
instance = new Logger() |
23
|
|
|
}) |
24
|
|
|
|
25
|
|
|
afterEach(function () { |
26
|
|
|
global.allure = allure |
27
|
|
|
}) |
28
|
|
|
|
29
|
|
|
describe('#write()', function () { |
30
|
|
|
it('writes every message into `._state`', function () { |
31
|
|
|
expect(instance._state.messages).to.be.empty |
32
|
|
|
var message = 'wow' |
33
|
|
|
instance.write(message) |
34
|
|
|
expect(instance._state.messages[0].message).to.eq(message) |
35
|
|
|
}) |
36
|
|
|
}) |
37
|
|
|
|
38
|
|
|
describe('#_flush()', function () { |
39
|
|
|
it('saves everything as allure attachment', function () { |
40
|
|
|
var filename = 'voxengine.json' |
41
|
|
|
var type = 'application/json' |
42
|
|
|
var options = {filename: filename, mimeType: type} |
43
|
|
|
var msg = 'wow' |
44
|
|
|
instance = new Logger({allure: options}) |
45
|
|
|
instance.write(msg) |
46
|
|
|
instance._flush() |
47
|
|
|
var handler = global.allure.createAttachment |
48
|
|
|
expect(handler.callCount).to.eq(1) |
49
|
|
|
expect(handler.getCall(0).args[0]).to.eq(filename) |
50
|
|
|
expect(handler.getCall(0).args[1]).to.contain(msg) |
51
|
|
|
expect(handler.getCall(0).args[2]).to.eq(type) |
52
|
|
|
}) |
53
|
|
|
|
54
|
|
|
it('doesn\'t save allure attachment if it is disabled', function () { |
55
|
|
|
instance = new Logger({allure: {enabled: false}}) |
56
|
|
|
instance.write('wow') |
57
|
|
|
instance._flush() |
58
|
|
|
expect(global.allure.createAttachment.callCount).to.eq(0) |
59
|
|
|
}) |
60
|
|
|
|
61
|
|
|
it('doesn\'t save allure attachment if it is missing', function () { |
62
|
|
|
global.allure = null |
63
|
|
|
instance.write('wow') |
64
|
|
|
expect(instance._flush).not.to.throw() |
65
|
|
|
}) |
66
|
|
|
}) |
67
|
|
|
}) |
68
|
|
|
}) |
69
|
|
|
}) |
70
|
|
|
}) |
71
|
|
|
|