Skip to content

Commit a14fabd

Browse files
authored
Protect: Add E2E Tests (#42197)
1 parent 0e45bba commit a14fabd

File tree

10 files changed

+137
-2
lines changed

10 files changed

+137
-2
lines changed

.github/files/e2e-tests/e2e-matrix.js

+8
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,14 @@ const projects = [
122122
suite: '',
123123
buildGroup: 'jetpack-social',
124124
},
125+
{
126+
project: 'Protect',
127+
path: 'projects/plugins/protect/tests/e2e',
128+
testArgs: [],
129+
targets: [ 'plugins/protect' ],
130+
suite: '',
131+
buildGroup: 'jetpack-protect',
132+
},
125133
];
126134

127135
const matrix = [];

pnpm-lock.yaml

+15
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Significance: minor
2+
Type: added
3+
4+
Add E2E tests.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/node_modules
2+
/config/local*
3+
/config/tmp/*
4+
/output
5+
plan-data.txt
6+
e2e_tunnels.txt
7+
jetpack-private-options.txt
8+
/allure-results
9+
storage.json
10+
/tmp
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = require( '_jetpack-e2e-commons/config/default.cjs' );
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import { makeE2eConfig } from '_jetpack-e2e-commons/eslint.config.mjs';
2+
3+
export default [ ...makeE2eConfig( import.meta.url ) ];
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
{
2+
"private": true,
3+
"type": "module",
4+
"description": "Security tools that keep your site safe and sound, from posts to plugins.",
5+
"homepage": "https://jetpack.com",
6+
"bugs": {
7+
"url": "https://github.com/Automattic/jetpack/labels/[Plugin] Protect"
8+
},
9+
"repository": {
10+
"type": "git",
11+
"url": "https://github.com/Automattic/jetpack.git",
12+
"directory": "projects/plugins/protect"
13+
},
14+
"license": "GPL-2.0-or-later",
15+
"author": "Automattic",
16+
"scripts": {
17+
"build": "pnpm jetpack build packages/assets packages/connection plugins/protect plugins/jetpack -v --no-pnpm-install --production",
18+
"clean": "rm -rf output",
19+
"config:decrypt": "openssl enc -md sha1 -aes-256-cbc -d -pass env:CONFIG_KEY -in ./node_modules/_jetpack-e2e-commons/config/encrypted.enc -out ./config/local.cjs",
20+
"distclean": "rm -rf node_modules",
21+
"env:up": "e2e-env start --activate-plugins protect",
22+
"env:down": "e2e-env stop",
23+
"env:reset": "e2e-env reset --activate-plugins protect",
24+
"tunnel:up": "tunnel up",
25+
"tunnel:reset": "tunnel reset",
26+
"tunnel:down": "tunnel down",
27+
"pretest:run": "pnpm run clean",
28+
"test:run": ". ./node_modules/_jetpack-e2e-commons/bin/app-password.sh && playwright install --with-deps chromium && NODE_CONFIG_DIR='./config' ALLURE_RESULTS_DIR=./output/allure-results NODE_PATH=\"$PWD/node_modules\" playwright test --config=./playwright.config.mjs"
29+
},
30+
"devDependencies": {
31+
"@playwright/test": "1.48.2",
32+
"allure-playwright": "2.9.2",
33+
"config": "3.3.12",
34+
"_jetpack-e2e-commons": "workspace:*"
35+
},
36+
"browserslist": [],
37+
"ci": {
38+
"targets": [
39+
"plugins/protect",
40+
"tools/e2e-commons"
41+
],
42+
"pluginSlug": "protect",
43+
"mirrorName": "jetpack-protect-plugin"
44+
}
45+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { default } from '_jetpack-e2e-commons/config/playwright.config.default.mjs';
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import { prerequisitesBuilder } from '_jetpack-e2e-commons/env/prerequisites.js';
2+
import { expect, test } from '_jetpack-e2e-commons/fixtures/base-test.js';
3+
import logger from '_jetpack-e2e-commons/logger.js';
4+
5+
test.describe( 'Jetpack Protect plugin', () => {
6+
test.beforeEach( async ( { page } ) => {
7+
await prerequisitesBuilder( page )
8+
.withCleanEnv()
9+
.withActivePlugins( [ 'protect' ] )
10+
.withLoggedIn( true )
11+
.build();
12+
} );
13+
14+
test( 'Jetpack Protect admin page', async ( { page, admin } ) => {
15+
logger.action( 'Visit the Jetpack Protect admin page and start for free' );
16+
17+
await admin.visitAdminPage( 'admin.php', 'page=jetpack-protect' );
18+
19+
logger.action( 'Checking for button "Get Jetpack Protect"' );
20+
const getJetpackProtectButton = page.getByRole( 'button', { name: 'Get Jetpack Protect' } );
21+
await expect( getJetpackProtectButton ).toBeVisible();
22+
await expect( getJetpackProtectButton ).toBeEnabled();
23+
24+
logger.action( 'Checking for button "Start for free"' );
25+
const startForFreeButton = page.getByRole( 'button', { name: 'Start for free' } );
26+
await expect( startForFreeButton ).toBeVisible();
27+
await expect( startForFreeButton ).toBeEnabled();
28+
29+
logger.action( 'Click the start for free button' );
30+
await startForFreeButton.click();
31+
32+
logger.action( 'Checking for heading "Stay one step ahead of threats"' );
33+
await expect(
34+
page.getByRole( 'heading', { name: 'Stay one step ahead of threats' } )
35+
).toBeVisible();
36+
} );
37+
} );

tools/e2e-commons/README.md

+13-2
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,22 @@ Update `tests/e2e/package.json` to match your plugin description. Also, review `
4747

4848
### Update PNPM workspace definitions
4949

50-
For monorepo to pick up additional dependencies in `e2e` folder, it should be added into `pnpm-workspace.yaml` definitions. Add `'projects/plugins/YOUR-PLUGIN/tests/e2e'` into the file.
50+
For monorepo to pick up additional dependencies in `e2e` folder, ensure that it is included in `pnpm-workspace.yaml` package definitions. By default, the workspace file will automatically include your project if it follows the `'projects/plugins/YOUR-PLUGIN/tests/e2e'` naming convention.
5151

5252
### Add your plugin tests into CI pipeline
5353

54-
In `.github/files/create-e2e-projects-matrix.sh` we define list of E2E projects to run tests for. Add your plugin into `PROJECTS` list as follows: `'{"project":"PLUGIN NAME","path":"projects/plugins/YOUR-PLUGIN/tests/e2e","testArgs":[],"slackArgs":[]}`. Be aware of spaces between entries.
54+
In `.github/files/e2e-tests/e2e-matrix.js` we define list of E2E projects to run tests for. Add your plugin into `projects` list as follows:
55+
56+
```javascript
57+
{
58+
project: 'PLUGIN NAME',
59+
path: 'projects/plugins/YOUR-PLUGIN/tests/e2e',
60+
testArgs: [],
61+
targets: [ 'plugins/jetpack' ],
62+
suite: '',
63+
buildGroup: 'jetpack-core',
64+
}
65+
```
5566

5667
### Run the tests
5768

0 commit comments

Comments
 (0)