MCPcopy
hub / github.com/vitest-dev/vitest / run

Function run

packages/vitest/src/runtime/runBaseTests.ts:21–92  ·  view source on GitHub ↗
(
  method: 'run' | 'collect',
  files: FileSpecification[],
  config: SerializedConfig,
  moduleRunner: TestModuleRunner,
  environment: Environment,
  traces: Traces,
)

Source from the content-addressed store, hash-verified

19
20// browser shouldn't call this!
21export async function run(
22 method: 'run' | 'collect',
23 files: FileSpecification[],
24 config: SerializedConfig,
25 moduleRunner: TestModuleRunner,
26 environment: Environment,
27 traces: Traces,
28): Promise<void> {
29 const workerState = getWorkerState()
30
31 const [testRunner] = await Promise.all([
32 traces.$('vitest.runtime.runner', () => resolveTestRunner(config, moduleRunner, traces)),
33 traces.$('vitest.runtime.global_env', () => setupGlobalEnv(config, environment)),
34 traces.$('vitest.runtime.coverage.start', () => startCoverageInsideWorker(config.coverage, moduleRunner, { isolate: config.isolate })),
35 traces.$('vitest.runtime.snapshot.environment', async () => {
36 if (!workerState.config.snapshotOptions.snapshotEnvironment) {
37 workerState.config.snapshotOptions.snapshotEnvironment
38 = await resolveSnapshotEnvironment(config, moduleRunner)
39 }
40 }),
41 ])
42
43 workerState.onCancel((reason) => {
44 closeInspector(config)
45 testRunner.cancel?.(reason)
46 })
47
48 workerState.durations.prepare = performance.now() - workerState.durations.prepare
49 await traces.$(
50 `vitest.test.runner.${method}`,
51 async () => {
52 for (const file of files) {
53 if (config.isolate) {
54 moduleRunner.mocker?.reset()
55 resetModules(workerState.evaluatedModules, true)
56 }
57
58 workerState.filepath = file.filepath
59
60 if (method === 'run') {
61 const collectAsyncLeaks = config.detectAsyncLeaks ? detectAsyncLeaks(file.filepath, workerState.ctx.projectName) : undefined
62
63 await traces.$(
64 `vitest.test.runner.${method}.module`,
65 { attributes: { 'code.file.path': file.filepath } },
66 () => startTests([file], testRunner),
67 )
68
69 const leaks = await collectAsyncLeaks?.()
70
71 if (leaks?.length) {
72 workerState.rpc.onAsyncLeaks(leaks)
73 }
74 }
75 else {
76 await traces.$(
77 `vitest.test.runner.${method}.module`,
78 { attributes: { 'code.file.path': file.filepath } },

Callers 1

runBaseTestsFunction · 0.90

Calls 15

getWorkerStateFunction · 0.90
resolveTestRunnerFunction · 0.90
setupGlobalEnvFunction · 0.90
closeInspectorFunction · 0.90
resetModulesFunction · 0.90
detectAsyncLeaksFunction · 0.90
startTestsFunction · 0.90
collectTestsFunction · 0.90
stopCoverageInsideWorkerFunction · 0.90
allMethod · 0.80

Tested by

no test coverage detected