forked from vitest-dev/vitest
-
Notifications
You must be signed in to change notification settings - Fork 0
/
entry.ts
28 lines (21 loc) · 951 Bytes
/
entry.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
import { promises as fs } from 'fs'
import type { BuiltinEnvironment, ResolvedConfig } from '../types'
import { setupGlobalEnv, withEnv } from './setup'
import { startTests } from './run'
export async function run(files: string[], config: ResolvedConfig): Promise<void> {
await setupGlobalEnv(config)
for (const file of files) {
const code = await fs.readFile(file, 'utf-8')
const env = code.match(/@(?:vitest|jest)-environment\s+?([\w-]+)\b/)?.[1] || config.environment || 'node'
if (!['node', 'jsdom', 'happy-dom'].includes(env))
throw new Error(`Unsupported environment: ${env}`)
__vitest_worker__.filepath = file
await withEnv(env as BuiltinEnvironment, config.environmentOptions || {}, async() => {
const cacheProcess = process
await startTests([file], config)
// eslint-disable-next-line no-global-assign
process = cacheProcess
})
__vitest_worker__.filepath = undefined
}
}