This repository has been archived by the owner on Apr 6, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
run.ts
69 lines (61 loc) · 1.45 KB
/
run.ts
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
import { resolve } from 'pathe'
import { distDir } from './dirs'
export interface RunTestOptions {
rootDir: string,
dev?: boolean,
watch?: boolean
runner?: 'vitest'
globalSetup?: boolean
}
const RunTestDefaults: Partial<RunTestOptions> = {
runner: 'vitest',
globalSetup: true
}
export async function runTests (opts: RunTestOptions) {
opts = { ...RunTestDefaults, ...opts }
if (opts.runner !== 'vitest') {
throw new Error(`Unsupported runner: ${opts.runner}. Currently only vitest runner is supported.`)
}
if (opts.dev) {
// Set default dev option for @nuxt/test-utils
process.env.NUXT_TEST_DEV = 'true'
}
// Consumed by recoverContextFromEnv()
process.env.NUXT_TEST_OPTIONS = JSON.stringify(opts)
const { startVitest } = await import('vitest/node')
const succeeded = await startVitest(
'test',
[] /* argv */,
// Vitest options
{
root: opts.rootDir,
run: !opts.watch,
deps: {
inline: [/@nuxt\/test-utils/]
}
},
// Vite options
{
esbuild: {
tsconfigRaw: '{}'
},
test: {
dir: opts.rootDir,
deps: {
inline: [
distDir,
'@nuxt/test-utils',
'@nuxt/test-utils-edge'
]
},
globals: true,
globalSetup: [
...opts.globalSetup ? [resolve(distDir, './runtime/global-setup')] : []
]
}
}
)
if (!succeeded) {
process.exit(1)
}
}