Fix api page tests creating routes

This commit is contained in:
shamoon
2026-10-10 23:12:49 -07:00
parent 347d34c08c
commit 4a38eea1b0
3 changed files with 21 additions and 2 deletions
@@ -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", () => {
@@ -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 };
@@ -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([]);
});