fix(training): keep the driver's page self-contained so it loads through the club router (1.87.1)
This commit is contained in:
1 parent
0caf50254a
commit
ee290a4ab8
6 files changed
+122
-7
No files matched your search
@@ -3,8 +3,7 @@ import assert from "node:assert/strict";
|
||||
import fs from "node:fs";
|
||||
import vm from "node:vm";
|
||||
|
||||
// The page is an ES module; drop its imports to run it as a plain script (rendering is stubbed below).
|
||||
const source = fs.readFileSync(new URL("../src/public_training.js", import.meta.url), "utf8").replace(/^import .*$/gm, "");
|
||||
const source = fs.readFileSync(new URL("../src/public_training.js", import.meta.url), "utf8");
|
||||
|
||||
function profileHarness() {
|
||||
const ui = { editing: false, saving: false, requests: 0, renders: 0, html: "existing profile" };
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
import test from "node:test";
|
||||
import assert from "node:assert/strict";
|
||||
import fs from "node:fs";
|
||||
import vm from "node:vm";
|
||||
import { buildStintLapRows, renderStintLapCards } from "../src/stint_laps_view.js";
|
||||
import { buildTrainingStintAnalysis } from "../src/training_logic.js";
|
||||
|
||||
@@ -48,3 +50,22 @@ test("the day's fastest lap is purple, over every stint that day", () => {
|
||||
assert.equal((both.match(/class="stint-lap is-day-best"/g) || []).length, 1);
|
||||
assert.equal(buildStintLapRows([{ lapMs: 13100 }], { dayBestMs: 13100 })[0].dayBest, true);
|
||||
});
|
||||
|
||||
// The driver's page goes to the internet through the club router, whose nginx publishes only
|
||||
// public_training.js/.css - an import from it is a 404 and the page spins forever. So it
|
||||
// carries its own copy of the stint cards, which must render exactly like the module.
|
||||
test("the driver's page imports nothing and its stint-card copy matches the module", () => {
|
||||
const source = fs.readFileSync(new URL("../src/public_training.js", import.meta.url), "utf8");
|
||||
assert.doesNotMatch(source, /^\s*import\b|\bimport\(/m, "public_training.js must stay one self-contained file");
|
||||
const copy = source.slice(source.indexOf("// ---- Stint cards: a copy"), source.indexOf("// ---- end of copy ----"));
|
||||
const context = vm.createContext({});
|
||||
vm.runInContext(`${copy}\nthis.render = renderStintLapCards; this.rows = buildStintLapRows;`, context);
|
||||
const day = new Date(2026, 10, 9, 18).getTime();
|
||||
const stints = [
|
||||
{ id: "a", number: 1, startedAt: day, lapCount: 3, bestLapMs: 13300, averageLapMs: 13500, durationMs: 40000, consistencyPct: 2.5, laps: [{ lapMs: 150000, excluded: true }, { lapMs: 13500 }, { lapMs: 13300 }, { lapMs: 16000 }] },
|
||||
{ id: "b", number: 2, startedAt: day + 3600000, lapCount: 2, bestLapMs: 13100, averageLapMs: 13250, durationMs: 26500, consistencyPct: null, laps: [{ lapMs: 13100 }, { lapMs: 13400 }] },
|
||||
];
|
||||
const options = { formatLap: fmt, formatDuration: fmt, escapeHtml, labels: { ...labels, consistency: "Jämnhet" }, openIds: new Set(["b"]) };
|
||||
assert.equal(context.render(stints, options), renderStintLapCards(stints, options));
|
||||
assert.equal(JSON.stringify(context.rows(stints[0].laps, { dayBestMs: 13100 })), JSON.stringify(buildStintLapRows(stints[0].laps, { dayBestMs: 13100 })));
|
||||
});
|
||||
Reference in new issue
Block a user