test(vitest): route zod and undici through Bun-safe test resolutions (#114520)

This commit is contained in:
Peter Steinberger
2026-07-27 06:54:45 -04:00
committed by GitHub
parent dd472deab4
commit 0f879595d4
2 changed files with 25 additions and 0 deletions

View File

@@ -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"),

View File

@@ -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;