48 lines
2.0 KiB
JavaScript
48 lines
2.0 KiB
JavaScript
import assert from "node:assert/strict";
|
|
import { readFile } from "node:fs/promises";
|
|
import test from "node:test";
|
|
|
|
async function render() {
|
|
const workerUrl = new URL("../dist/server/index.js", import.meta.url);
|
|
workerUrl.searchParams.set("test", `${process.pid}-${Date.now()}`);
|
|
const { default: worker } = await import(workerUrl.href);
|
|
|
|
return worker.fetch(
|
|
new Request("http://localhost/", { headers: { accept: "text/html" } }),
|
|
{ ASSETS: { fetch: async () => new Response("Not found", { status: 404 }) } },
|
|
{ waitUntil() {}, passThroughOnException() {} },
|
|
);
|
|
}
|
|
|
|
test("server-renders the pixel bead application shell", async () => {
|
|
const response = await render();
|
|
assert.equal(response.status, 200);
|
|
assert.match(response.headers.get("content-type") ?? "", /^text\/html\b/i);
|
|
|
|
const html = await response.text();
|
|
assert.match(html, /<title>豆格工坊|图片转拼豆图纸<\/title>/i);
|
|
assert.match(html, /导入现成图纸/);
|
|
assert.match(html, /MARD 221 基础色卡/);
|
|
assert.match(html, /原图与现成图纸都只在当前浏览器中处理/);
|
|
assert.doesNotMatch(html, /codex-preview|Your site is taking shape/i);
|
|
});
|
|
|
|
test("keeps MARD pattern import wired to the crop and recognition flow", async () => {
|
|
const [page, css, palette] = await Promise.all([
|
|
readFile(new URL("../app/page.tsx", import.meta.url), "utf8"),
|
|
readFile(new URL("../app/globals.css", import.meta.url), "utf8"),
|
|
readFile(new URL("../app/mard-palette.ts", import.meta.url), "utf8"),
|
|
]);
|
|
|
|
assert.match(page, /function importMardPatternImage\(/);
|
|
assert.match(page, /recognizedCodes/);
|
|
assert.match(page, /missingCodeAsEmpty/);
|
|
assert.match(page, /没有识别到 MARD 编码的格子视为空白/);
|
|
assert.match(page, /pattern-import-grid-overlay/);
|
|
assert.match(page, /max="256"/);
|
|
assert.match(css, /\.pattern-import-grid-overlay/);
|
|
assert.match(css, /@media \(max-width: 760px\)/);
|
|
assert.match(palette, /export const MARD_221/);
|
|
assert.match(palette, /A:\s*"#[0-9A-F]{6}/);
|
|
});
|