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

Function collectTests

packages/ui/client/composables/explorer/collector.ts:394–439  ·  view source on GitHub ↗
(file: File, search: SearchMatcher = () => true, filter?: Filter)

Source from the content-addressed store, hash-verified

392}
393
394function collectTests(file: File, search: SearchMatcher = () => true, filter?: Filter) {
395 const data = {
396 failed: 0,
397 success: 0,
398 skipped: 0,
399 running: 0,
400 total: 0,
401 ignored: 0,
402 todo: 0,
403 expectedFail: 0,
404 slow: 0,
405 } satisfies CollectFilteredTests
406
407 for (const t of testsCollector(file)) {
408 if (!filter || testMatcher(t, search, filter)) {
409 data.total++
410 if (isSlowTestTask(t)) {
411 data.slow++
412 }
413 if (t.result?.state === 'fail') {
414 data.failed++
415 }
416 else if (t.result?.state === 'pass') {
417 // Check if this is an expected failure
418 if (t.fails) {
419 data.expectedFail++
420 }
421 else {
422 data.success++
423 }
424 }
425 else if (t.mode === 'skip') {
426 data.ignored++
427 data.skipped++
428 }
429 else if (t.mode === 'todo') {
430 data.ignored++
431 data.todo++
432 }
433 }
434 }
435
436 data.running = data.total - data.failed - data.success - data.ignored - data.expectedFail
437
438 return data
439}
440
441export function collectTestsTotalData(
442 filtered: boolean,

Callers 2

collectDataFunction · 0.70
collectTestsTotalDataFunction · 0.70

Calls 3

testMatcherFunction · 0.90
isSlowTestTaskFunction · 0.90
testsCollectorFunction · 0.85

Tested by

no test coverage detected