Files
magpie/internal/gui/tests/win-fonts.test.cjs
T
yetone 57a87f0ab9 gui: code text on Windows is Cascadia Mono / Consolas with Chinese in YaHei UI, not SimSun (#690) — on a Chinese Windows 11 the Library's MCP tags (远程 · 需登录), the routing page's model chips (gpt-6.1-sol) and other small code text drew thin, unhinted and not round: the tags take --code, whose stack (ui-monospace, SF Mono, Menlo, Consolas, monospace) has no Chinese face, so their Chinese fell to the generic monospace, SimSun on a Chinese Windows; and routing.css's model chips and step lines, the sign-in sheet's link and code, the import textarea, the headers editor and What's new named stacks of their own (ui-monospace, SFMono-Regular, Menlo, monospace, or var(--mono, …) with no --mono anywhere) with no Windows face at all, so all their text was SimSun. Now every monospace text takes var(--code), and on Windows (html.win, as --font already is) --code is "Cascadia Mono", Consolas, "Microsoft YaHei UI", "Microsoft YaHei", monospace; the Mac's and Linux's stack is unchanged (the Mac's ui-monospace is SF Mono either way). win-fonts.test.cjs (no sheet names a monospace stack of its own; the badge, the id, the model chip and the sign-in link take the Mac's stack off Windows and Cascadia Mono / Consolas / YaHei UI with html.win) fails on the old CSS and passes in webkit and chromium; the routing, library, omarchy and signin-link GUI tests pass as before but routing-compact, routing-manual and routing-time, which fail the same on main. Not seen on a real Windows machine; the light grey of the ids (--faint) is unchanged.
2026-10-03 22:23:17 +08:00

40 lines
2.3 KiB
JavaScript

// Run with Node's test runner and Playwright on the module path; see README.md.
// Code text on Windows (#690): every monospace text in the GUI takes --code,
// and on Windows (html.win) --code is Cascadia Mono / Consolas with YaHei UI
// for Chinese, never the generic monospace alone, which a Chinese Windows
// draws in SimSun (thin, unhinted at 11px). Elsewhere --code stays the Mac's.
const assert = require("node:assert/strict");
const fs = require("node:fs/promises");
const path = require("node:path");
const { test } = require("node:test");
const { chromium, webkit } = require("playwright");
const assets = path.resolve(__dirname, "../assets");
const sheets = ["app.css", "library.css", "routing.css", "sessions.css", "plugins.css"];
test("no stylesheet names a monospace stack of its own", async () => {
for (const f of sheets) {
const css = await fs.readFile(path.join(assets, f), "utf8");
const lines = css.replace(/\/\*[\s\S]*?\*\//g, "").split("\n").filter((l) => /monospace/.test(l) && !/--code:/.test(l));
assert.deepEqual(lines, [], `${f} has a monospace stack of its own`);
}
});
test("code text on Windows is Cascadia Mono / Consolas with YaHei UI", async () => {
const css = (await Promise.all(sheets.map((f) => fs.readFile(path.join(assets, f), "utf8")))).join("\n");
const browser = await (process.env.BROWSER === "webkit" ? webkit : chromium).launch();
try {
const page = await browser.newPage();
await page.setContent(`<style>${css}</style>
<span class="mk-badge">远程 · 需登录</span><span class="mk-id">atlassian</span>
<div class="rt-accts"><b><code class="mdl">gpt-6.1-sol</code></b></div>
<div class="signing"><div class="signlink"><code>https://x</code></div></div>`);
const fams = () => page.evaluate(() => [".mk-badge", ".mk-id", ".rt-accts code.mdl", ".signing .signlink code"].map((s) => getComputedStyle(document.querySelector(s)).fontFamily));
for (const f of await fams()) assert.match(f, /^ui-monospace, "?SF Mono"?, Menlo/, "the Mac's stack off Windows");
await page.evaluate(() => document.documentElement.classList.add("win"));
for (const f of await fams()) assert.match(f, /^"?Cascadia Mono"?, Consolas, "?Microsoft YaHei UI"?/, "Windows' stack");
} finally {
await browser.close();
}
});