51 lines
1.9 KiB
JavaScript
51 lines
1.9 KiB
JavaScript
import { serveAssets } from "./asset-server.mjs";
|
|
import assert from "node:assert/strict";
|
|
import { chromium } from "playwright";
|
|
import { init, stripSecret } from "../engine/index.js";
|
|
const base = await serveAssets("dist");
|
|
const state = stripSecret(await init(3, [], {}, "chinese-browser"), 0);
|
|
const browser = await chromium.launch({
|
|
executablePath: process.env.CHROMIUM_EXECUTABLE,
|
|
});
|
|
try {
|
|
for (const width of [390, 1400]) {
|
|
const page = await browser.newPage({ viewport: { width, height: 950 } });
|
|
const errors = [];
|
|
page.on("pageerror", (e) => errors.push(e.message));
|
|
await page.setContent(
|
|
'<!doctype html><meta name="viewport" content="width=device-width,initial-scale=1"><div id="app"></div>',
|
|
);
|
|
await page.addStyleTag({ url: base + "/viewer.css" });
|
|
await page.addScriptTag({ url: base + "/viewer.js" });
|
|
await page.evaluate((state) => {
|
|
window.e = primordialSoup.launch("#app");
|
|
e.emit("preferences", { locale: "zh-CN" });
|
|
e.emit("player", { index: 0 });
|
|
e.emit("state", state);
|
|
}, state);
|
|
await page.waitForFunction(() =>
|
|
document.body.innerText.includes("变形虫"),
|
|
);
|
|
const chinese = await page.locator("body").innerText();
|
|
assert.match(chinese, /基因|营养|漂流/);
|
|
await page.evaluate(() => e.emit("preferences", { locale: "en" }));
|
|
await page.waitForFunction(
|
|
() => !document.body.innerText.includes("变形虫"),
|
|
);
|
|
await page.evaluate(() => e.emit("preferences", { locale: "zh-Hans-SG" }));
|
|
await page.waitForFunction(() =>
|
|
document.body.innerText.includes("变形虫"),
|
|
);
|
|
assert.deepEqual(errors, []);
|
|
await page.screenshot({
|
|
path: `/tmp/soup-zh-${width}.png`,
|
|
fullPage: true,
|
|
});
|
|
console.log(
|
|
`Simplified Chinese cold load and live switching passed at ${width}px`,
|
|
);
|
|
await page.close();
|
|
}
|
|
} finally {
|
|
await browser.close();
|
|
}
|