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

Function resolveDeps

packages/runner/src/fixture.ts:554–594  ·  view source on GitHub ↗
(
  usedFixtures: TestFixtureItem[],
  registrations: FixtureRegistrations,
  depSet = new Set<TestFixtureItem>(),
  pendingFixtures: TestFixtureItem[] = [],
)

Source from the content-addressed store, hash-verified

552}
553
554function resolveDeps(
555 usedFixtures: TestFixtureItem[],
556 registrations: FixtureRegistrations,
557 depSet = new Set<TestFixtureItem>(),
558 pendingFixtures: TestFixtureItem[] = [],
559) {
560 usedFixtures.forEach((fixture) => {
561 if (pendingFixtures.includes(fixture)) {
562 return
563 }
564 if (!isFixtureFunction(fixture.value) || !fixture.deps) {
565 pendingFixtures.push(fixture)
566 return
567 }
568 if (depSet.has(fixture)) {
569 if (fixture.parent) {
570 fixture = fixture.parent
571 }
572 else {
573 throw new Error(
574 `Circular fixture dependency detected: ${fixture.name} <- ${[...depSet]
575 .reverse()
576 .map(d => d.name)
577 .join(' <- ')}`,
578 )
579 }
580 }
581
582 depSet.add(fixture)
583 resolveDeps(
584 [...fixture.deps].map(n => n === fixture.name ? fixture.parent : registrations.get(n)).filter(n => !!n),
585 registrations,
586 depSet,
587 pendingFixtures,
588 )
589 pendingFixtures.push(fixture)
590 depSet.clear()
591 })
592
593 return pendingFixtures
594}
595
596function validateSuiteHook(fn: Function, hook: SuiteHook, suiteError: Error | undefined) {
597 const usedProps = getUsedProps(fn, { sourceError: suiteError, suiteHook: hook })

Callers 1

withFixturesFunction · 0.85

Calls 6

isFixtureFunctionFunction · 0.85
filterMethod · 0.65
clearMethod · 0.65
hasMethod · 0.45
addMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected