test(player): hold the session stop and the kept-point rule to the server
- The client's resume thresholds equal the server's (read from both sources). - The session stop's URL matches the route the server serves it on. - The player stops its server session by its item and its own id on an unload and on close, and keeps it when the page only goes into the back/forward cache.
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
import { readFileSync } from "node:fs";
|
||||
import { expect, it } from "vitest";
|
||||
|
||||
// One rule, two languages, no shared wire format — so a test is the only thing that holds them
|
||||
// together. Which point a library item keeps is the server's (`routes/_common.kept_position`); the
|
||||
// client repeats it (`lib/resume.ts`) for the shared link, which has no server side, and for the
|
||||
// library row it patches before the server has answered. A server-only change left the row showing
|
||||
// a Continue point the server had already cleared, and a link resuming at points the library no
|
||||
// longer keeps. Both must be EQUAL: neither direction is merely conservative here.
|
||||
//
|
||||
// Read from source rather than imported, as in plexFinishMargin.contract.test.ts.
|
||||
function constantIn(path: string, pattern: RegExp): number {
|
||||
const source = readFileSync(new URL(path, import.meta.url), "utf8");
|
||||
const m = pattern.exec(source);
|
||||
// If this fails the constant was renamed or moved — find it and re-point this test, because the
|
||||
// rule it guards did not go away.
|
||||
expect(m, `${pattern} not found in ${path}`).not.toBeNull();
|
||||
return Number(m![1]);
|
||||
}
|
||||
|
||||
const SERVER = "../../../backend/app/routes/_common.py";
|
||||
|
||||
it.each([
|
||||
["the least position that counts as started", "PROGRESS_MIN_SECONDS", "PROGRESS_MIN_S"],
|
||||
["the margin before the end that counts as finished", "FINISH_MARGIN_SECONDS", "FINISH_MARGIN_S"],
|
||||
])("keeps %s the same as the server", (_what, server, client) => {
|
||||
const backend = constantIn(SERVER, new RegExp(`^${server}\\s*=\\s*(\\d+)`, "m"));
|
||||
const frontend = constantIn("./resume.ts", new RegExp(`^const ${client}\\s*=\\s*(\\d+)`, "m"));
|
||||
expect(backend).toBeGreaterThan(0);
|
||||
expect(frontend).toBe(backend);
|
||||
});
|
||||
Reference in New Issue
Block a user