Skip to content

Commit 45e0457

Browse files
authored
Merge branch 'production' into fix/PLTFRM-1567-additional-fixes-for-corrupted-roles
2 parents 02fdb30 + c7ceed0 commit 45e0457

43 files changed

Lines changed: 8035 additions & 1 deletion

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/e2e.yml

Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
name: Run e2e tests
2+
on:
3+
pull_request:
4+
workflow_dispatch:
5+
inputs:
6+
wpversion:
7+
description: 'WordPress version to run tests against'
8+
required: false
9+
default: 'latest'
10+
url:
11+
description: 'Alternative Test URL'
12+
required: false
13+
default: ''
14+
user:
15+
description: 'Alternative User Name'
16+
required: false
17+
default: ''
18+
password:
19+
description: 'Alternative Password'
20+
required: false
21+
default: ''
22+
23+
concurrency:
24+
group: ${{ github.workflow }}-${{ github.ref }}
25+
cancel-in-progress: true
26+
27+
permissions:
28+
contents: read
29+
30+
env:
31+
DO_NOT_TRACK: "1"
32+
33+
jobs:
34+
Run_e2e_tests:
35+
name: Run E2E Tests
36+
runs-on: ubuntu-latest
37+
steps:
38+
- name: Harden Runner
39+
uses: step-security/harden-runner@f4a75cfd619ee5ce8d5b864b0d183aff3c69b55a # v2.13.1
40+
with:
41+
egress-policy: block
42+
allowed-endpoints:
43+
1.gravatar.com:443
44+
1.gravatar.com:80
45+
140.82.114.22:443
46+
2.gravatar.com:443
47+
2.gravatar.com:80
48+
api.github.com:443
49+
api.ipify.org:443
50+
api.wordpress.org:443
51+
api.wordpress.org:80
52+
api.wpvip.com:443
53+
auth.docker.io:443
54+
cdn.playwright.dev:443
55+
dl-cdn.alpinelinux.org:443
56+
downloads.wordpress.org:443
57+
e2e-test-site.vipdev.lndo.site:443
58+
geoip.elastic.co:443
59+
ghcr.io:443
60+
github.com:443
61+
nodejs.org:443
62+
objects.githubusercontent.com:443
63+
pkg-containers.githubusercontent.com:443
64+
planet.wordpress.org:443
65+
playwright.azureedge.net:443
66+
playwright.download.prss.microsoft.com:443
67+
production.cloudflare.docker.com:443
68+
public-api.wordpress.com:443
69+
raw.githubusercontent.com:443
70+
registry-1.docker.io:443
71+
registry.npmjs.org:443
72+
s.w.org:443
73+
s0.wp.com:443
74+
secure.gravatar.com:443
75+
storage.googleapis.com:443
76+
update.traefik.io:443
77+
vaultpress.com:443
78+
wordpress.org:443
79+
80+
- name: Check out repository code
81+
uses: actions/checkout@v5.0.0
82+
83+
- name: Setup Node
84+
uses: actions/setup-node@v6.0.0
85+
with:
86+
node-version: 'lts/*'
87+
cache: npm
88+
cache-dependency-path: tests/e2e/package-lock.json
89+
90+
- name: Install dependencies
91+
run: npm ci
92+
working-directory: tests/e2e
93+
94+
- name: Install Playwright with Chromium
95+
run: npx playwright install chromium
96+
working-directory: tests/e2e
97+
98+
- name: Install VIP CLI
99+
run: npm install -g @automattic/vip
100+
101+
- name: Determine WP version
102+
run: |
103+
if [ -z "${{ github.event.inputs.wpversion }}" ]; then
104+
echo "WORDPRESS_VERSION=latest" >> $GITHUB_ENV
105+
else
106+
echo "WORDPRESS_VERSION=${{ github.event.inputs.wpversion }}" >> $GITHUB_ENV
107+
fi
108+
109+
- name: Setup test env variables
110+
if: ${{ github.event.inputs.url != '' }}
111+
run: |
112+
echo "E2E_BASE_URL=${{ github.event.inputs.url }}" >> $GITHUB_ENV
113+
echo "E2E_USER=${{ github.event.inputs.user }}" >> $GITHUB_ENV
114+
echo "E2E_PASSWORD=${{ github.event.inputs.password }}" >> $GITHUB_ENV
115+
116+
- name: Run e2e tests
117+
run: npm test
118+
working-directory: tests/e2e
119+
120+
- name: Archive test results
121+
uses: actions/upload-artifact@v4
122+
if: failure()
123+
with:
124+
name: test-results
125+
path: |
126+
tests/e2e/test-results
127+
tests/e2e/screenshots
128+
129+
lint_e2e:
130+
name: Run ESLint on E2E tests
131+
runs-on: ubuntu-latest
132+
steps:
133+
- name: Harden Runner
134+
uses: step-security/harden-runner@f4a75cfd619ee5ce8d5b864b0d183aff3c69b55a # v2.13.1
135+
with:
136+
egress-policy: audit
137+
138+
- name: Check out repository code
139+
uses: actions/checkout@v5.0.0
140+
141+
- name: Setup Node
142+
uses: actions/setup-node@v6.0.0
143+
with:
144+
node-version: 'lts/*'
145+
cache: npm
146+
cache-dependency-path: tests/e2e/package-lock.json
147+
148+
- name: Install dependencies
149+
run: npm ci
150+
working-directory: tests/e2e
151+
152+
- name: Run ESLint
153+
run: npm run lint
154+
working-directory: tests/e2e

