/
testing.mjs
63 lines (50 loc) · 1.37 KB
/
testing.mjs
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
import { startVitest } from 'vitest/node'
// Set this to true when intentionally updating the snapshots
const UPDATE_SNAPSHOTS = false
const provider = getArgument('--provider')
const configs = [
// Run test cases. Generates coverage report.
['test/', {
include: ['test/*.test.*'],
exclude: ['coverage-report-tests/**/*'],
}],
// Run tests for checking coverage report contents.
['coverage-report-tests', {
include: [
'./coverage-report-tests/generic.report.test.ts',
`./coverage-report-tests/${provider}.report.test.ts`,
],
coverage: { enabled: false, clean: false },
}],
]
runTests()
async function runTests() {
for (const threads of [true, false]) {
for (const [directory, config] of configs) {
await startVitest('test', [directory], {
run: true,
update: UPDATE_SNAPSHOTS,
...config,
threads,
coverage: {
include: ['src/**'],
provider,
...config.coverage,
},
})
if (process.exitCode)
process.exit()
}
}
process.exit(0)
}
function getArgument(name) {
const args = process.argv
const index = args.indexOf(name)
if (index === -1)
throw new Error(`Missing argument ${name}, received ${args}`)
const value = args[index + 1]
if (!value)
throw new Error(`Missing value of ${name}, received ${args}`)
return value
}