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

Function fixture

packages/runner/src/suite.ts:888–904  ·  view source on GitHub ↗
(ctx: any, use: (value: any) => Promise<void>)

Source from the content-addressed store, hash-verified

886
887 // Wrap builder pattern function (returns value) to use() pattern
888 const fixture = async (ctx: any, use: (value: any) => Promise<void>) => {
889 let cleanup: (() => any) | undefined
890 const onCleanup = (fn: () => any) => {
891 if (cleanup !== undefined) {
892 throw new Error(
893 `onCleanup can only be called once per fixture. `
894 + `Define separate fixtures if you need multiple cleanup functions.`,
895 )
896 }
897 cleanup = fn
898 }
899 const value = await builderFn(ctx, { onCleanup })
900 await use(value)
901 if (cleanup) {
902 await cleanup()
903 }
904 }
905 configureProps(fixture, { original: builderFn })
906
907 if (fixtureOptions) {

Callers

nothing calls this directly

Calls 2

useFunction · 0.70
cleanupFunction · 0.50

Tested by

no test coverage detected