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

Function initiateRunner

packages/browser/src/client/tester/runner.ts:327–368  ·  view source on GitHub ↗
(
  state: WorkerGlobalState,
  mocker: VitestBrowserClientMocker,
  config: SerializedConfig,
)

Source from the content-addressed store, hash-verified

325}
326
327export async function initiateRunner(
328 state: WorkerGlobalState,
329 mocker: VitestBrowserClientMocker,
330 config: SerializedConfig,
331): Promise<BrowserVitestRunner> {
332 if (cachedRunner) {
333 return cachedRunner
334 }
335 const runnerClass
336 = config.mode === 'test' ? TestRunner : BenchmarkRunner
337
338 const BrowserRunner = createBrowserRunner(runnerClass, mocker, state, {
339 takeCoverage: () =>
340 takeCoverageInsideWorker(config.coverage, moduleRunner),
341 })
342 if (!config.snapshotOptions.snapshotEnvironment) {
343 config.snapshotOptions.snapshotEnvironment = new VitestBrowserSnapshotEnvironment()
344 }
345 const runner = new BrowserRunner({
346 config,
347 })
348 cachedRunner = runner
349
350 onCancel((reason) => {
351 runner.cancel?.(reason)
352 })
353
354 const [diffOptions] = await Promise.all([
355 loadDiffConfig(config, moduleRunner as any),
356 loadSnapshotSerializers(config, moduleRunner as any),
357 ])
358 runner.config.diffOptions = diffOptions
359 getWorkerState().onFilterStackTrace = (stack: string) => {
360 const stacks = parseStacktrace(stack, {
361 getSourceMap(file) {
362 return runner.sourceMapCache.get(file)
363 },
364 })
365 return createStackString(stacks)
366 }
367 return runner
368}
369
370async function getTraceMap(file: string, sourceMaps: Map<string, any>) {
371 const result = sourceMaps.get(file) || await rpc().getBrowserFileSourceMap(file).then((map) => {

Callers 1

prepareTestEnvironmentFunction · 0.90

Calls 10

onCancelFunction · 0.90
getWorkerStateFunction · 0.90
parseStacktraceFunction · 0.90
createStackStringFunction · 0.90
createBrowserRunnerFunction · 0.85
takeCoverageInsideWorkerFunction · 0.85
loadDiffConfigFunction · 0.85
loadSnapshotSerializersFunction · 0.85
allMethod · 0.80
cancelMethod · 0.45

Tested by

no test coverage detected