diff --git a/test/vitest/vitest.shared.config.ts b/test/vitest/vitest.shared.config.ts index 50ca3c96e600..1d93b0a0e9cb 100644 --- a/test/vitest/vitest.shared.config.ts +++ b/test/vitest/vitest.shared.config.ts @@ -160,6 +160,21 @@ export const sharedVitestConfig = { envDir: false as const, resolve: { alias: [ + { + // Route bare `zod` through a runtime shim (same pattern as the + // discord-api-types shims below): zod's own entry re-exports `z` as a + // namespace binding, which Bun's linker drops under Vitest's loader + // hooks. The shim exposes the identical surface on Node and Bun. + find: /^zod$/u, + replacement: path.join(repoRoot, "test", "vitest", "zod-runtime.ts"), + }, + { + // Bun substitutes its built-in fetch shim for bare `undici`, whose + // MockAgent is a non-functional stub; pin the real package so + // mock-http interception works. Node resolves to this file anyway. + find: /^undici$/u, + replacement: path.join(repoRoot, "node_modules", "undici", "index.js"), + }, { find: "discord-api-types/v10", replacement: path.join(repoRoot, "test", "vitest", "discord-api-types-v10-runtime.ts"), diff --git a/test/vitest/zod-runtime.ts b/test/vitest/zod-runtime.ts new file mode 100644 index 000000000000..4a354a0f8e5e --- /dev/null +++ b/test/vitest/zod-runtime.ts @@ -0,0 +1,10 @@ +// Test-only zod entry: zod's real index.js re-exports the `z` namespace via +// `import * as z; export { z }`, which Bun's module linker drops when Vitest's +// loader hooks are active (named `z` arrives undefined). Re-exporting through a +// const binding links correctly on both Node and Bun; the exposed surface is +// identical to `zod` (zod/v4 is the same classic API), so Node is unchanged. +import * as zNamespace from "zod/v4"; + +export * from "zod/v4"; +export const z = zNamespace; +export default zNamespace;