Repository navigation
Expand file tree
/
Copy pathplaywright.config.mjs
More file actions
87 lines (82 loc) · 4.05 KB
/
Copy pathplaywright.config.mjs
File metadata and controls
87 lines (82 loc) · 4.05 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import { defineConfig } from "@playwright/test";
import { randomUUID } from "node:crypto";
import { createRequire } from "node:module";
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";
const playwrightVersion = createRequire(import.meta.url)("@playwright/test/package.json").version;
// Backport Playwright #43605 for the pinned 1.63.0 browser. Chromium treats
// repeated disable-features switches as last-wins, so preserve the existing
// feature list and replace that exact switch instead of adding a second one.
const pinnedDisabledFeatures = "--disable-features=" + [
"AvoidUnnecessaryBeforeUnloadCheckSync", "DestroyProfileOnBrowserClose",
"DialMediaRouteProvider", "GlobalMediaControls", "HttpsUpgrades",
"LensOverlay", "MediaRouter", "PaintHolding", "ThirdPartyStoragePartitioning",
"BlockOriginHeaderModificationOnRedirect", "Translate", "AutoDeElevate",
"OptimizationHints", "msForceBrowserSignIn", "msEdgeUpdateLaunchServicesPreferredVersion",
].join(",");
const windowsTcpWorkaround = process.platform === "win32" && playwrightVersion === "1.63.0"
? {
ignoreDefaultArgs: [pinnedDisabledFeatures],
args: [`${pinnedDisabledFeatures},TcpPortRandomizationWin`],
}
: {};
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: {
...windowsTcpWorkaround,
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,
},
});