docs/setup.md

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,53 @@ You'll need the VIP-CLI to create a local development environment to test this l
99
### Setup
1010

1111
Run `vip dev-env create` to create a new development environment.
12-
Once the environment has been created, you can start it with `vip dev-env start`.
12+
Once the environment has been created, you can start it with `vip dev-env start`.
13+
14+
## End-to-End Tests
15+
16+
The Playwright suite lives under `tests/e2e` and depends on a disposable VIP dev-env site. The npm scripts in that directory will provision the environment, run the tests, and tear everything down.
17+
18+
### Requirements
19+
20+
- VIP CLI with access to create local environments (`vip dev-env ...`).
21+
- Node.js 20 (run `nvm use` against `tests/e2e/.nvmrc`).
22+
- Playwright browsers (the install step below handles this).
23+
24+
### One-time install
25+
26+
```bash
27+
cd tests/e2e
28+
nvm use
29+
npm install
30+
npx playwright install --with-deps
31+
```
32+
33+
The initial install downloads the Playwright browsers and ensures the CLI has the required dependencies.
34+
35+
### Running the full suite
36+
37+
Run the tests from the `tests/e2e` directory so the relative paths in the config resolve correctly:
38+
39+
```bash
40+
cd tests/e2e
41+
npx playwright test -c playwright.config.ts
42+
```
43+
44+
The Playwright config uses `lib/global-setup.ts` to sign in as `vipgo` and saves the session in `e2eStorageState.json`. Tests that need to clear WordPress sessions opt-in to their own storage state so the shared admin login remains available to the rest of the suite.
45+
46+
`package.json` wires `npm test` to the same command and includes a `pretest` hook (`bin/setup-env.sh`) that creates a fresh site at the `e2e-sb-test-site` slug and a `posttest` hook that destroys it. If you stop the run early, clean up manually with:
47+
48+
```bash
49+
vip dev-env destroy --slug=e2e-sb-test-site
50+
```
51+
52+
### Running individual specs
53+
54+
To focus on a single spec, pass the relative path after the config:
55+
56+
```bash
57+
cd tests/e2e
58+
npx playwright test -c playwright.config.ts specs/highlight-mfa-users.spec.ts
59+
```
60+
61+
The global setup still runs so the test inherits the signed-in state.

