// Tests for the goes-to-eleven fader's pure math (no DOM — mountFader owns all // document references, so the module imports cleanly in Node). // node home/test/fader.test.mjs import assert from "node:assert/strict"; import { faderLevel, faderValue } from "../web/static/fader.js"; let failures = 0; async function test(name, fn) { try { await fn(); console.log("PASS " + name); } catch (e) { console.log("FAIL " + name + " — " + (e && e.message)); failures++; } } await test("faderValue maps the slot run to 1..10 and clamps beyond it", () => { assert.equal(faderValue(0), 1); assert.equal(faderValue(0.86), 10, "the end of the run (RUN_END) is 10"); assert.equal(faderValue(1), 10, "past the run still clamps to 10 — eleven is not reachable by position"); assert.equal(faderValue(-0.5), 1, "before the slot clamps to 1"); assert.ok(faderValue(0.43) > 5 && faderValue(0.43) < 6.6, "mid-run lands mid-scale"); }); await test("faderLevel is silent below 5, hot by 10, and pressure adds strain", () => { assert.equal(faderLevel("slide", 1, 0), 0); assert.equal(faderLevel("slide", 5, 0), 0); assert.ok(Math.abs(faderLevel("slide", 10, 0) - 5 / 6) < 1e-9); assert.ok(faderLevel("slide", 10, 0.8) > faderLevel("slide", 10, 0), "the hold adds strain"); }); await test("faderLevel holds PAST 1.0 at the snap and through the whole build", () => { assert.equal(faderLevel("snap", 10, 0), 1.2); assert.equal(faderLevel("build", 10, 0), 1.2, "the volume stays AT eleven while building"); }); await test("faderLevel cuts to zero at done (silence before the confetti)", () => { assert.equal(faderLevel("done", 10, 0), 0); }); console.log(failures ? `\n${failures} FAILED` : "\nALL PASSED"); process.exit(failures ? 1 : 0);