Skip to content

Commit a210d3c

Browse files
authored
Merge pull request #33088 from element-hq/t3chguy/monorepo-playwright-common
Absorb remainder of playwright-common from element-modules
2 parents 4186b8e + 1096ca2 commit a210d3c

40 files changed

Lines changed: 3658 additions & 81 deletions

.github/workflows/build-and-test.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ jobs:
163163
- name: Run Playwright tests
164164
working-directory: apps/web
165165
run: |
166-
pnpm playwright test \
166+
pnpm test:playwright \
167167
--shard "$SHARD" \
168168
--project="${{ matrix.project }}" \
169169
${{ (github.event_name == 'pull_request' && matrix.runAllTests == false ) && '--grep-invert @mergequeue' || '' }}

apps/web/package.json

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@
3030
"lint:types": "nx lint:types",
3131
"lint:style": "stylelint \"res/css/**/*.pcss\"",
3232
"test": "nx test:unit",
33-
"test:playwright": "playwright test",
34-
"test:playwright:open": "pnpm test:playwright --ui",
35-
"test:playwright:screenshots": "playwright-screenshots-experimental pnpm playwright test --update-snapshots --project=Chrome --grep @screenshot",
33+
"test:playwright": "nx test:playwright --",
34+
"test:playwright:open": "nx test:playwright -- --ui",
35+
"test:playwright:screenshots": "nx test:playwright:screenshots --",
3636
"coverage": "pnpm test --coverage",
3737
"analyse:webpack-bundles": "webpack-bundle-analyzer webpack-stats.json webapp"
3838
},
@@ -127,8 +127,7 @@
127127
"@babel/preset-typescript": "^7.12.7",
128128
"@casualbot/jest-sonar-reporter": "2.5.0",
129129
"@element-hq/element-call-embedded": "0.18.0",
130-
"@element-hq/element-web-playwright-common": "catalog:",
131-
"@element-hq/element-web-playwright-common-local": "workspace:*",
130+
"@element-hq/element-web-playwright-common": "workspace:*",
132131
"@fetch-mock/jest": "^0.2.20",
133132
"@jest/globals": "^30.2.0",
134133
"@peculiar/webcrypto": "^1.4.3",

apps/web/project.json

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
"parallel": false,
4545
"cwd": "apps/web"
4646
},
47-
"dependsOn": ["^build"]
47+
"dependsOn": ["^build", "^build:playwright"]
4848
},
4949
"test:unit": {
5050
"executor": "@nx/jest:jest",
@@ -53,6 +53,16 @@
5353
"cwd": "apps/web"
5454
},
5555
"dependsOn": ["^build"]
56+
},
57+
"test:playwright": {
58+
"command": "playwright test",
59+
"options": { "cwd": "apps/web" },
60+
"dependsOn": ["^build:playwright"]
61+
},
62+
"test:playwright:screenshots": {
63+
"command": "playwright-screenshots nx test:playwright --update-snapshots --project=Chrome --grep @screenshot",
64+
"options": { "cwd": "apps/web" },
65+
"dependsOn": ["^build:playwright"]
5666
}
5767
}
5868
}

knip.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,9 @@ process.env.GITHUB_ACTIONS = "1";
55

