/
entry.ts
58 lines (43 loc) · 2.16 KB
/
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
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
import { performance } from 'node:perf_hooks'
import { startTests } from '@vitest/runner'
import type { ResolvedConfig, ResolvedTestEnvironment } from '../types'
import { getWorkerState, resetModules } from '../utils'
import { vi } from '../integrations/vi'
import { startCoverageInsideWorker, stopCoverageInsideWorker } from '../integrations/coverage'
import { setupChaiConfig } from '../integrations/chai/config'
import { setupGlobalEnv, withEnv } from './setup.node'
import type { VitestExecutor } from './execute'
import { resolveTestRunner } from './runners'
// browser shouldn't call this!
export async function run(files: string[], config: ResolvedConfig, environment: ResolvedTestEnvironment, executor: VitestExecutor): Promise<void> {
const workerState = getWorkerState()
await setupGlobalEnv(config, environment)
await startCoverageInsideWorker(config.coverage, executor)
if (config.chaiConfig)
setupChaiConfig(config.chaiConfig)
const runner = await resolveTestRunner(config, executor)
workerState.onCancel.then(reason => runner.onCancel?.(reason))
workerState.durations.prepare = performance.now() - workerState.durations.prepare
workerState.environment = environment.environment
workerState.durations.environment = performance.now()
await withEnv(environment, environment.options || config.environmentOptions || {}, async () => {
workerState.durations.environment = performance.now() - workerState.durations.environment
for (const file of files) {
// it doesn't matter if running with --threads
// if running with --no-threads, we usually want to reset everything before running a test
// but we have --isolate option to disable this
if (config.isolate) {
workerState.mockMap.clear()
resetModules(workerState.moduleCache, true)
}
workerState.filepath = file
await startTests([file], runner)
// reset after tests, because user might call `vi.setConfig` in setupFile
vi.resetConfig()
// mocks should not affect different files
vi.restoreAllMocks()
}
await stopCoverageInsideWorker(config.coverage, executor)
})
workerState.environmentTeardownRun = true
}