Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .github/files/e2e-tests/e2e-matrix.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,14 @@ const projects = [
suite: '',
buildGroup: 'jetpack-protect',
},
{
project: 'mu-wpcom-plugin',
path: 'projects/plugins/mu-wpcom-plugin/tests/e2e',
testArgs: [ 'specs' ],
targets: [ 'plugins/mu-wpcom-plugin' ],
suite: '',
buildGroup: 'jetpack-mu-wpcom-plugin',
},
];

const matrix = [];
Expand Down
27 changes: 27 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: added

Add basic E2E test infrastructure with plugin activation tests
10 changes: 10 additions & 0 deletions projects/plugins/mu-wpcom-plugin/tests/e2e/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/node_modules
/config/local*
/config/tmp/*
/output
plan-data.txt
e2e_tunnels.txt
jetpack-private-options.txt
/allure-results
storage.json
/tmp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = require( '_jetpack-e2e-commons/config/default.cjs' );
3 changes: 3 additions & 0 deletions projects/plugins/mu-wpcom-plugin/tests/e2e/eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { makeE2eConfig } from '_jetpack-e2e-commons/eslint.config.mjs';

export default makeE2eConfig( import.meta.url );
39 changes: 39 additions & 0 deletions projects/plugins/mu-wpcom-plugin/tests/e2e/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"private": true,
"type": "module",
"scripts": {
"allure-report": "allure generate --clean --output ./output/allure-report ./output/allure-results && allure open ./output/allure-report",
"build": "pnpm jetpack build plugins/mu-wpcom-plugin -v --no-pnpm-install --production",
"clean": "rm -rf output",
"config:decrypt": "openssl enc -md sha1 -aes-256-cbc -pbkdf2 -iter 100000 -d -pass env:CONFIG_KEY -in ./node_modules/_jetpack-e2e-commons/config/encrypted.enc -out ./config/local.cjs",
"distclean": "rm -rf node_modules",
"env:down": "e2e-env stop",
"env:reset": "e2e-env reset --activate-plugins jetpack-mu-wpcom-plugin",
"env:up": "e2e-env start --activate-plugins jetpack-mu-wpcom-plugin",
"pretest:run": "pnpm run clean",
"test:run": "playwright install chromium && NODE_CONFIG_DIR='./config' ALLURE_RESULTS_DIR=./output/allure-results NODE_PATH=\"$PWD/node_modules\" playwright test",
"tunnel:down": "tunnel down",
"tunnel:reset": "tunnel reset",
"tunnel:up": "tunnel up",
"typecheck": "tsc --noEmit"
},
"browserslist": [],
"devDependencies": {
"@playwright/test": "1.55.1",
"@types/node": "^20.4.2",
"@wordpress/e2e-test-utils-playwright": "^1.37.0",
"_jetpack-e2e-commons": "workspace:*",
"allure-playwright": "2.15.1",
"config": "4.1.1",
"playwright-ctrf-json-reporter": "^0.0.26",
"typescript": "5.9.3"
},
"ci": {
"targets": [
"plugins/mu-wpcom-plugin",
"tools/e2e-commons"
],
"pluginSlug": "jetpack-mu-wpcom-plugin",
"mirrorName": "jetpack-mu-wpcom-plugin"
}
}
32 changes: 32 additions & 0 deletions projects/plugins/mu-wpcom-plugin/tests/e2e/playwright.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { defineConfig, devices } from '@playwright/test';
import config from 'config';

const baseURL = process.env.WP_BASE_URL || 'http://localhost';

export default defineConfig( {
testDir: './specs',
timeout: 60000,
expect: {
timeout: 10000,
},
fullyParallel: false,
forbidOnly: !! process.env.CI,
retries: process.env.CI ? 1 : 0,
workers: 1,
reporter: [
[ 'list' ],
[ 'json', { outputFile: `${ config.get( 'dirs.output' ) }/summary.json` } ],
],
use: {
baseURL,
trace: 'retain-on-failure',
screenshot: 'only-on-failure',
video: 'retain-on-failure',
},
projects: [
{
name: 'mu-wpcom-plugin e2e',
use: { ...devices[ 'Desktop Chrome' ] },
},
],
} );
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import { test, expect } from '@wordpress/e2e-test-utils-playwright';

test.describe( 'mu-wpcom-plugin', () => {
test( 'Plugin is active and admin is accessible', async ( { page, admin } ) => {
await test.step( 'Visit dashboard page', async () => {
await admin.visitAdminPage( '' );
await expect(
page.getByRole( 'heading', { name: 'Dashboard' } ),
'Dashboard heading should be visible'
).toBeVisible();
} );

await test.step( 'Navigate to plugins page and verify plugin is active', async () => {
await admin.visitAdminPage( 'plugins.php?plugin_status=active&s=jetpack-mu-wpcom' );
await expect(
page.getByRole( 'heading', { name: 'Plugins', level: 1 } ),
'Plugins heading should be visible'
).toBeVisible();

// Target the specific plugin row
const pluginRow = page.locator(
'tr[data-plugin="jetpack-mu-wpcom-plugin/mu-wpcom-plugin.php"]'
);
await expect( pluginRow, 'Plugin row should exist' ).toBeVisible();
await expect(
pluginRow.locator( '.deactivate' ),
'Deactivate link should be present (indicating plugin is active)'
).toBeVisible();
} );
} );

test( 'Admin pages load without errors', async ( { page, admin } ) => {
const consoleLogs: string[] = [];
page.on( 'console', msg => {
if ( msg.type() === 'error' ) {
consoleLogs.push( msg.text() );
}
} );

await test.step( 'Visit dashboard', async () => {
await admin.visitAdminPage( '' );
await expect( page.getByRole( 'heading', { name: 'Dashboard' } ) ).toBeVisible();
} );

await test.step( 'Visit posts page', async () => {
await admin.visitAdminPage( 'edit.php' );
await expect( page.getByRole( 'heading', { name: 'Posts', level: 1 } ) ).toBeVisible();
} );

await test.step( 'Check for console errors', async () => {
const criticalErrors = consoleLogs.filter(
log =>
! log.includes( 'Download the React DevTools' ) &&
! log.includes( 'webpack' ) &&
! log.includes( 'Failed to load resource' )
);
expect(
criticalErrors.length,
`Expected no critical console errors, but found: ${ criticalErrors.join( ', ' ) }`
).toBe( 0 );
} );
} );
} );
3 changes: 3 additions & 0 deletions projects/plugins/mu-wpcom-plugin/tests/e2e/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "_jetpack-e2e-commons/tsconfig.json"
}
13 changes: 8 additions & 5 deletions tools/e2e-commons/bin/e2e-env.sh
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ configure_wp_env() {
$BASE_CMD exec-silent -- chown -R www-data:www-data /var/www/html/wp-content/jetpack-waf
$BASE_CMD wp plugin status

$BASE_CMD wp plugin activate jetpack
# Activate Jetpack plugin if available
$BASE_CMD wp plugin is-installed jetpack && $BASE_CMD wp plugin activate jetpack || true
$BASE_CMD wp plugin activate e2e-direct-filesystem
$BASE_CMD wp plugin activate e2e-plan-helper
$BASE_CMD wp plugin activate e2e-waf-data-interceptor
Expand All @@ -89,11 +90,13 @@ configure_wp_env() {
done
fi
$BASE_CMD wp option set permalink_structure ""
$BASE_CMD wp jetpack module deactivate sso

# Disable modules that may interfere with login flow.
$BASE_CMD wp jetpack module deactivate account-protection
$BASE_CMD wp jetpack module deactivate protect
# Disable Jetpack modules that may interfere with login flow (only if Jetpack is active)
if $BASE_CMD wp plugin is-active jetpack 2>/dev/null; then
$BASE_CMD wp jetpack module deactivate sso
$BASE_CMD wp jetpack module deactivate account-protection
$BASE_CMD wp jetpack module deactivate protect
fi

echo
$BASE_CMD wp plugin status
Expand Down
Loading