Add a test suite for the domain logic and the server routes.
The project had no automated verification at all, so the "Test" step in the AGENTS.md workflow rested entirely on clicking through the app. The suite runs on bun with node:assert and adds no dependency: every file is a script that exits non-zero when a check fails, and test/run.ts runs each one in its own process. Unit tests cover the rules that decide what players see (badges, streaks, ball duty rotation, ratings, MVP ties, scouting totals, goals, notifications, CSI parsing); integration and end-to-end tests drive the real dev server. Nothing writes to the database, so both can be pointed at a live environment. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
+45
@@ -0,0 +1,45 @@
|
||||
/**
|
||||
* Esecutore della suite: `bun test/run.ts [unit|integration|e2e|all]`.
|
||||
* Ogni file gira in un processo separato, così un test non può inquinare gli altri.
|
||||
* Senza argomenti esegue solo gli unit test (non serve rete né database).
|
||||
*/
|
||||
import { spawnSync } from "node:child_process";
|
||||
import { readdirSync } from "node:fs";
|
||||
|
||||
const cartelle = { unit: "test/unit", integration: "test/integration", e2e: "test/e2e" };
|
||||
type Gruppo = keyof typeof cartelle;
|
||||
|
||||
const argomento = (process.argv[2] ?? "unit") as Gruppo | "all";
|
||||
const gruppi: Gruppo[] =
|
||||
argomento === "all" ? (Object.keys(cartelle) as Gruppo[]) : [argomento as Gruppo];
|
||||
|
||||
for (const g of gruppi) {
|
||||
if (!cartelle[g]) {
|
||||
console.error(`Gruppo sconosciuto: ${g}. Usa unit, integration, e2e oppure all.`);
|
||||
process.exit(2);
|
||||
}
|
||||
}
|
||||
|
||||
const falliti: string[] = [];
|
||||
let totali = 0;
|
||||
|
||||
for (const gruppo of gruppi) {
|
||||
const cartella = cartelle[gruppo];
|
||||
const file = readdirSync(cartella)
|
||||
.filter((f) => f.endsWith(".test.ts"))
|
||||
.sort();
|
||||
|
||||
console.log(`\n── ${gruppo} (${file.length} file)`);
|
||||
for (const nome of file) {
|
||||
const percorso = `${cartella}/${nome}`;
|
||||
totali += 1;
|
||||
const esito = spawnSync("bun", [percorso], { stdio: "inherit" });
|
||||
if (esito.status !== 0) falliti.push(percorso);
|
||||
}
|
||||
}
|
||||
|
||||
console.log(
|
||||
`\n${totali - falliti.length}/${totali} file ok` +
|
||||
(falliti.length ? `\nfalliti:\n ${falliti.join("\n ")}` : ""),
|
||||
);
|
||||
process.exit(falliti.length ? 1 : 0);
|
||||
Reference in New Issue
Block a user