/
testing.mjs
55 lines (47 loc) · 1.72 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
import { startVitest } from 'vitest/node'
// Set this to true when intentionally updating the snapshots
const UPDATE_SNAPSHOTS = false
const provider = process.argv[1 + process.argv.indexOf('--provider')]
const isBrowser = process.argv.includes('--browser')
const configs = [
// Run test cases. Generates coverage report.
['test/', {
include: ['test/*.test.*'],
exclude: [
'coverage-report-tests/**/*',
// TODO: Include once mocking is supported in browser
isBrowser && '**/no-esbuild-transform.test.js',
].filter(Boolean),
coverage: { enabled: true },
browser: { enabled: isBrowser, name: 'chrome', headless: true },
}],
// Run tests for checking coverage report contents.
['coverage-report-tests', {
include: [
['c8', 'istanbul'].includes(provider) && './coverage-report-tests/generic.report.test.ts',
`./coverage-report-tests/${provider}.report.test.ts`,
].filter(Boolean),
coverage: { enabled: false, clean: false },
}],
]
// Prevent the "vitest/src/node/browser/webdriver.ts" from calling process.exit
const exit = process.exit
process.exit = () => !isBrowser && exit()
for (const threads of [{ threads: true }, { threads: false }, { singleThread: true }]) {
for (const isolate of [true, false]) {
for (const [directory, config] of configs) {
await startVitest('test', [directory], {
name: `With settings: ${JSON.stringify({ ...threads, isolate, directory, browser: config.browser?.enabled })}`,
...config,
update: UPDATE_SNAPSHOTS,
...threads,
isolate,
})
if (process.exitCode) {
console.error(`process.exitCode was set to ${process.exitCode}, exiting.`)
exit()
}
}
}
}
exit()