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

Function astCollectTests

packages/vitest/src/node/ast-collect.ts:491–513  ·  view source on GitHub ↗
(
  project: TestProject,
  filepath: string,
)

Source from the content-addressed store, hash-verified

489}
490
491export async function astCollectTests(
492 project: TestProject,
493 filepath: string,
494): Promise<File> {
495 const request = await transformSSR(project, filepath)
496 const testFilepath = relative(project.config.root, filepath)
497 if (!request) {
498 debug?.('Cannot parse', testFilepath, '(vite didn\'t return anything)')
499 return createFailedFileTask(
500 project,
501 filepath,
502 new Error(`Failed to parse ${testFilepath}. Vite didn't return anything.`),
503 )
504 }
505 return createFileTask(
506 testFilepath,
507 request.code,
508 request.map,
509 project.serializedConfig,
510 filepath,
511 request.fileTags,
512 )
513}
514
515async function transformSSR(project: TestProject, filepath: string) {
516 // Read original file content to extract pragmas (environment, tags)

Calls 5

transformSSRFunction · 0.85
createFailedFileTaskFunction · 0.85
createFileTaskFunction · 0.70
relativeFunction · 0.50
debugFunction · 0.50

Tested by

no test coverage detected