UNPKG

histoire

Version:

A fast story book powered by Vite

3 lines • 2.39 kB
/** Story vi facade: module mocks, spies, global stubs, and polling helpers. */ export declare const STORY_MOCKS_CODE = "\nconst compilerHints = createCompilerHints({\n globalThisKey: '__vitest_mocker__',\n})\n\nconst originalGlobals = new Map()\n\n/** Vitest helpers supported in a story iframe. */\nexport const vi = {\n ...compilerHints,\n clearAllMocks,\n fn,\n isMockFunction,\n /** Preserves the runtime value of Vitest's type-only helper. */\n mocked(value) {\n return value\n },\n resetAllMocks,\n restoreAllMocks,\n spyOn,\n /** Evaluates a factory when no mocker transform has already hoisted it. */\n hoisted(factory) {\n return factory()\n },\n /** Replaces a global while retaining its original property descriptor. */\n stubGlobal(name, value) {\n if (!originalGlobals.has(name)) {\n originalGlobals.set(name, Object.getOwnPropertyDescriptor(globalThis, name))\n }\n Object.defineProperty(globalThis, name, { configurable: true, writable: true, value })\n return vi\n },\n /** Restores globals replaced through this facade. */\n unstubAllGlobals() {\n for (const [name, descriptor] of originalGlobals) {\n if (descriptor) {\n Object.defineProperty(globalThis, name, descriptor)\n }\n else {\n delete globalThis[name]\n }\n }\n originalGlobals.clear()\n return vi\n },\n /** Retains compatibility with the immutable Vite browser environment. */\n stubEnv() {\n return vi\n },\n /** Completes the environment-stubbing no-op pair. */\n unstubAllEnvs() {\n return vi\n },\n /** Rejects fake timers, which the embedded runtime does not install. */\n useFakeTimers() {\n return unsupportedRuntimeFeature('vi.useFakeTimers')\n },\n /** Returns the facade because this runtime always uses real timers. */\n useRealTimers() {\n return vi\n },\n /** Rejects clock changes that require fake timers. */\n setSystemTime() {\n return unsupportedRuntimeFeature('vi.setSystemTime')\n },\n /** Rejects advancing an unavailable fake clock. */\n advanceTimersByTime() {\n return unsupportedRuntimeFeature('vi.advanceTimersByTime')\n },\n /** Rejects draining an unavailable fake clock. */\n runAllTimers() {\n return unsupportedRuntimeFeature('vi.runAllTimers')\n },\n waitFor: waitForValue,\n waitUntil: waitUntilValue,\n}\n"; //# sourceMappingURL=mocks.d.ts.map