From 4a38eea1b07d239c87786820d4ec0a6d99c9606c Mon Sep 17 00:00:00 2001 From: shamoon <4887959+shamoon@users.noreply.github.com> Date: Sat, 10 Oct 2026 23:12:49 -0700 Subject: [PATCH] Fix api page tests creating routes --- .../pages/api/mcp/index.test.js | 2 +- .../services/proxy-request-shaping.test.js} | 2 +- .../pages/no-colocated-tests.test.js | 19 +++++++++++++++++++ 3 files changed, 21 insertions(+), 2 deletions(-) rename src/{ => __tests__}/pages/api/mcp/index.test.js (99%) rename src/{pages/api/services/proxy.test.js => __tests__/pages/api/services/proxy-request-shaping.test.js} (99%) create mode 100644 src/__tests__/pages/no-colocated-tests.test.js diff --git a/src/pages/api/mcp/index.test.js b/src/__tests__/pages/api/mcp/index.test.js similarity index 99% rename from src/pages/api/mcp/index.test.js rename to src/__tests__/pages/api/mcp/index.test.js index 30bf73140..2eb84b01d 100644 --- a/src/pages/api/mcp/index.test.js +++ b/src/__tests__/pages/api/mcp/index.test.js @@ -34,7 +34,7 @@ function mockResponse() { async function loadHandler() { vi.resetModules(); - return (await import("./index")).default; + return (await import("pages/api/mcp/index")).default; } describe("pages/api/mcp", () => { diff --git a/src/pages/api/services/proxy.test.js b/src/__tests__/pages/api/services/proxy-request-shaping.test.js similarity index 99% rename from src/pages/api/services/proxy.test.js rename to src/__tests__/pages/api/services/proxy-request-shaping.test.js index 3c5336040..6c6147c60 100644 --- a/src/pages/api/services/proxy.test.js +++ b/src/__tests__/pages/api/services/proxy-request-shaping.test.js @@ -57,7 +57,7 @@ vi.mock("widgets/widgets", () => ({ }, })); -import handler from "./proxy"; +import handler from "pages/api/services/proxy"; function createReq({ method = "GET", body, query = {} } = {}) { return { method, body, query }; diff --git a/src/__tests__/pages/no-colocated-tests.test.js b/src/__tests__/pages/no-colocated-tests.test.js new file mode 100644 index 000000000..7133b67a6 --- /dev/null +++ b/src/__tests__/pages/no-colocated-tests.test.js @@ -0,0 +1,19 @@ +import { readdirSync } from "fs"; + +import { expect, it } from "vitest"; + +// Next compiles everything under src/pages into routes, so a colocated test ships +// to users and drags its dev dependencies into the runtime image. +function filesIn(dir, found = []) { + readdirSync(dir, { withFileTypes: true }).forEach((entry) => { + const path = `${dir}/${entry.name}`; + if (entry.isDirectory()) filesIn(path, found); + else found.push(path); + }); + return found; +} + +it("keeps test files out of src/pages", () => { + const tests = filesIn("src/pages").filter((path) => /\.(test|spec)\.[jt]sx?$/.test(path)); + expect(tests).toEqual([]); +});