-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Expand file tree
/
Copy pathplaywright.browserstack.config.ts
More file actions
96 lines (85 loc) · 4.11 KB
/
playwright.browserstack.config.ts
File metadata and controls
96 lines (85 loc) · 4.11 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
88
89
90
91
92
93
94
95
96
/**
* Playwright configuration for running tests on BrowserStack via CDP.
*
* Connects to a remote Chrome on BrowserStack using Playwright's built-in
* `connectOptions.wsEndpoint`. No BrowserStack SDK or browserstack.yml needed.
*
* Usage:
* BSTACK_TEST_TYPE=webgl2 npx playwright test \
* --config ./playwright.browserstack.config.ts
*
* Supported BSTACK_TEST_TYPE values:
* webgl2, webgpu, interaction, performance
*/
import { defineConfig } from "@playwright/test";
import { populateEnvironment } from "@dev/build-tools";
populateEnvironment();
if (!process.env.BROWSERSTACK_USERNAME || !process.env.BROWSERSTACK_ACCESS_KEY) {
throw new Error("BROWSERSTACK_USERNAME and BROWSERSTACK_ACCESS_KEY must be set. " + "Add them to .env at the repo root or export them in your shell.");
}
// Derive installed Playwright version so the BrowserStack capability stays in
// sync with the repo's dependency and doesn't silently drift after upgrades.
// eslint-disable-next-line @typescript-eslint/no-require-imports
const playwrightVersion: string = require("@playwright/test/package.json").version;
const testType = process.env.BSTACK_TEST_TYPE || "webgl2";
const isPerformanceRun = testType === "performance";
// ---------------------------------------------------------------------------
// BrowserStack CDP capabilities
// ---------------------------------------------------------------------------
const caps = {
browser: process.env.BSTACK_BROWSER || "chrome",
browser_version: process.env.BSTACK_BROWSER_VERSION || "latest",
os: process.env.BSTACK_OS || "OS X",
os_version: process.env.BSTACK_OS_VERSION || "Sonoma",
project: "Babylon.js",
build: process.env.BSTACK_BUILD_NAME || `Tests - ${testType}`,
name: `Babylon.js ${testType}`,
"browserstack.username": process.env.BROWSERSTACK_USERNAME,
"browserstack.accessKey": process.env.BROWSERSTACK_ACCESS_KEY,
"browserstack.console": "errors",
"browserstack.networkLogs": "false",
"browserstack.debug": "false",
"browserstack.idleTimeout": "300",
"browserstack.playwrightVersion": playwrightVersion,
};
// SECURITY NOTE: The wsEndpoint embeds BROWSERSTACK_ACCESS_KEY. Playwright may
// log this URL on connection failure, and trace files (trace: "on-first-retry")
// may include it. Ensure BROWSERSTACK_ACCESS_KEY is marked **secret** in the
// Azure DevOps variable group, and do NOT publish playwright-report/ or
// trace-*.zip as public CI artifacts.
const wsEndpoint = `wss://cdp.browserstack.com/playwright?caps=${encodeURIComponent(JSON.stringify(caps))}`;
// ---------------------------------------------------------------------------
// Per-test-type testMatch patterns
// ---------------------------------------------------------------------------
const testConfigs: Record<string, { testMatch: string | string[] }> = {
webgl2: { testMatch: "**/*webgl2.test.ts" },
webgpu: { testMatch: "**/*webgpu.test.ts" },
interaction: { testMatch: "**/interaction.test.ts" },
performance: { testMatch: "**/test/performance/visualization.test.ts" },
};
const activeConfig = testConfigs[testType];
if (!activeConfig) {
throw new Error(`Unknown BSTACK_TEST_TYPE: "${testType}". Valid values: ${Object.keys(testConfigs).join(", ")}`);
}
// ---------------------------------------------------------------------------
// Reporters
// ---------------------------------------------------------------------------
const baseReporters: any[] = [["line"], ["junit", { outputFile: "junit.xml" }], ["html", { open: "never" }]];
if (isPerformanceRun) {
baseReporters.push(["./packages/tools/tests/performanceSummaryReporter.ts"]);
}
export default defineConfig({
fullyParallel: true,
forbidOnly: true,
retries: 2,
workers: process.env.CIWORKERS && +process.env.CIWORKERS ? +process.env.CIWORKERS : 2,
timeout: isPerformanceRun ? 300_000 : undefined,
reporter: baseReporters,
testMatch: activeConfig.testMatch,
use: {
connectOptions: { wsEndpoint },
trace: "on-first-retry",
ignoreHTTPSErrors: true,
},
snapshotPathTemplate: "packages/tools/tests/test/visualization/ReferenceImages/{arg}{ext}",
});