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

Function collectTests

packages/runner/src/collect.ts:23–148  ·  view source on GitHub ↗
(
  specs: string[] | FileSpecification[],
  runner: VitestRunner,
)

Source from the content-addressed store, hash-verified

21const now = globalThis.performance ? globalThis.performance.now.bind(globalThis.performance) : Date.now
22
23export async function collectTests(
24 specs: string[] | FileSpecification[],
25 runner: VitestRunner,
26): Promise<File[]> {
27 const files: File[] = []
28
29 const config = runner.config
30 const $ = runner.trace!
31 let defaultTagsFilter: ((testTags: string[]) => boolean) | undefined
32
33 for (const spec of specs) {
34 const filepath = typeof spec === 'string' ? spec : spec.filepath
35 await $(
36 'collect_spec',
37 { 'code.file.path': filepath },
38 async () => {
39 runner._currentSpecification = typeof spec === 'string' ? { filepath: spec } : spec
40
41 const testLocations = typeof spec === 'string' ? undefined : spec.testLocations
42 const testNamePattern = typeof spec === 'string' ? undefined : spec.testNamePattern
43 const testIds = typeof spec === 'string' ? undefined : spec.testIds
44 const testTagsFilter = typeof spec === 'object' && spec.testTagsFilter
45 ? createTagsFilter(spec.testTagsFilter, config.tags)
46 : undefined
47
48 const fileTags: string[] = typeof spec === 'string' ? [] : (spec.fileTags || [])
49
50 const file = createFileTask(filepath, config.root, config.name, runner.pool, runner.viteEnvironment)
51 file.tags = fileTags
52 file.shuffle = config.sequence.shuffle
53
54 try {
55 validateTags(runner.config, fileTags)
56
57 runner.onCollectStart?.(file)
58
59 clearCollectorContext(file, runner)
60
61 const setupFiles = toArray(config.setupFiles)
62 if (setupFiles.length) {
63 const setupStart = now()
64 await runSetupFiles(config, setupFiles, runner)
65 const setupEnd = now()
66 file.setupDuration = setupEnd - setupStart
67 }
68 else {
69 file.setupDuration = 0
70 }
71
72 const collectStart = now()
73
74 await runner.importFile(filepath, 'collect')
75
76 const durations = runner.getImportDurations?.()
77 if (durations) {
78 file.importDurations = durations
79 }
80

Callers 5

startTestsFunction · 0.90
publicCollectFunction · 0.90
runFunction · 0.90
runFunction · 0.90
executeTestsFunction · 0.50

Calls 15

createTagsFilterFunction · 0.90
createFileTaskFunction · 0.90
validateTagsFunction · 0.90
clearCollectorContextFunction · 0.90
toArrayFunction · 0.90
runSetupFilesFunction · 0.90
getDefaultSuiteFunction · 0.90
createSuiteHooksFunction · 0.90
getHooksFunction · 0.90
setHooksFunction · 0.90
processErrorFunction · 0.90
calculateSuiteHashFunction · 0.90

Tested by

no test coverage detected