-
Notifications
You must be signed in to change notification settings - Fork 406
Expand file tree
/
Copy pathcoverage-writer.spec.js
More file actions
119 lines (95 loc) · 2.76 KB
/
Copy pathcoverage-writer.spec.js
File metadata and controls
119 lines (95 loc) · 2.76 KB
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
'use strict'
const { describe, it, beforeEach } = require('mocha')
const sinon = require('sinon')
const proxyquire = require('proxyquire')
require('../../../../../dd-trace/test/setup/core')
const id = require('../../../../src/id')
let CoverageWriter
let coverageWriter
let request
let encoder
let url
let log
describe('CI Visibility Coverage Writer', () => {
beforeEach(() => {
request = sinon.stub().yieldsAsync(null, 'OK', 200)
encoder = {
encode: sinon.stub(),
count: sinon.stub().returns(0),
makePayload: sinon.stub().returns({
getHeaders: () => ({}),
pipe: () => {},
size: () => 1
})
}
url = {
protocol: 'https:',
hostname: 'citestcov-intake.datadog.com'
}
log = {
error: sinon.spy()
}
const CoverageCIVisibilityEncoder = function () {
return encoder
}
CoverageWriter = proxyquire('../../../../src/ci-visibility/exporters/agentless/coverage-writer.js', {
'../../../exporters/common/request': request,
'../../../encode/coverage-ci-visibility': { CoverageCIVisibilityEncoder },
'../../../log': log
})
coverageWriter = new CoverageWriter({ url })
})
describe('append', () => {
it('should encode a coverage payload', () => {
const input = { sessionId: id('1'), suiteId: id('2'), files: ['file.js'] }
coverageWriter.append(input)
sinon.assert.calledWith(encoder.encode, input)
})
})
describe('flush', () => {
it('should skip flushing if empty', () => {
coverageWriter.flush()
sinon.assert.notCalled(encoder.makePayload)
})
it('should empty the internal queue', () => {
encoder.count.returns(1)
coverageWriter.flush()
sinon.assert.called(encoder.makePayload)
})
it('should call callback when empty', (done) => {
coverageWriter.flush(done)
})
it('should flush its traces to the intake and call done', (done) => {
encoder.count.returns(2)
const payload = {
getHeaders: () => ({}),
pipe: () => {},
size: () => 1
}
encoder.makePayload.returns(payload)
coverageWriter.flush(() => {
sinon.assert.calledWithMatch(request, payload, {
url,
path: '/api/v2/citestcov',
method: 'POST'
})
done()
})
})
it('should log request errors', done => {
const error = new Error('boom')
request.yields(error)
const payload = {
getHeaders: () => ({}),
pipe: () => {},
size: () => 1
}
encoder.count.returns(1)
encoder.makePayload.returns(payload)
coverageWriter.flush(() => {
sinon.assert.calledWith(log.error, 'Error sending CI coverage payload', error)
done()
})
})
})
})