mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-11-25 08:32:45 +00:00
test(studio): preview walks read the frame Studio shows, not one Chrome re-lays out mid-shot (#8780)
* test(studio): preview walks read the frame Studio shows, not one Chrome re-lays out mid-shot * test(studio): the A-roll walk keeps its shots when given a folder that does not exist yet * test(studio): the graded walk names the brightest channel, and a grey pixel leads none
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
#!/usr/bin/env node
|
||||
// The A-roll must show in Studio's preview while playing: the untimed #plate backdrop above it is
|
||||
// one the film's own script keeps hidden outside 6-8 s, and the preview must not force it visible.
|
||||
import { writeFileSync } from "node:fs";
|
||||
import { launchStudioChrome } from "./chrome-executable.mjs";
|
||||
import { mkdirSync, writeFileSync } from "node:fs";
|
||||
import { launchStudioChrome, screenshotInPlace } from "./chrome-executable.mjs";
|
||||
|
||||
const STUDIO_URL = process.env.STUDIO_URL;
|
||||
const OUT_DIR = process.env.OUT_DIR;
|
||||
@@ -13,6 +13,7 @@ if (!STUDIO_URL) {
|
||||
console.error("STUDIO_URL is required and must point at the aroll-backdrop fixture");
|
||||
process.exit(2);
|
||||
}
|
||||
if (OUT_DIR) mkdirSync(OUT_DIR, { recursive: true });
|
||||
const { browser } = await launchStudioChrome();
|
||||
const failures = [];
|
||||
const evidence = {};
|
||||
@@ -62,7 +63,7 @@ try {
|
||||
do {
|
||||
attempts++;
|
||||
before = await readPreview();
|
||||
png = await iframe.screenshot({ encoding: "base64" });
|
||||
png = await screenshotInPlace(iframe, { encoding: "base64" });
|
||||
after = await readPreview();
|
||||
} while (before.box !== after.box && attempts < 5);
|
||||
if (OUT_DIR) writeFileSync(`${OUT_DIR}/${name}.png`, Buffer.from(png, "base64"));
|
||||
|
||||
@@ -4,6 +4,10 @@ import { findSystemChrome } from "../../vite.chrome.ts";
|
||||
/** The Chrome every Studio browser acceptance test launches: the one Studio's dev server picks. */
|
||||
export const resolveChromeExecutable = findSystemChrome;
|
||||
|
||||
/** `element` as laid out now; a shot past the viewport resizes the page mid-shot and Studio's dock re-lays out. */
|
||||
export const screenshotInPlace = (element, options = {}) =>
|
||||
element.screenshot({ ...options, captureBeyondViewport: false });
|
||||
|
||||
/** Headless Chrome for a Studio browser gate; exits 2 when no Chrome is installed. */
|
||||
export async function launchStudioChrome() {
|
||||
const executablePath = resolveChromeExecutable();
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
// green clip-path wipe from the left (4-6 s). Grading once froze the dissolve, and its hide once blacked it out.
|
||||
// A click on a graded clip still picks it.
|
||||
import { mkdirSync, writeFileSync } from "node:fs";
|
||||
import { launchStudioChrome } from "./chrome-executable.mjs";
|
||||
import { launchStudioChrome, screenshotInPlace } from "./chrome-executable.mjs";
|
||||
|
||||
const STUDIO_URL = process.env.STUDIO_URL;
|
||||
const OUT_DIR = process.env.OUT_DIR;
|
||||
@@ -50,7 +50,7 @@ try {
|
||||
const r = document.getElementById("film").getBoundingClientRect();
|
||||
return { x: r.x, y: r.y, width: r.width, height: r.height };
|
||||
});
|
||||
const png = await iframe.screenshot({ encoding: "base64" });
|
||||
const png = await screenshotInPlace(iframe, { encoding: "base64" });
|
||||
if (OUT_DIR) writeFileSync(`${OUT_DIR}/${name}.png`, Buffer.from(png, "base64"));
|
||||
const box = await iframe.boundingBox();
|
||||
const scale = box.width / (await frame.evaluate(() => window.innerWidth));
|
||||
@@ -76,7 +76,12 @@ try {
|
||||
);
|
||||
};
|
||||
const dark = ({ r, g, b }) => Math.max(r, g, b) < 40;
|
||||
const leads = ({ r, g, b }) => (g > r && g > b ? "green" : b > r ? "blue" : "red");
|
||||
const CHANNEL_COLOUR = { r: "red", g: "green", b: "blue" };
|
||||
const leads = (pixel) => {
|
||||
const values = Object.values(pixel);
|
||||
if (Math.max(...values) - Math.min(...values) < 40) return "no colour";
|
||||
return CHANNEL_COLOUR[Object.keys(pixel).reduce((top, c) => (pixel[c] > pixel[top] ? c : top))];
|
||||
};
|
||||
|
||||
for (const { time, red } of DISSOLVE) {
|
||||
const [centre] = await sample(`dissolve-${time}`, time, [[0.5, 0.5]]);
|
||||
@@ -108,7 +113,9 @@ try {
|
||||
]) {
|
||||
if (dark(pixel)) failures.push(`wipe at ${WIPE.time} s, ${side}: black`);
|
||||
else if (leads(pixel) !== colour)
|
||||
failures.push(`wipe at ${WIPE.time} s, ${side}: ${leads(pixel)} leads, expected ${colour}`);
|
||||
failures.push(
|
||||
`wipe at ${WIPE.time} s, ${side}: ${leads(pixel)} leads (${JSON.stringify(pixel)}), expected ${colour}`,
|
||||
);
|
||||
}
|
||||
} finally {
|
||||
await browser.close();
|
||||
|
||||
@@ -39,7 +39,7 @@ import { arch, platform, tmpdir } from "node:os";
|
||||
import { dirname, join, resolve } from "node:path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
import puppeteer from "puppeteer-core";
|
||||
import { resolveChromeExecutable } from "./chrome-executable.mjs";
|
||||
import { resolveChromeExecutable, screenshotInPlace } from "./chrome-executable.mjs";
|
||||
|
||||
const E2E_DIR = dirname(fileURLToPath(import.meta.url));
|
||||
const STUDIO_DIR = resolve(E2E_DIR, "../..");
|
||||
@@ -267,7 +267,7 @@ async function savePreviewScreenshot(page, name) {
|
||||
});
|
||||
const element = handle.asElement();
|
||||
assert(element, "Could not find the Studio preview iframe");
|
||||
await element.screenshot({ path: join(EVIDENCE_DIR, name) });
|
||||
await screenshotInPlace(element, { path: join(EVIDENCE_DIR, name) });
|
||||
await handle.dispose();
|
||||
}
|
||||
|
||||
@@ -278,7 +278,7 @@ async function capturePreviewHash(page) {
|
||||
});
|
||||
const element = handle.asElement();
|
||||
assert(element, "Could not find the Studio preview iframe");
|
||||
const bytes = await element.screenshot({ type: "png" });
|
||||
const bytes = await screenshotInPlace(element, { type: "png" });
|
||||
await handle.dispose();
|
||||
return sha256(bytes);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user