-
-
Notifications
You must be signed in to change notification settings - Fork 84
/
init.ts
50 lines (49 loc) · 1.33 KB
/
init.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
import type { UserConfig } from 'vitest'
import { VSCodeReporter } from './reporter'
import type { WorkerMeta } from './types'
export async function initVitest(meta: WorkerMeta, options?: UserConfig) {
const vitestModule = await import(meta.vitestNodePath) as typeof import('vitest/node')
const reporter = new VSCodeReporter()
const vitest = await vitestModule.createVitest(
'test',
{
config: meta.configFile,
workspace: meta.workspaceFile,
...meta.arguments ? vitestModule.parseCLI(meta.arguments).options : {},
...options,
watch: true,
api: false,
// @ts-expect-error private property
reporter: undefined,
reporters: [reporter],
ui: false,
includeTaskLocation: true,
},
{
server: {
middlewareMode: true,
},
plugins: [
{
name: 'vitest:vscode-extension',
configResolved(config) {
// stub a server so Vite doesn't start a websocket connection,
// because we don't need it in the extension and it messes up Vite dev command
config.server.hmr = {
server: {
on: () => {},
off: () => {},
} as any,
}
},
},
],
},
)
reporter.init(vitest)
return {
vitest,
reporter,
meta,
}
}