Completed
Push — dev ( 6ada4c...6e0845 )
by Fike
31s
created

test/suite/acceptance/Stub/Logger.spec.js   A

Complexity

Total Complexity 14
Complexity/F 1.17

Size

Lines of Code 67
Function Count 12

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 0
c 1
b 0
f 0
nc 1
dl 0
loc 67
rs 10
wmc 14
mnd 0
bc 12
fnc 12
bpm 1
cpm 1.1666
noi 1
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