forked from mcollina/borp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcoverage.test.js
More file actions
108 lines (96 loc) · 3.01 KB
/
coverage.test.js
File metadata and controls
108 lines (96 loc) · 3.01 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
import { test } from 'node:test'
import { match, doesNotMatch, fail, equal, AssertionError } from 'node:assert'
import { execa } from 'execa'
import { join } from 'desm'
import { mkdtemp, rm, cp, access } from 'node:fs/promises'
import path from 'node:path'
delete process.env.GITHUB_ACTION
const borp = join(import.meta.url, '..', 'borp.js')
test('coverage', async () => {
const res = await execa('node', [
borp,
'--coverage'
], {
cwd: join(import.meta.url, '..', 'fixtures', 'ts-esm')
})
match(res.stdout, /% Stmts/)
match(res.stdout, /All files/)
match(res.stdout, /add\.ts/)
})
test('coverage supports html reporter', async () => {
const repoRoot = path.dirname(borp)
const tmpDir = await mkdtemp(path.join(repoRoot, '.test-coverage-html-'))
const fixtureDir = join(import.meta.url, '..', 'fixtures', 'ts-esm')
const cwd = path.join(tmpDir, 'project')
try {
await cp(fixtureDir, cwd, { recursive: true })
const res = await execa('node', [
borp,
'--coverage',
'--coverage-html'
], {
cwd
})
match(res.stdout, /% Stmts/)
await access(path.join(cwd, 'coverage', 'index.html'))
} finally {
await rm(tmpDir, { recursive: true, force: true })
}
})
test('coverage excludes', async () => {
const res = await execa('node', [
borp,
'-C',
'--coverage-exclude=src'
], {
cwd: join(import.meta.url, '..', 'fixtures', 'ts-esm')
})
match(res.stdout, /% Stmts/)
match(res.stdout, /All files/)
doesNotMatch(res.stdout, /add\.ts/)
// The test files are shown
match(res.stdout, /add\.test\.ts/)
match(res.stdout, /add2\.test\.ts/)
})
test('borp should return right error when check coverage is active with default thresholds', async (t) => {
try {
await execa('node', [
borp,
'--coverage',
'--check-coverage'
], {
cwd: join(import.meta.url, '..', 'fixtures', 'ts-esm-check-coverage')
})
fail('Should not complete borp without error')
} catch (e) {
if (e instanceof AssertionError) {
throw e
}
equal(e.exitCode, 1)
match(e.stderr, /ERROR: Coverage for lines \(\d+(?:.\d+)?%\) does not meet global threshold \(100%\)/)
match(e.stderr, /ERROR: Coverage for functions \(\d+(?:.\d+)?%\) does not meet global threshold \(100%\)/)
match(e.stderr, /ERROR: Coverage for statements \(\d+(?:.\d+)?%\) does not meet global threshold \(100%\)/)
}
})
test('borp should return right error when check coverage is active with defined thresholds', async (t) => {
try {
await execa('node', [
borp,
'--coverage',
'--check-coverage',
'--lines=80',
'--functions=50',
'--statements=0',
'--branches=100'
], {
cwd: join(import.meta.url, '..', 'fixtures', 'ts-esm-check-coverage')
})
fail('Should not complete borp without error')
} catch (e) {
if (e instanceof AssertionError) {
throw e
}
equal(e.exitCode, 1)
match(e.stderr, /ERROR: Coverage for lines \(\d+(?:.\d+)?%\) does not meet global threshold \(80%\)/)
}
})