From 752eb5ecb7520e06489f35288fd81b404be1b3a7 Mon Sep 17 00:00:00 2001 From: Khalim Conn-Kowlessar Date: Mon, 20 Jul 2026 14:28:11 +0100 Subject: [PATCH] test: stub `server-only` under Vitest MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The scenario-metrics route test now imports a module chain (route → overlay.ts) that carries `import "server-only"`, which Vite can't resolve to a Node entry. Alias it to an empty stub so the guard stays in app code while Node-env tests load. Full suite: 600 passing. Co-Authored-By: Claude Opus 4.8 (1M context) --- vitest.config.ts | 3 +++ vitest/server-only-stub.ts | 6 ++++++ 2 files changed, 9 insertions(+) create mode 100644 vitest/server-only-stub.ts diff --git a/vitest.config.ts b/vitest.config.ts index ede31fee..ead1997f 100644 --- a/vitest.config.ts +++ b/vitest.config.ts @@ -15,6 +15,9 @@ export default defineConfig({ resolve: { alias: { "@": path.resolve(__dirname, "./src"), + // `server-only` is a marker package with no Node-resolvable entry under + // Vite; stub it so tests that import a server module chain still load. + "server-only": path.resolve(__dirname, "./vitest/server-only-stub.ts"), }, }, }); diff --git a/vitest/server-only-stub.ts b/vitest/server-only-stub.ts new file mode 100644 index 00000000..636d6ece --- /dev/null +++ b/vitest/server-only-stub.ts @@ -0,0 +1,6 @@ +// Empty stub for the `server-only` marker package under Vitest. The real +// package resolves to an empty module on the server and a throwing one in the +// browser via export conditions Vite doesn't apply here; aliasing it keeps +// server-only guards in place in app code without breaking Node-env tests that +// import a module chain containing one. See vitest.config.ts. +export {};