// Tests for build-video's snap: where a cut lands in a pause. // // Run with: pnpm test:scripts import assert from "node:assert/strict"; import test from "node:test"; import { snap } from "./build-video.mjs"; const SIL = [{ s: 10, e: 10.8 }, { s: 20, e: 20.12 }]; test("snap: the default keeps 0.10 s before speech and 0.18 s after it", () => { assert.deepEqual(snap(10.5, SIL, "end", 1.6), { at: 10.18, snapped: true }); assert.equal(Number(snap(10.5, SIL, "start", 1.6).at.toFixed(3)), 10.7); assert.deepEqual(snap(15, SIL, "end", 1.6), { at: 15, snapped: false }); }); test("snap: snapTail / snapLead keep more of the pause, never more than it holds", () => { const render = { snapTail: 0.55, snapLead: 0.45 }; assert.equal(snap(10.5, SIL, "end", 1.6, render).at, 10.55); assert.equal(Number(snap(10.5, SIL, "start", 1.6, render).at.toFixed(3)), 10.35); // A 0.12 s gap: the whole gap and no more. assert.equal(Number(snap(20, SIL, "end", 1, render).at.toFixed(3)), 20.12); assert.equal(snap(20.1, SIL, "start", 1, render).at, 20); });