Files
psu-schedule/test/snapshot.test.js
Zakhar Timoshenko e38c388462 Add course schedules for ISF and ITZS programs for 2026 and 2024 sessions
- Created new snapshot files for ISF credits and daily schedules for the 26-АРХ and 26-ПГС programs.
- Added summer 2026 and winter 2024 exam schedules for the 23-ИТзс program, detailing lectures, labs, and consultations.
2026-10-19 22:55:28 +03:00

45 lines
2.1 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { test } from "node:test";
import assert from "node:assert/strict";
import { readFileSync, readdirSync, writeFileSync, existsSync, mkdirSync } from "node:fs";
import { parseDocx } from "../server/parser.js";
import { diagnose } from "../server/diagnostics.js";
import { snapshotOf, diffLines } from "../scripts/snapshot-lines.js";
// Every fixture parsed and compared line by line with test/snapshots/<name>.txt, together with
// the cells diagnostics flags. After an intended parser change: UPDATE_SNAPSHOTS=1 npm test,
// then read the diff of test/snapshots/ before committing it.
const fixtures = new URL("./fixtures/", import.meta.url);
const snapshots = new URL("./snapshots/", import.meta.url);
const update = process.env.UPDATE_SNAPSHOTS === "1";
// The bell schedule and the week table are calendar documents, not timetables.
const calendars = new Set(["bells.docx", "weeks.docx"]);
for (const file of readdirSync(fixtures).filter((f) => f.endsWith(".docx") && !calendars.has(f)).sort()) {
test(`снимок разбора: ${file}`, () => {
const meta = existsSync(new URL(`${file}.json`, fixtures))
? JSON.parse(readFileSync(new URL(`${file}.json`, fixtures), "utf8"))
: {};
const schedule = parseDocx(readFileSync(new URL(file, fixtures)), {
name: meta.name || file,
modified: meta.modified,
});
const lines = [
...snapshotOf(schedule),
...diagnose(schedule).map((p) => `! ${p.code} | ${(p.raw || p.groups?.join(",") || "").replace(/\s+/g, " ")}`),
];
const target = new URL(file.replace(/\.docx$/, ".txt"), snapshots);
if (update || !existsSync(target)) {
mkdirSync(snapshots, { recursive: true });
writeFileSync(target, lines.join("\n") + "\n");
return;
}
const saved = readFileSync(target, "utf8").trimEnd().split("\n");
const { removed, added } = diffLines(saved, lines);
assert.ok(
!removed.length && !added.length,
`Разбор ${file} изменился (UPDATE_SNAPSHOTS=1 npm test, если так и задумано):\n` +
[...removed.map((l) => ` − ${l}`), ...added.map((l) => ` + ${l}`)].join("\n"),
);
});
}