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

Function collect

packages/vitest/src/node/cli/cac.ts:338–384  ·  view source on GitHub ↗
(mode: VitestRunMode, cliFilters: string[], options: CliOptions)

Source from the content-addressed store, hash-verified

336}
337
338async function collect(mode: VitestRunMode, cliFilters: string[], options: CliOptions): Promise<void> {
339 try {
340 const { prepareVitest, processCollected, outputFileList } = await import('./cli-api')
341 const ctx = await prepareVitest(mode, {
342 ...normalizeCliOptions(cliFilters, options),
343 watch: false,
344 run: true,
345 }, undefined, undefined, cliFilters)
346 if (!options.filesOnly) {
347 const { testModules: tests, unhandledErrors: errors } = await ctx.collect(
348 cliFilters.map(normalize),
349 {
350 staticParse: options.staticParse,
351 staticParseConcurrency: options.staticParseConcurrency,
352 },
353 )
354
355 if (errors.length) {
356 console.error('\nThere were unhandled errors during test collection')
357 errors.forEach(e => console.error(e))
358 console.error('\n\n')
359 await ctx.close()
360 return
361 }
362
363 processCollected(ctx, tests, options)
364 }
365 else {
366 const files = await ctx.getRelevantTestSpecifications(cliFilters.map(normalize))
367 outputFileList(files, options)
368 }
369
370 await ctx.close()
371 }
372 catch (e) {
373 const { errorBanner } = await import('../reporters/renderers/utils')
374 console.error(`\n${errorBanner('Collect Error')}`)
375 console.error(e)
376 console.error('\n\n')
377
378 if (process.exitCode == null) {
379 process.exitCode = 1
380 }
381
382 process.exit()
383 }
384}

Callers 1

createCLIFunction · 0.70

Calls 10

prepareVitestFunction · 0.85
normalizeCliOptionsFunction · 0.85
processCollectedFunction · 0.85
outputFileListFunction · 0.85
errorBannerFunction · 0.85
errorMethod · 0.80
exitMethod · 0.80
collectMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected