-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathplaywright.config.ts
More file actions
98 lines (86 loc) · 3.2 KB
/
playwright.config.ts
File metadata and controls
98 lines (86 loc) · 3.2 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
/*
Copyright 2025 New Vector Ltd.
SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
Please see LICENSE files in the repository root for full details.
*/
import { defineConfig, devices, type Project } from "@playwright/test";
import fs, { globSync } from "node:fs";
import path from "node:path";
import type { Options } from "./playwright/element-web-test";
const chromeProject = {
...devices["Desktop Chrome"],
channel: "chromium",
permissions: ["clipboard-write", "clipboard-read", "microphone"],
launchOptions: {
args: ["--use-fake-ui-for-media-stream", "--use-fake-device-for-media-stream", "--mute-audio"],
},
};
/**
We assume that all modules will have the following directory structure:
<repo_root>
└── modules/
└── my-module/
└── element-web/
├── e2e/
│ ├── test-1.spec.ts
│ └── test-2.spec.ts
└── package.json
The following code maps each such module (my-module in the example above) to a separate
playwright project.
*/
const projects: Project<Options>[] = [];
// Get all the directories that hold playwright tests
const moduleTestDirectories = globSync("modules/*/element-web/e2e", {});
// Process each directory
for (const testDirectory of moduleTestDirectories) {
// Based on the directory structure, the parent directory of the test directory holds package.json.
const moduleDirectory = path.join(testDirectory, "..");
// Get module name from package.json
const packageJson = JSON.parse(fs.readFileSync(path.join(moduleDirectory, "package.json"), "utf-8"));
const MODULE_PREFIX = "@element-hq/element-web-module-";
const name = packageJson.name.startsWith(MODULE_PREFIX)
? packageJson.name.slice(MODULE_PREFIX.length)
: packageJson.name;
// Create playwright project
projects.push({
name,
use: {
...chromeProject,
moduleDir: moduleDirectory,
},
testDir: testDirectory,
snapshotDir: `${testDirectory}/snapshots`,
outputDir: `${testDirectory}/_results`,
});
}
const baseURL = process.env["BASE_URL"] ?? "http://localhost:8080";
export default defineConfig<Options>({
projects,
use: {
viewport: { width: 1280, height: 720 },
ignoreHTTPSErrors: true,
video: "retain-on-failure",
baseURL,
trace: "on-first-retry",
},
webServer: {
command: process.env.WEBAPP_PATH
? `npx serve -p 8080 -L ${process.env.WEBAPP_PATH}`
: "docker run --rm -p 8080:80 ghcr.io/element-hq/element-web:develop",
url: `${baseURL}/config.json`,
reuseExistingServer: true,
timeout: (process.env.CI ? 30 : 120) * 1000,
},
workers: 1,
retries: process.env.CI ? 2 : 0,
reporter: process.env.CI
? [
["list"],
["html"],
["github"],
["@element-hq/element-web-playwright-common/lib/stale-screenshot-reporter.js"],
]
: [["list"], ["html", { outputFolder: "playwright-html-report" }]],
snapshotPathTemplate: "{snapshotDir}/{testFilePath}/{arg}-{platform}{ext}",
forbidOnly: !!process.env.CI,
});