-
-
Notifications
You must be signed in to change notification settings - Fork 1k
/
create.ts
33 lines (27 loc) · 1016 Bytes
/
create.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
import { resolve } from 'pathe'
import { createServer, mergeConfig } from 'vite'
import type { InlineConfig as ViteInlineConfig, UserConfig as ViteUserConfig } from 'vite'
import { findUp } from 'find-up'
import type { UserConfig } from '../types'
import { configFiles } from '../constants'
import { Vitest } from './core'
import { VitestPlugin } from './plugins'
export async function createVitest(options: UserConfig, viteOverrides: ViteUserConfig = {}) {
const ctx = new Vitest()
const root = resolve(options.root || process.cwd())
const configPath = options.config
? resolve(root, options.config)
: await findUp(configFiles, { cwd: root } as any)
const config: ViteInlineConfig = {
root,
logLevel: 'error',
configFile: configPath,
plugins: await VitestPlugin(options, ctx),
}
const server = await createServer(mergeConfig(config, viteOverrides))
if (ctx.config.api?.port)
await server.listen()
else
await server.pluginContainer.buildStart({})
return ctx
}