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

Function resolveTestRunner

packages/vitest/src/runtime/runners/index.ts:32–156  ·  view source on GitHub ↗
(
  config: SerializedConfig,
  moduleRunner: TestModuleRunner,
  traces: Traces,
)

Source from the content-addressed store, hash-verified

30}
31
32export async function resolveTestRunner(
33 config: SerializedConfig,
34 moduleRunner: TestModuleRunner,
35 traces: Traces,
36): Promise<VitestRunner> {
37 const TestRunner = await getTestRunnerConstructor(config, moduleRunner)
38 const testRunner = new TestRunner(config)
39
40 // inject private executor to every runner
41 Object.defineProperty(testRunner, 'moduleRunner', {
42 value: moduleRunner,
43 enumerable: false,
44 configurable: false,
45 })
46
47 if (!testRunner.config) {
48 testRunner.config = config
49 }
50
51 if (!testRunner.importFile) {
52 throw new Error('Runner must implement "importFile" method.')
53 }
54
55 if ('__setTraces' in testRunner) {
56 (testRunner.__setTraces as any)(traces)
57 }
58
59 const [diffOptions] = await Promise.all([
60 loadDiffConfig(config, moduleRunner),
61 loadSnapshotSerializers(config, moduleRunner),
62 ])
63 testRunner.config.diffOptions = diffOptions
64
65 // patch some methods, so custom runners don't need to call RPC
66 const originalOnTaskUpdate = testRunner.onTaskUpdate
67 testRunner.onTaskUpdate = async (task, events) => {
68 const p = rpc().onTaskUpdate(task, events)
69 await originalOnTaskUpdate?.call(testRunner, task, events)
70 return p
71 }
72
73 // patch some methods, so custom runners don't need to call RPC
74 const originalOnTestAnnotate = testRunner.onTestAnnotate
75 testRunner.onTestAnnotate = async (test, annotation) => {
76 const p = rpc().onTaskArtifactRecord(test.id, { type: 'internal:annotation', location: annotation.location, annotation })
77 const overriddenResult = await originalOnTestAnnotate?.call(testRunner, test, annotation)
78 const vitestResult = await p
79 return overriddenResult || vitestResult.annotation
80 }
81
82 const originalOnTestArtifactRecord = testRunner.onTestArtifactRecord
83 testRunner.onTestArtifactRecord = async (test, artifact) => {
84 const p = rpc().onTaskArtifactRecord(test.id, artifact)
85 const overriddenResult = await originalOnTestArtifactRecord?.call(testRunner, test, artifact)
86 const vitestResult = await p
87 return overriddenResult as typeof artifact || vitestResult
88 }
89

Callers 2

runFunction · 0.90
runFunction · 0.90

Calls 13

cancelMethod · 0.95
loadDiffConfigFunction · 0.90
loadSnapshotSerializersFunction · 0.90
rpcFunction · 0.90
getWorkerStateFunction · 0.90
takeCoverageInsideWorkerFunction · 0.90
getTestRunnerConstructorFunction · 0.85
allMethod · 0.80
getCountOfFailedTestsMethod · 0.80
onCancelMethod · 0.80
onTaskUpdateMethod · 0.45
onAfterSuiteRunMethod · 0.45

Tested by

no test coverage detected