54 lines
1.8 KiB
JavaScript
54 lines
1.8 KiB
JavaScript
import assert from "node:assert/strict";
|
|
import { readFile } from "node:fs/promises";
|
|
import test from "node:test";
|
|
|
|
async function renderHome() {
|
|
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("首页可正常服务端渲染正式称重界面", async () => {
|
|
const response = await renderHome();
|
|
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>/);
|
|
assert.match(html, /选择废料类型/);
|
|
assert.match(html, /管理员登录/);
|
|
assert.match(html, /TYPE ID · (?:<!-- -->)?3/);
|
|
assert.match(html, /TYPE ID · (?:<!-- -->)?6/);
|
|
});
|
|
|
|
test("正式代码不包含历史人员、机台或重量模拟数据", async () => {
|
|
const [page, utilities] = await Promise.all([
|
|
readFile(new URL("../app/page.tsx", import.meta.url), "utf8"),
|
|
readFile(new URL("../app/scale-utils.ts", import.meta.url), "utf8"),
|
|
]);
|
|
|
|
for (const legacySample of ["张伟", "E-0826", "A01 绕线机", "2.486"]) {
|
|
assert.doesNotMatch(page, new RegExp(legacySample));
|
|
}
|
|
|
|
assert.match(page, /new WebSocket\(appSettings\.weight\.trim\(\)\)/);
|
|
assert.match(page, /if \(!appSettings\.upload\.trim\(\)\) throw/);
|
|
assert.match(page, /evaluateStability\(stableSamples\.current\)/);
|
|
assert.match(utilities, /返回值统一为千克/);
|
|
});
|