import type { Payload } from "payload"; /** * Module-level memoized Payload instance for the int suite under Vitest's * `isolate: false` worker pool (stage 3 of the test speedup). A vitest fork * keeps its module registry across test files, so the first spec to call this * pays the full config load + adapter boot and every later file in the same * fork reuses the instance against the fork's dedicated database clone. * * Specs that turn out to leak or depend on module state across files simply * keep (or revert to) their own direct `getPayload({ config })` boot: opting * out is just not importing this helper, which restores a cheap-but-correct * per-file boot. Name any reason in a comment at the opt-out site. */ let instance: Promise | undefined; export function getTestPayload(): Promise { if (!instance) { instance = import("@payload-config") .then((m) => m.default) .then((config) => import("payload").then(({ getPayload }) => getPayload({ config }))); instance.catch(() => { // A failed boot must not poison the worker for all later files. instance = undefined; }); } return instance; }