Repository navigation
Expand file tree
/
Copy pathplaywright.config.mjs
More file actions
68 lines (63 loc) · 2.97 KB
/
Copy pathplaywright.config.mjs
File metadata and controls
68 lines (63 loc) · 2.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import { defineConfig } from "@playwright/test";
import { randomUUID } from "node:crypto";
import { fileURLToPath } from "node:url";
import { prepareFontEnvironment } from "./scripts/lib/webui-font-environment.mjs";
const root = fileURLToPath(new URL(".", import.meta.url));
const serverId = process.env.WEBUI_BROWSER_SERVER_ID ?? randomUUID();
process.env.WEBUI_BROWSER_SERVER_ID = serverId;
// The visual baselines compare pixels, so the glyphs they draw have to be the
// same on every machine. The host's installed fonts are not: the CI image
// changes, the gate's browser dependency install pulls a different font
// package set over time, and the host's fontconfig decides between LCD
// subpixel fringes and grayscale antialiasing. The browser therefore runs
// under a fontconfig that exposes only the font files committed to
// `packages/webui/test/browser/fonts/`, so the rendering depends on this
// repository and on nothing else.
// Playwright clears outputDir before running. Runtime diagnostics and the
// fontconfig prepared while loading this config must live outside that tree.
const outputDirectory =
process.env.WEBUI_PLAYWRIGHT_OUTPUT_DIR ?? "/tmp/minimax-webui-playwright-results";
const fontEnvironment = prepareFontEnvironment(root, {
cacheDirectory: process.env.WEBUI_BROWSER_FONT_CACHE_DIR ?? "/tmp/minimax-webui-browser-font-cache",
});
// `reuseExistingServer` is opt-in. Playwright only probes the url for
// reachability, so reusing by default meant that *any* process answering on the
// harness port was silently adopted: the suite then ran against whatever artifact
// that process was serving, under a server id the in-test guard rejects only if
// the guard happens to run. Reusing is still useful for a deliberate local loop
// against one known-good server, so `WEBUI_BROWSER_REUSE=1` asks for it
// explicitly and anything else fails loudly on a busy port instead. CI never
// reuses: it is a fresh machine per run and has nothing to reuse.
const reuseExistingServer = !process.env.CI && process.env.WEBUI_BROWSER_REUSE === "1";
const headedBrowser = process.env.WEBUI_BROWSER_HEADED === "1";
export default defineConfig({
testDir: "./packages/webui/test/browser",
outputDir: outputDirectory,
fullyParallel: false,
workers: 1,
reporter: "list",
metadata: { webuiBrowserServerId: serverId },
use: {
baseURL: "http://127.0.0.1:4179",
viewport: { width: 1440, height: 900 },
deviceScaleFactor: 1,
locale: "zh-CN",
timezoneId: "Asia/Shanghai",
colorScheme: "light",
reducedMotion: "reduce",
browserName: "chromium",
channel: headedBrowser ? "chromium" : undefined,
headless: !headedBrowser,
trace: "retain-on-failure",
launchOptions: {
env: { ...process.env, ...fontEnvironment.env },
},
},
webServer: {
command: "node packages/webui/test/browser/server.mjs",
url: "http://127.0.0.1:4179/health",
reuseExistingServer,
env: { ...process.env, WEBUI_BROWSER_SERVER_ID: serverId },
timeout: 15_000,
},
});