mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-12-01 18:07:00 +01:00
test: Storybook visual snapshot suite (Phase 0 tooling)
Playwright-based screenshot suite over the built Storybook: one test per story per theme (dark/light), byte-identical comparison (maxDiffPixels 0), Date frozen via init-script shim (page.clock broke React rendering in several stories), animations disabled, per-story settle map for delayed state flips and a mask for one bimodal ::highlight race. Run with pnpm test:storybook-visual (or :update to re-baseline). No new dependencies: reuses the repo's @playwright/test and a dependency-free static server script. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
29dadead61
commit
b0a5872ec6
5 files changed
+212
No files matched your search
@@ -0,0 +1,69 @@
|
||||
#!/usr/bin/env node
|
||||
// Tiny dependency-free static file server for the built Storybook
|
||||
// (ui/storybook-static). Used by the visual snapshot suite's webServer so we
|
||||
// don't add an http-server dependency.
|
||||
import { createServer } from "node:http";
|
||||
import { createReadStream, existsSync, statSync } from "node:fs";
|
||||
import { extname, join, normalize, resolve } from "node:path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
|
||||
const root = resolve(
|
||||
fileURLToPath(new URL(".", import.meta.url)),
|
||||
"..",
|
||||
"ui",
|
||||
"storybook-static",
|
||||
);
|
||||
const port = Number(process.env.PORT ?? 6106);
|
||||
|
||||
if (!existsSync(join(root, "index.html"))) {
|
||||
console.error(
|
||||
`No built Storybook at ${root}. Run \`pnpm build-storybook\` first.`,
|
||||
);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
const MIME = {
|
||||
".html": "text/html; charset=utf-8",
|
||||
".js": "text/javascript; charset=utf-8",
|
||||
".mjs": "text/javascript; charset=utf-8",
|
||||
".css": "text/css; charset=utf-8",
|
||||
".json": "application/json; charset=utf-8",
|
||||
".png": "image/png",
|
||||
".jpg": "image/jpeg",
|
||||
".jpeg": "image/jpeg",
|
||||
".gif": "image/gif",
|
||||
".svg": "image/svg+xml",
|
||||
".ico": "image/x-icon",
|
||||
".woff": "font/woff",
|
||||
".woff2": "font/woff2",
|
||||
".ttf": "font/ttf",
|
||||
".map": "application/json; charset=utf-8",
|
||||
".txt": "text/plain; charset=utf-8",
|
||||
".webm": "video/webm",
|
||||
".mp4": "video/mp4",
|
||||
};
|
||||
|
||||
const server = createServer((req, res) => {
|
||||
const url = new URL(req.url ?? "/", `http://localhost:${port}`);
|
||||
let filePath = normalize(join(root, decodeURIComponent(url.pathname)));
|
||||
if (!filePath.startsWith(root)) {
|
||||
res.writeHead(403).end("forbidden");
|
||||
return;
|
||||
}
|
||||
if (existsSync(filePath) && statSync(filePath).isDirectory()) {
|
||||
filePath = join(filePath, "index.html");
|
||||
}
|
||||
if (!existsSync(filePath)) {
|
||||
res.writeHead(404).end("not found");
|
||||
return;
|
||||
}
|
||||
res.writeHead(200, {
|
||||
"content-type": MIME[extname(filePath)] ?? "application/octet-stream",
|
||||
"cache-control": "no-store",
|
||||
});
|
||||
createReadStream(filePath).pipe(res);
|
||||
});
|
||||
|
||||
server.listen(port, () => {
|
||||
console.log(`storybook-static served at http://localhost:${port}`);
|
||||
});
|
||||
Reference in new issue
Block a user