import { test, expect, type Page } from "@playwright/test"; import { execFileSync } from "node:child_process"; import { copyFileSync, existsSync, readFileSync } from "node:fs"; import path from "node:path"; import { fileURLToPath } from "node:url"; import * as urls from "./urls"; // --------------------------------------------------------------------------- // A VIDEO entry (report-to-video/video-entry.mjs; umtool/docs/report-video.md, "A video entry"): a file of the // project played FULL FRAME with its own sound, nothing of the deck over it. Play plays the fixture's cut, // which ends on one: the item before darkens into it, the video's element plays on Play's clock, and while it // is on screen the root says the chrome is off and the video covers the whole frame. And the CLI adds one to a // take only (`timeline

--take add-video`), the project's cut untouched. Fixture: // e2e/fixtures/video-entry-fixture.mjs. // --------------------------------------------------------------------------- const HERE = path.dirname(fileURLToPath(import.meta.url)); const FIXTURE = path.join(HERE, "..", ".e2e-song"); const PROJECT = "reports/video-entry-fixture"; const DIR = path.join(FIXTURE, "reports", "video-entry-fixture"); const MANIFEST = path.join(DIR, "video.manifest.json"); const TAKE = path.join(DIR, "takes", "walk", "take.json"); const root = (page: Page) => page.locator("[data-play-cut]"); const umtool = (args: string[]) => execFileSync("node", ["bin/umtool.mjs", ...args], { cwd: path.join(HERE, ".."), encoding: "utf8", env: { ...process.env, REPORTS_DIR: FIXTURE, CHANNELS_DIR: path.join(FIXTURE, "channels"), UMTOOL_CACHE_DIR: path.join(FIXTURE, "cache"), UMTOOL_MEDIA_DIR: "" }, }); test.beforeAll(() => { for (const f of [MANIFEST, TAKE]) { if (!existsSync(`${f}.pristine`)) copyFileSync(f, `${f}.pristine`); copyFileSync(`${f}.pristine`, f); } }); test.beforeEach(() => { test.setTimeout(120_000); }); test("Play plays a cut that ends on a video entry: the stage darkens into it, then the file plays full frame, chrome off", async ({ page }) => { await page.setViewportSize({ width: 1366, height: 1000 }); await page.goto(urls.playHref(PROJECT, { bare: true })); await expect(root(page)).toHaveAttribute("data-play-state", "paused", { timeout: 30_000 }); // The strip shows it as an item of its own, last. const rows = page.locator("[data-play-row]"); await expect(rows).toHaveCount(3); expect(await rows.evaluateAll((els) => els.map((e) => e.getAttribute("data-play-row")))).toEqual(["c01", "k01", "fin"]); // Nothing of it before it is near. await expect(page.locator("[data-play-video]")).toHaveCount(0); await expect(root(page)).not.toHaveAttribute("data-play-chrome", "off"); // From the card: it plays on into the video. await page.locator('[data-play-row="k01"]').click(); await expect(root(page)).toHaveAttribute("data-play-item", "k01"); await page.locator("[data-play-toggle]").click(); // The card darkens into it (the whole stage, its chrome with it). await expect(page.locator('[data-play-dip="k01"]')).toBeVisible({ timeout: 20_000 }); await expect(root(page)).toHaveAttribute("data-play-item", "fin", { timeout: 20_000 }); await expect(root(page)).toHaveAttribute("data-play-chrome", "off"); const player = page.locator('[data-play-video="fin"]'); await expect(player).toBeVisible(); await expect(player).toHaveAttribute("data-play-video-fit", "contain"); // It covers the whole frame: its box is the player's. const pb = await page.locator("[data-play-player-pin]").boundingBox(); const vb = await player.boundingBox(); expect(pb && vb).toBeTruthy(); expect(Math.abs((vb?.width ?? 0) - (pb?.width ?? 0))).toBeLessThan(2); // Its element plays the file on Play's clock: its source second moves on from `from` (1 s). const el = player.locator("video"); await expect(el).toHaveAttribute("src", /\/api\/report\/file\?.*path=media%2Ffin\.mp4/); await expect.poll(async () => el.evaluate((v: HTMLVideoElement) => v.currentTime), { timeout: 20_000 }).toBeGreaterThan(1.2); await expect.poll(async () => el.evaluate((v: HTMLVideoElement) => v.muted), { timeout: 10_000 }).toBe(false); // It ends on its last frame: the cut ends, the video stays on screen at its end. await expect(root(page)).toHaveAttribute("data-play-state", "ended", { timeout: 20_000 }); await expect(player).toBeVisible(); expect(await el.evaluate((v: HTMLVideoElement) => v.currentTime)).toBeGreaterThan(2.5); await page.screenshot({ path: test.info().outputPath("video-entry-end.png") }); }); test("the CLI adds a video entry to a take only: its knobs, its file's length; the project's cut untouched", () => { const before = readFileSync(MANIFEST, "utf8"); const dry = JSON.parse(umtool(["timeline", PROJECT, "--take", "walk", "add-video", "media/fin.mp4", "--from", "1", "--bass", "6", "--dry-run", "--json"])); expect(dry.ok).toBe(true); expect(JSON.parse(readFileSync(TAKE, "utf8")).patch.timeline).toHaveLength(2); const out = JSON.parse(umtool(["timeline", PROJECT, "--take", "walk", "add-video", "media/fin.mp4", "--from", "1", "--bass", "6", "--json"])); expect(out.ok).toBe(true); expect(out.inserted.at).toBe(2); expect(out.inserted.entry).toMatchObject({ type: "video", src: "media/fin.mp4", from: 1, audio: { bass: 6 } }); expect(out.inserted.entry.fileSeconds).toBeGreaterThan(2.9); const take = JSON.parse(readFileSync(TAKE, "utf8")); expect(take.patch.timeline.map((e: { id: string }) => e.id)).toEqual(["c01", "k01", out.inserted.id]); expect(readFileSync(MANIFEST, "utf8")).toBe(before); // A bad knob is refused in the build's words, nothing written. let code = 0; try { umtool(["timeline", PROJECT, "--take", "walk", "add-video", "media/fin.mp4", "--fit", "stretch", "--json"]); } catch (e) { code = (e as { status?: number }).status ?? -1; } expect(code).not.toBe(0); expect(JSON.parse(readFileSync(TAKE, "utf8")).patch.timeline).toHaveLength(3); });