mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-10-30 17:27:09 +00:00
* fix(registry): carousel cards fall back to their sample image inside the assets folder When an image variable resolves to nothing, the 25 carousel blocks loaded the sample card by bare file name, which 404s beside the block and draws a white card. The fallback now keeps assets/carousel-images/, the folder every card image is installed into. A guard test fails on any block with a bare fallback. * test(registry): the carousel fallback guard covers every block that uses it The guard now picks each block that reads an image variable and fails when its fallback no longer matches, instead of silently skipping it, and ignores stray files in the blocks folder.
35 lines
1.3 KiB
TypeScript
35 lines
1.3 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
import { readdirSync, readFileSync } from "node:fs";
|
|
import { join } from "node:path";
|
|
|
|
const blocksDir = join(import.meta.dirname, "..", "..", "registry", "blocks");
|
|
|
|
// The carousels draw each card from its image variable, or from the block's own
|
|
// sample image when the variable resolves to nothing.
|
|
const FALLBACK = /varUrl\(V\[id\]\)\s*\|\|\s*([^\n]*)DATA\.cards\[i % DATA\.cards\.length\]\.file/g;
|
|
|
|
function carousels(): Array<{ block: string; prefixes: string[] }> {
|
|
return readdirSync(blocksDir, { withFileTypes: true })
|
|
.filter((entry) => entry.isDirectory())
|
|
.map(({ name }) => ({
|
|
block: name,
|
|
html: readFileSync(join(blocksDir, name, `${name}.html`), "utf8"),
|
|
}))
|
|
.filter(({ html }) => html.includes("varUrl(V[id])"))
|
|
.map(({ block, html }) => ({
|
|
block,
|
|
prefixes: [...html.matchAll(FALLBACK)].map((match) => match[1] ?? ""),
|
|
}));
|
|
}
|
|
|
|
describe("carousel image fallback", () => {
|
|
it("loads the sample image from the block's assets folder, not a bare file name", () => {
|
|
const found = carousels();
|
|
expect(found.length).toBeGreaterThan(0);
|
|
for (const { block, prefixes } of found) {
|
|
expect(prefixes.length, block).toBeGreaterThan(0);
|
|
for (const prefix of prefixes) expect(prefix, block).toContain('"assets/carousel-images/" +');
|
|
}
|
|
});
|
|
});
|