Initial commit
This commit is contained in:
2
packages/core-testing/src/payload/index.ts
Normal file
2
packages/core-testing/src/payload/index.ts
Normal file
@@ -0,0 +1,2 @@
|
||||
export { stubPayloadConfig } from "./stub-config";
|
||||
export { mockPayloadModule } from "./mock-payload-module";
|
||||
27
packages/core-testing/src/payload/mock-payload-module.ts
Normal file
27
packages/core-testing/src/payload/mock-payload-module.ts
Normal file
@@ -0,0 +1,27 @@
|
||||
import type { Payload } from "payload";
|
||||
|
||||
/**
|
||||
* @deprecated DO NOT USE — hoisting incompatible.
|
||||
*
|
||||
* Vitest statically hoists `vi.mock()` calls to the top of the file.
|
||||
* This helper wraps `vi.mock()` inside a regular function body, so the
|
||||
* hoist never fires — the mock is installed too late and the real
|
||||
* `payload` module loads before being intercepted.
|
||||
*
|
||||
* Instead, write at the TOP LEVEL of your test file:
|
||||
*
|
||||
* vi.mock("payload", () => ({ getPayload: vi.fn() }));
|
||||
*
|
||||
* // then in your test:
|
||||
* const { getPayload } = await import("payload");
|
||||
* (getPayload as ReturnType<typeof vi.fn>).mockResolvedValue(yourStub);
|
||||
*
|
||||
* This export is preserved only so existing imports don't break and
|
||||
* agents searching for it find this warning.
|
||||
*/
|
||||
export function mockPayloadModule(impl: Partial<Payload>): void {
|
||||
void impl;
|
||||
throw new Error(
|
||||
"mockPayloadModule is deprecated and broken; see JSDoc. Call vi.mock('payload', ...) at the top of your test file instead.",
|
||||
);
|
||||
}
|
||||
6
packages/core-testing/src/payload/stub-config.ts
Normal file
6
packages/core-testing/src/payload/stub-config.ts
Normal file
@@ -0,0 +1,6 @@
|
||||
import type { SanitizedConfig } from "payload";
|
||||
|
||||
// Minimal SanitizedConfig stub for tests that need to construct repos
|
||||
// without actually loading the real Payload config. Repository tests
|
||||
// that mock the `payload` module never read fields off this object.
|
||||
export const stubPayloadConfig = {} as SanitizedConfig;
|
||||
Reference in New Issue
Block a user