Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions api/_lib/function-count.test.ts
Original file line number Diff line number Diff line change
@@ -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([]);
});
});
Original file line number Diff line number Diff line change
@@ -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";

Expand Down
Loading