-
Notifications
You must be signed in to change notification settings - Fork 88
/
integration.js
174 lines (159 loc) · 4.74 KB
/
integration.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
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
/* global describe, before, beforeEach, it */
const { spawnSync } = require('child_process')
const c8Path = require.resolve('../bin/c8')
const nodePath = process.execPath
const chaiJestSnapshot = require('chai-jest-snapshot')
const rimraf = require('rimraf')
require('chai')
.use(chaiJestSnapshot)
.should()
before(cb => rimraf('tmp', cb))
beforeEach(function () { chaiJestSnapshot.configureUsingMochaContext(this) })
describe('c8', () => {
it('reports coverage for script that exits normally', () => {
const { output } = spawnSync(nodePath, [
c8Path,
'--exclude="test/*.js"',
'--temp-directory=tmp/normal',
'--clean=false',
nodePath,
require.resolve('./fixtures/normal')
])
output.toString('utf8').should.matchSnapshot()
})
it('merges reports from subprocesses together', () => {
const { output } = spawnSync(nodePath, [
c8Path,
'--exclude="test/*.js"',
'--temp-directory=tmp/multiple-spawn',
'--clean=false',
nodePath,
require.resolve('./fixtures/multiple-spawn')
])
output.toString('utf8').should.matchSnapshot()
})
it('allows relative files to be included', () => {
const { output } = spawnSync(nodePath, [
c8Path,
'--exclude="test/*.js"',
'--temp-directory=tmp/multiple-spawn-2',
'--omit-relative=false',
'--clean=false',
nodePath,
require.resolve('./fixtures/multiple-spawn')
])
output.toString('utf8').should.match(
/Error: ENOENT: no such file or directory.*loaders\.js/
)
})
describe('check-coverage', () => {
before(() => {
spawnSync(nodePath, [
c8Path,
'--exclude="test/*.js"',
'--temp-directory=tmp/check-coverage',
'--clean=false',
nodePath,
require.resolve('./fixtures/normal')
])
})
it('exits with 0 if coverage within threshold', () => {
const { output, status } = spawnSync(nodePath, [
c8Path,
'check-coverage',
'--exclude="test/*.js"',
'--temp-directory=tmp/check-coverage',
'--lines=80'
])
status.should.equal(0)
output.toString('utf8').should.matchSnapshot()
})
it('exits with 1 if coverage is below threshold', () => {
const { output, status } = spawnSync(nodePath, [
c8Path,
'check-coverage',
'--exclude="test/*.js"',
'--temp-directory=tmp/check-coverage',
'--lines=101'
])
status.should.equal(1)
output.toString('utf8').should.matchSnapshot()
})
it('allows threshold to be applied on per-file basis', () => {
const { output, status } = spawnSync(nodePath, [
c8Path,
'check-coverage',
'--exclude="test/*.js"',
'--temp-directory=tmp/check-coverage',
'--lines=101',
'--per-file'
])
status.should.equal(1)
output.toString('utf8').should.matchSnapshot()
})
it('allows --check-coverage when executing script', () => {
const { output, status } = spawnSync(nodePath, [
c8Path,
'--exclude="test/*.js"',
'--clean=false',
'--temp-directory=tmp/check-coverage',
'--lines=101',
'--check-coverage',
nodePath,
require.resolve('./fixtures/normal')
])
status.should.equal(1)
output.toString('utf8').should.matchSnapshot()
})
})
describe('report', () => {
before(() => {
spawnSync(nodePath, [
c8Path,
'--exclude="test/*.js"',
'--temp-directory=tmp/report',
'--clean=false',
nodePath,
require.resolve('./fixtures/normal')
])
})
it('generates report from existing temporary files', () => {
const { output } = spawnSync(nodePath, [
c8Path,
'report',
'--exclude="test/*.js"',
'--temp-directory=tmp/report',
'--clean=false'
])
output.toString('utf8').should.matchSnapshot()
})
it('supports --check-coverage, when generating reports', () => {
const { output, status } = spawnSync(nodePath, [
c8Path,
'report',
'--check-coverage',
'--lines=101',
'--exclude="test/*.js"',
'--temp-directory=tmp/report',
'--clean=false'
])
status.should.equal(1)
output.toString('utf8').should.matchSnapshot()
})
})
describe('ESM Modules', () => {
it('collects coverage for ESM modules', () => {
const { output } = spawnSync(nodePath, [
c8Path,
'--exclude="test/*.js"',
'--clean=false',
'--temp-directory=tmp/esm',
nodePath,
'--experimental-modules',
'--no-warnings',
require.resolve('./fixtures/import.mjs')
])
output.toString('utf8').should.matchSnapshot()
})
})
})