83 lines
3 KiB
JavaScript
83 lines
3 KiB
JavaScript
// Test the actual release artifact, including its relative locale downloads.
|
||
// Usage: node test/journal-release-browser.mjs viewer.json [candidate-viewer.js]
|
||
import assert from "node:assert/strict";
|
||
import { readFile } from "node:fs/promises";
|
||
import { chromium } from "playwright";
|
||
import { prepared } from "../viewer/tutorials.js";
|
||
import { stripSecret } from "../engine/index.js";
|
||
|
||
const viewer = JSON.parse(await readFile(process.argv[2], "utf8"));
|
||
const browser = await chromium.launch({
|
||
executablePath: process.env.CHROMIUM_EXECUTABLE,
|
||
});
|
||
try {
|
||
const page = await browser.newPage();
|
||
const errors = [];
|
||
page.on("pageerror", (error) => errors.push(error.message));
|
||
await page.route(
|
||
"https://boardgamers.space/__journal_release_check__",
|
||
(route) =>
|
||
route.fulfill({
|
||
contentType: "text/html; charset=utf-8",
|
||
body: '<html lang="en"><body><div id="app"></div></body></html>',
|
||
}),
|
||
);
|
||
if (process.argv[3]) {
|
||
const body = await readFile(process.argv[3], "utf8");
|
||
await page.route(viewer.url, (route) =>
|
||
route.fulfill({ contentType: "text/javascript; charset=utf-8", body }),
|
||
);
|
||
}
|
||
await page.goto("https://boardgamers.space/__journal_release_check__");
|
||
for (const url of viewer.dependencies?.stylesheets ?? [])
|
||
await page.addStyleTag({ url });
|
||
await page.addScriptTag({ url: viewer.url });
|
||
const state = prepared();
|
||
const name = `O'Brien & "Co" <img src=x>`;
|
||
state.players[0].name = "dcobin";
|
||
state.players[1].name = name;
|
||
state.log = [
|
||
{ round: 2, phase: 1, text: "The current is north. Ozone layer: 11." },
|
||
{ round: 2, phase: 2, text: "dcobin didn't buy any genes." },
|
||
{ round: 2, phase: 2, text: `${name} didn't buy any genes.` },
|
||
];
|
||
await page.evaluate((state) => {
|
||
window.e = primordialSoup.launch("#app");
|
||
e.emit("player", { index: 0 });
|
||
e.emit("state", state);
|
||
}, stripSecret(state));
|
||
const entry = page.locator(".journal-event").filter({ hasText: "dcobin" });
|
||
await entry.waitFor();
|
||
for (const locale of ["en", "fr", "en"]) {
|
||
await page.evaluate((locale) => e.emit("preferences", { locale }), locale);
|
||
const phase = locale === "fr" ? "Nouveaux gènes" : "New genes";
|
||
await page.waitForFunction(
|
||
(phase) =>
|
||
document.querySelector(".journal-list")?.textContent.includes(phase),
|
||
phase,
|
||
);
|
||
const pass =
|
||
locale === "fr" ? "n’a acheté aucun gène." : "didn't buy any genes.";
|
||
assert.equal((await entry.textContent()).trim(), `dcobin ${pass}`);
|
||
assert.equal(
|
||
await entry
|
||
.locator("[data-localized-rich-text]")
|
||
.getAttribute("data-localized-rich-text"),
|
||
"dcobin didn't buy any genes.",
|
||
);
|
||
assert.equal(
|
||
(await page.locator(".last-move").textContent()).trim(),
|
||
`${name} ${pass}`,
|
||
);
|
||
assert.equal(
|
||
await page.locator(".journal-event img, .last-move img").count(),
|
||
0,
|
||
);
|
||
}
|
||
assert.deepEqual(errors, []);
|
||
console.log(
|
||
"Release journal: plain apostrophes, quoted player names and English/French switching passed",
|
||
);
|
||
} finally {
|
||
await browser.close();
|
||
}
|