( specs: string[] | FileSpecification[], runner: VitestRunner, )
| 21 | const now = globalThis.performance ? globalThis.performance.now.bind(globalThis.performance) : Date.now |
| 22 | |
| 23 | export 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 |
no test coverage detected