66
export default {
77
workspaces: {
8-
"packages/shared-components": {
9-
ignoreDependencies: [
10-
// Used for vitest browser tests
11-
"@playwright/test",
12-
],
13-
},
8+
"packages/shared-components": {},
149
"packages/playwright-common": {
10+
entry: ["src/fixtures/index.ts", "src/testcontainers/index.ts"],
1511
ignoreDependencies: [
1612
// Used in playwright-screenshots.sh
1713
"wait-on",

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
"devDependencies": {
2828
"@action-validator/cli": "^0.6.0",
2929
"@action-validator/core": "^0.6.0",
30-
"@element-hq/element-web-playwright-common": "catalog:",
3130
"@nx-tools/nx-container": "^7.2.1",
3231
"@nx/jest": "^22.5.0",
3332
"@playwright/test": "catalog:",
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
lib/

packages/playwright-common/README.md

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
11
# @element-hq/element-web-playwright-common
22

3-
Set of Playwright utilities to make it easier to write tests for Element Web, Element Web Modules & Element Desktop.
3+
Set of Playwright & testcontainers utilities to make it easier to write tests for Element Web, Element Web Modules & Element Desktop.
44

5-
# This is a partial clone of https://github.com/element-hq/element-modules/tree/main/packages/element-web-playwright-common
5+
The main export includes a number of fixtures and custom assertions as documented in JSDoc.
66

7-
In the future the rest of the package will be brought into this monorepo, for now it serves as an experimental alternative to https://github.com/element-hq/element-modules/pull/188
7+
The `lib/testcontainers` export contains the following modules:
8+
9+
- `SynapseContainer` - A testcontainer for running a Synapse server
10+
- `MatrixAuthenticationServiceContainer` - A testcontainer for running a Matrix Authentication Service
11+
- `MailpitContainer` - A testcontainer for running a Mailpit SMTP server
12+
13+
There are a number of utils available in the `lib/utils` export.
814

915
## Releases
1016

packages/playwright-common/package.json

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"name": "@element-hq/element-web-playwright-common-local",
2+
"name": "@element-hq/element-web-playwright-common",
33
"type": "module",
44
"version": "3.0.0",
55
"license": "SEE LICENSE IN README.md",
@@ -12,10 +12,34 @@
1212
"engines": {
1313
"node": ">=20.0.0"
1414
},
15+
"main": "lib/index.js",
16+
"types": "lib/index.d.ts",
1517
"bin": {
16-
"playwright-screenshots-experimental": "playwright-screenshots.sh"
18+
"playwright-screenshots": "playwright-screenshots.sh"
19+
},
20+
"scripts": {
21+
"prepack": "nx build:playwright",
22+
"lint:types": "tsc --noEmit"
1723
},
1824
"devDependencies": {
25+
"@element-hq/element-web-module-api": "*",
26+
"@types/lodash-es": "^4.17.12",
27+
"typescript": "^5.8.2",
1928
"wait-on": "^9.0.4"
29+
},
30+
"dependencies": {
31+
"@axe-core/playwright": "^4.10.1",
32+
"@testcontainers/postgresql": "^11.0.0",
33+
"glob": "^13.0.5",
34+
"lodash-es": "^4.17.23",
35+
"mailpit-api": "^1.2.0",
36+
"strip-ansi": "^7.1.0",
37+
"testcontainers": "^11.0.0",
38+
"yaml": "^2.7.0"
39+
},
40+
"peerDependencies": {
41+
"@element-hq/element-web-module-api": "*",
42+
"@playwright/test": "catalog:",
43+
"playwright-core": "catalog:"
2044
}
2145
}

packages/playwright-common/project.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,13 @@
33
"projectType": "library",
44
"root": "packages/playwright-common",
55
"targets": {
6+
"build:playwright": {
7+
"cache": true,
8+
"command": "tsc",
9+
"inputs": ["src"],
10+
"outputs": ["{projectRoot}/lib"],
11+
"options": { "cwd": "packages/playwright-common" }
12+
},
613
"docker:prebuild": {
714
"cache": true,
815
"command": "echo PLAYWRIGHT_VERSION=$(pnpm --silent -- playwright --version | awk '{print $2}') > .env.docker:build",
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/*
2+
Copyright 2024-2025 New Vector Ltd.
3+
Copyright 2024 The Matrix.org Foundation C.I.C.
4+
5+
SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
6+
Please see LICENSE files in the repository root for full details.
7+
*/
8+
9+
declare module "playwright-core/lib/utils" {
10+
// This type is not public in playwright-core utils
11+
export function sanitizeForFilePath(filePath: string): string;
12+
}

0 commit comments

Comments
 (0)