Files
systemic-game-design-course/tools/test/play-spellgrid.test.mjs
T
Lucas WintherandClaude Opus 5.5 bb98be089a feat(tools): play-spellgrid stages the M10 reference with cards and levels and runs its CLI
Lesson 10 and both M10 reference READMEs now give the real recipe
(node tools/play-spellgrid.mjs <rust|ts> [l1|l2|l3]); root script play:spellgrid.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-29 19:08:17 +01:00

38 lines
1.9 KiB
JavaScript

import { test } from "node:test";
import assert from "node:assert/strict";
import { existsSync, mkdtempSync, writeFileSync } from "node:fs";
import { tmpdir } from "node:os";
import { join } from "node:path";
import { run } from "./helpers.mjs";
import { parseArgs } from "../play-spellgrid.mjs";
test("play_spellgrid_parses_args", () => {
assert.deepEqual(parseArgs(["rust"]), { lang: "rust", level: "l1", dir: null, stageOnly: false });
assert.deepEqual(parseArgs(["ts", "l2", "--dir", "x", "--stage-only"]), { lang: "ts", level: "l2", dir: "x", stageOnly: true });
});
test("play_spellgrid_stages_reference_cards_and_levels", () => {
// Uses the real course: the Module 10 Rust reference with every card it reads and the levels.
const dir = join(mkdtempSync(join(tmpdir(), "sdc-play-")), "ws");
const r = run("play-spellgrid.mjs", ["rust", "l3", "--dir", dir, "--stage-only"]);
assert.equal(r.code, 0, r.out);
for (const f of ["Cargo.toml", "src/cli.rs", "cards/whirlwind.json", "cards/powder-keg.json", "levels/l1-double-tap.json"]) {
assert.ok(existsSync(join(dir, f)), f);
}
assert.match(r.out, /cargo run --quiet --bin spellgrid -- levels\/l3-simultaneous-paradox\.json/);
// Re-staging the same directory is allowed.
assert.equal(run("play-spellgrid.mjs", ["rust", "--dir", dir, "--stage-only"]).code, 0);
});
test("play_spellgrid_refuses_unknown_level_and_foreign_dir", () => {
const foreign = mkdtempSync(join(tmpdir(), "sdc-play-"));
writeFileSync(join(foreign, "mine.txt"), "keep me");
const r = run("play-spellgrid.mjs", ["rust", "--dir", foreign, "--stage-only"]);
assert.equal(r.code, 1);
assert.match(r.out, /not empty/);
const bad = run("play-spellgrid.mjs", ["rust", "l9", "--dir", join(foreign, "ws"), "--stage-only"]);
assert.equal(bad.code, 1);
assert.match(bad.out, /no level "l9"\. Levels: l1-double-tap, l2-spliced-corpse, l3-simultaneous-paradox/);
assert.equal(run("play-spellgrid.mjs", ["java"]).code, 1);
});