Repository navigation
Expand file tree
/
Copy pathplaywright.config.js
More file actions
128 lines (111 loc) · 4.79 KB
/
Copy pathplaywright.config.js
File metadata and controls
128 lines (111 loc) · 4.79 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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
/*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
import { existsSync, readdirSync } from "node:fs";
import { defineConfig } from "@playwright/test";
import { expectedTests } from "./tests/manifests/suites.js";
if (Object.prototype.hasOwnProperty.call(process.env, "NO_COLOR")) { delete process.env.NO_COLOR; process.env.FORCE_COLOR = "0"; }
const PORT = 4173;
const BASE_URL = `http://127.0.0.1:${PORT}`;
const browserName = process.env.WASMGPU_BROWSER ?? "chromium";
const supportedBrowsers = new Set(["chromium", "firefox", "webkit"]);
if (!supportedBrowsers.has(browserName)) throw new Error(`Unsupported WASMGPU_BROWSER: ${browserName}`);
const forceFallbackAdapter = process.env.WASMGPU_FORCE_FALLBACK_ADAPTER === "1";
if (forceFallbackAdapter && browserName !== "firefox") throw new Error("WASMGPU_FORCE_FALLBACK_ADAPTER is only supported for Firefox.");
const headless = browserName !== "firefox" || process.platform === "linux";
const requestedProjects = process.argv.flatMap((argument, index, arguments_) => {
if (argument === "--project") return [arguments_[index + 1]];
if (argument.startsWith("--project=")) return [argument.slice("--project=".length)];
return [];
});
const lifecycleSuites = new Map([
["test:setup", "setup"],
["test:js", "javascript"],
["test:js:headed", "javascript"],
["test:js:debug", "javascript"],
["test:ex", "examples"]
]);
const reportSuite = lifecycleSuites.get(process.env.npm_lifecycle_event) ?? (requestedProjects.length === 1 && requestedProjects[0] === "setup" ? "setup" : requestedProjects.includes("examples") && !requestedProjects.includes("runner") ? "examples" : requestedProjects.length ? "javascript" : "all");
const findLavapipeICD = () => {
const directory = "/usr/share/vulkan/icd.d", preferred = `${directory}/lvp_icd.json`;
if (existsSync(preferred)) return preferred;
if (!existsSync(directory)) return null;
const filename = readdirSync(directory).filter((name) => /^lvp_icd.*\.json$/.test(name)).sort()[0];
return filename ? `${directory}/${filename}` : null;
};
const launchOptions = {};
if (browserName === "chromium") {
const args = [
"--enable-unsafe-webgpu",
"--disable-dawn-features=use_dxc",
"--use-gpu-in-tests",
"--enable-accelerated-2d-canvas"
];
if (process.platform === "linux") {
const lavapipeICD = process.env.VK_DRIVER_FILES ?? findLavapipeICD();
if (!lavapipeICD) throw new Error("Lavapipe Vulkan ICD was not found. Install mesa-vulkan-drivers or set VK_DRIVER_FILES.");
args.push(
"--enable-features=Vulkan",
"--use-angle=vulkan",
"--use-vulkan=native"
);
launchOptions.env = { ...process.env, VK_DRIVER_FILES: lavapipeICD, LIBGL_ALWAYS_SOFTWARE: "1" };
} else {
args.push(
"--use-webgpu-adapter=swiftshader"
);
if (process.platform === "darwin" && process.arch === "x64") args.push(
"--use-gl=angle",
"--use-angle=swiftshader"
);
}
launchOptions.args = args;
} else if (browserName === "firefox") {
launchOptions.firefoxUserPrefs = {
"dom.webgpu.enabled": true
};
}
export default defineConfig({
testDir: "./tests/manifests",
testMatch: "**/*.spec.js",
fullyParallel: false,
workers: 1,
timeout: 120_000,
expect: { timeout: 5_000 },
retries: process.env.CI ? 1 : 0,
retryStrategy: "isolated",
reporter: [
["line"],
["html", { open: "never", outputFolder: `./playwright-report/${reportSuite}` }],
["blob", { outputDir: `./blob-report/${reportSuite}` }],
["./scripts/merge-test-reports.js", { expectedTests: expectedTests[reportSuite], outputFile: `./blob-report/${reportSuite}/run.json`, suite: reportSuite }]
],
outputDir: `./test-results/${reportSuite}`,
projects: [
{ name: "setup", testMatch: "setup.spec.js" },
{ name: "runner", testMatch: "runner.spec.js" },
{ name: "examples", testMatch: "examples.spec.js" }
],
use: {
baseURL: BASE_URL,
browserName,
...(browserName === "chromium" ? { channel: "chromium" } : {}),
headless,
viewport: { width: 1280, height: 720 },
deviceScaleFactor: 1,
trace: "retain-on-failure",
screenshot: "only-on-failure",
launchOptions
},
webServer: {
command: `node ./scripts/serve-tests.js --port ${PORT}`,
gracefulShutdown: { signal: "SIGTERM", timeout: 500 },
url: `${BASE_URL}/tests/index.html`,
reuseExistingServer: !process.env.CI,
timeout: 30_000,
stdout: "ignore",
stderr: "pipe"
}
});