diff --git a/api/_lib/function-count.test.ts b/api/_lib/function-count.test.ts new file mode 100644 index 0000000..186cc9f --- /dev/null +++ b/api/_lib/function-count.test.ts @@ -0,0 +1,27 @@ +import { readdirSync, statSync } from "node:fs"; +import { join, relative } from "node:path"; +import { describe, expect, it } from "vitest"; + +// Vercel's Hobby plan deploys at most 12 functions; every .ts under api/ +// outside _-prefixed folders counts, tests included, and one more fails the deploy. +const HOBBY_LIMIT = 12; +const API_ROOT = join(__dirname, ".."); + +function functionFiles(dir: string): string[] { + return readdirSync(dir).flatMap((name) => { + const path = join(dir, name); + if (name.startsWith("_") || name.startsWith(".")) return []; + if (statSync(path).isDirectory()) return functionFiles(path); + return /\.(ts|js|mjs)$/.test(name) && !name.endsWith(".d.ts") ? [relative(API_ROOT, path)] : []; + }); +} + +describe("api functions", () => { + it("stay within the Vercel Hobby limit", () => { + expect(functionFiles(API_ROOT).length).toBeLessThanOrEqual(HOBBY_LIMIT); + }); + + it("do not include tests (they would deploy as functions)", () => { + expect(functionFiles(API_ROOT).filter((file) => file.includes(".test."))).toEqual([]); + }); +}); diff --git a/api/ranked/challenge.test.ts b/api/_lib/ranked-challenge.test.ts similarity index 94% rename from api/ranked/challenge.test.ts rename to api/_lib/ranked-challenge.test.ts index cfc0522..df0e695 100644 --- a/api/ranked/challenge.test.ts +++ b/api/_lib/ranked-challenge.test.ts @@ -1,5 +1,5 @@ import { describe, expect, it } from "vitest"; -import { selectSnippetCode } from "./challenge"; +import { selectSnippetCode } from "../ranked/challenge"; import { isWithinLengthSpec } from "../../src/utils/ranking"; import type { SnippetLength } from "../../src/types";