phpstan.neon

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ parameters:
1010
- email
1111
- class-loader.php
1212
- vip-security-boost.php
13+
excludePaths:
14+
- %rootDir%/../../../tests/e2e
1315
scanDirectories:
1416
- mu-plugins
1517
scanFiles:

tests/e2e/.eslintrc.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
require( '@automattic/eslint-plugin-wpvip/init' );
2+
3+
module.exports = {
4+
parserOptions: {
5+
ecmaVersion: 2021,
6+
project: [__dirname + "/tsconfig.json"],
7+
},
8+
extends: [
9+
'plugin:@automattic/wpvip/recommended',
10+
'plugin:playwright/playwright-test',
11+
'plugin:deprecation/recommended',
12+
],
13+
ignorePatterns: [ 'bin/**/*', '*.js' ],
14+
rules: {
15+
'@typescript-eslint/no-non-null-assertion': 'off',
16+
},
17+
root: true,
18+
};

tests/e2e/.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
/e2eStorageState.json
2+
/node_modules/
3+
/test-results/

tests/e2e/.nvmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
20

tests/e2e/.prettierrc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
arrowParens: 'avoid',
2+
bracketSpacing: true
3+
parenSpacing: true
4+
printWidth: 100
5+
semi: true
6+
singleQuote: true
7+
trailingComma: 'es5'
8+
useTabs: true

tests/e2e/README.md

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
# End to End (e2e) Tests for VIP Go MU Plugins
2+
3+
This is a set of tests to run against VIP test sites. They are written in Typescript and use [Playwright](https://playwright.dev/) as the test framework and runner
4+
<br />
5+
<br />
6+
## Setup Env
7+
8+
These tests require that NodeJS and NPM be installed
9+
<br />
10+
<br />
11+
If using the e2e test environment, you will also need to install the [VIP CLI](https://docs.wpvip.com/technical-references/vip-cli/installing-vip-cli/)
12+
<br />
13+
<br />
14+
To start the e2e test environment, from the `vip-go-mu-plugins` root run:
15+
16+
`npm run setup-e2e-env`
17+
<br />
18+
<br />
19+
This will start up a test environment running locally to run the tests against.
20+
<br />
21+
<br />
22+
If using this test environment, you only need to start it once and then you can keep running tests against it until you're done or need to change the configuration.
23+
<br />
24+
<br />
25+
When you're done, you can tear down the environment using:
26+
27+
`npm run destroy-e2e-env`
28+
<br />
29+
<br />
30+
<br />
31+
32+
### Optional Environment Configuration
33+
<br />
34+
To start e2e environment with a specific version of WordPress:
35+
36+
`npm run setup-e2e-env -- -v 5.9-beta1`
37+
<br />
38+
<br />
39+
To start e2e environment with custom client code:
40+
41+
`npm run setup-e2e-env -- -c pathToClientCode`
42+
<br />
43+
<br />
44+
To start e2e environment with a custom set of MU plugins:
45+
46+
`npm run setup-e2e-env -- -p pathToMUPlugins`
47+
48+
<br />
49+
<br />
50+
<br />
51+
52+
## Run tests
53+
To run the tests against the default environment:
54+
55+
`npm run test-e2e`
56+
<br />
57+
<br />
58+
To run against different environments, you'll need to set these environment variables before starting the tests
59+
<br />
60+
<br />
61+
| Environment Variable | Description |
62+
| -------------------- | ------------------------------------------- |
63+
| E2E_BASE_URL | Url to the environment to run tests against |
64+
| E2E_USER | User name to run tests with |
65+
| E2E_PASSWORD | Password to run tests with |
66+
67+
<br />
68+
<br />
69+
Example:
70+
71+
`E2E_BASE_URL=https://mytestsite.local E2E_USER=myuser E2E_PASSWORD=mypassword npm run test-e2e`

0 commit comments

Comments
 (0)