48 lines
1.7 KiB
JavaScript
48 lines
1.7 KiB
JavaScript
import { test } from "node:test";
|
|
import assert from "node:assert/strict";
|
|
import { join } from "node:path";
|
|
import { run, fixtures } from "./helpers.mjs";
|
|
import { planVerification } from "../verify-references.mjs";
|
|
import { moduleDirs } from "../lib.mjs";
|
|
|
|
const root = join(fixtures, "course");
|
|
|
|
test("verify_plan_skips_modules_without_reference", () => {
|
|
process.env.COURSE_ROOT = root;
|
|
const plan = planVerification(moduleDirs(), 3);
|
|
assert.deepEqual(plan.map((p) => p.num), ["01", "02", "03"]);
|
|
assert.deepEqual(plan[2].testModules.map((m) => m.num), ["01", "02", "03"]);
|
|
assert.deepEqual(plan[2].langs, ["rust", "ts"]);
|
|
});
|
|
|
|
test("verify_runs_with_copied_reference_and_tests", () => {
|
|
const r = run("verify-references.mjs", ["02"], {
|
|
COURSE_ROOT: root,
|
|
VERIFY_CMD_RUST: "test -f tests/m01.rs && test -f Cargo.toml && ! test -f tests/m03.rs",
|
|
VERIFY_CMD_TS: "test -f tests/m01.test.ts && test -f package.json",
|
|
});
|
|
assert.equal(r.code, 0, r.out);
|
|
assert.match(r.out, /01.*ok/s);
|
|
assert.match(r.out, /02.*ok/s);
|
|
});
|
|
|
|
test("verify_reports_failure", () => {
|
|
const r = run("verify-references.mjs", ["01"], {
|
|
COURSE_ROOT: root,
|
|
VERIFY_CMD_RUST: "false",
|
|
VERIFY_CMD_TS: "true",
|
|
});
|
|
assert.equal(r.code, 1);
|
|
assert.match(r.out, /FAIL/);
|
|
});
|
|
|
|
test("verify_stage_copies_all_earlier_module_tests", async () => {
|
|
process.env.COURSE_ROOT = root;
|
|
const { planVerification, stage } = await import("../verify-references.mjs");
|
|
const { existsSync } = await import("node:fs");
|
|
const plan = planVerification(moduleDirs(), 3)[2];
|
|
const dir = stage(plan, "rust");
|
|
for (const f of ["m01.rs", "m02.rs", "m03.rs"]) assert.ok(existsSync(join(dir, "tests", f)));
|
|
assert.ok(existsSync(join(dir, "Cargo.toml")));
|
|
});
|