Skip to content
Closed
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
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
7 changes: 6 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/config/wp.config.ts
/config/plugin.config.ts
/node_modules
/artifacts
/plugin/*.zip
Expand All @@ -13,4 +14,8 @@
.DS_Store
.idea
backstop.json
/temp
/temp
/.tmp-plugin-build

#Ignore insiders AI rules
.github/instructions/codacy.instructions.md
20 changes: 14 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,17 @@ E2E tests here are written with Playwright. Without further ado, let's meet belo
## Requirements
- Do you still not have node installed? You'll be needing it.
- Some tests don't come easy with just Playwright, so you need to install the [helper plugin](https://github.com/wp-media/wp-rocket-e2e-test-helper) on your test site. just download the zip from the repo.
- You also need zip files of WP Rocket, I'll explain:
- zip for new release - **rename the zip file name to `new_release.zip`. e.g `wp-rocket_3.13.1.zip` becomes `new_release.zip`**
- zip for previous stable release - **rename the zip file name to `previous_stable`. e.g `wp-rocket_3.13.0.2.zip becomes `previous_stable.zip`**
- zip for 3.10.9 - **leave this as `wp-rocket_3.10.9.zip`**
- Make sure to put these files in the `./plugin` folder in the root - Playwright will pick these files when needed and use them during tests.
- **WP Rocket plugin versions are now automatically managed!** 🎉
- Configure which versions to use in `config/plugin.config.ts`
- The test suite will automatically download/build the required versions
- Manual setup is no longer required unless you want to customize versions

**NB:** Files like the new release and previous stable release are not constant so make sure to always update as your tests fit.
**Optional manual management:**
- `npm run plugin:setup` - Download/build all configured versions
- `npm run plugin:list` - List all plugin files and their status
- `npm run plugin:clean` - Remove all plugin files
- `npm run plugin:validate` - Check if all required files exist
- `npm run plugin:setup -- --force` - Force rebuild even if files exist

## Installation
- Clone this repo
Expand All @@ -26,6 +30,10 @@ E2E tests here are written with Playwright. Without further ado, let's meet belo

You can find this [here](https://github.com/wp-media/wp-rocket-e2e/blob/trunk/config/wp.config.sample.ts)

### Plugin Version Configuration

Copy `config/plugin.config.sample.ts` to `config/plugin.config.ts` and configure which WP Rocket versions to use for testing. See the sample file for detailed examples and configuration options.

## Running Tests
- Don't forget to install the [helper plugin](https://github.com/wp-media/wp-rocket-e2e-test-helper)
- To run tests on playwright, simply run `npx playwright test` or `npm run test:e2e` which ever you prefer.
Expand Down
110 changes: 110 additions & 0 deletions config/plugin.config.sample.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
/**
* @fileoverview
* Plugin version configuration sample for WP Rocket E2E tests.
* Copy this file to plugin.config.ts and update with your desired versions.
*
* The plugin manager will automatically download or build the specified versions
* if they are not already present in the plugin/ directory.
*/

export interface PluginVersionConfig {
/**
* Previous stable release version.
* This will be used for upgrade/downgrade tests.
*
* Can be:
* - A version number (e.g., '3.16.0') - will download from WP Rocket releases
* - A GitHub branch name prefixed with 'branch:' (e.g., 'branch:release/3.16.0')
* - A GitHub tag prefixed with 'tag:' (e.g., 'tag:3.16.0')
* - A URL pointing to a zip file
*/
previousStable: string;

/**
* New release version.
* This is the main version being tested.
*
* Can be:
* - A version number (e.g., '3.16.1') - will download from WP Rocket releases
* - A GitHub branch name prefixed with 'branch:' (e.g., 'branch:develop')
* - A GitHub tag prefixed with 'tag:' (e.g., 'tag:3.16.1')
* - A URL pointing to a zip file
*/
newRelease: string;

/**
* Specific version for rollback/upgrade tests (currently 3.10.9).
* This version is used for specific test scenarios.
*
* Can be:
* - A version number (e.g., '3.10.9') - will download from WP Rocket releases
* - A GitHub branch name prefixed with 'branch:' (e.g., 'branch:release/3.10.9')
* - A GitHub tag prefixed with 'tag:' (e.g., 'tag:3.10.9')
* - A URL pointing to a zip file
*/
specificVersion?: string;

/**
* GitHub repository information for building from branches.
* Only required if using branch: or tag: prefixes.
*/
repository?: {
owner: string;
name: string;
/**
* Personal Access Token for GitHub API (if needed for private repos or rate limits).
* Can also be set via GITHUB_TOKEN environment variable.
*/
token?: string;
};
}

/**
* Plugin version configuration.
*
* @example
* // Using version numbers (will download from releases)
* export const pluginConfig: PluginVersionConfig = {
* previousStable: '3.16.0',
* newRelease: '3.16.1',
* specificVersion: '3.10.9',
* };
*
* @example
* // Using GitHub branches
* export const pluginConfig: PluginVersionConfig = {
* previousStable: 'branch:release/3.16.0',
* newRelease: 'branch:develop',
* specificVersion: '3.10.9',
* repository: {
* owner: 'wp-media',
* name: 'wp-rocket',
* token: process.env.GITHUB_TOKEN
* }
* };
*
* @example
* // Using direct URLs
* export const pluginConfig: PluginVersionConfig = {
* previousStable: 'https://example.com/wp-rocket-3.16.0.zip',
* newRelease: 'https://example.com/wp-rocket-3.16.1.zip',
* specificVersion: '3.10.9',
* };
*/
export const pluginConfig: PluginVersionConfig = {
// Configure the versions you want to test here
previousStable: '3.20.1', // Previous stable version

// NOTE: Pre-release (beta) versions like '3.20.2-beta5' may not be available at the standard release URL.
// If you need to test a beta version, use a direct URL or a GitHub tag/branch instead (see examples above).
newRelease: '3.20.2', // Latest stable version to test

specificVersion: '3.10.9', // Specific version for rollback tests

// Optional: Configure GitHub repository for branch-based builds
repository: {
owner: 'wp-media',
name: 'wp-rocket',
token: process.env.GITHUB_TOKEN,
}
};
7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,16 @@
"test:performancehints": "$npm_package_config_testCommand --tags @performancehints",
"healthcheck": "ts-node healthcheck.ts",
"push-report": "ts-node report.ts",
"open-report": "open ./test-results/cucumber-report.html",
"wp-env": "wp-env",
"test:bwpupstorage": "$npm_package_config_testCommand --tags @bwpupstorage",
"test:bwpuponboarding": "$npm_package_config_testCommand --tags @bwpuponboarding",
"test:bwpupsmoke": "$npm_package_config_testCommand --tags @bwpupsmoke",
"test:bwpup": "$npm_package_config_testCommand --tags @bwpup"
"test:bwpup": "$npm_package_config_testCommand --tags @bwpup",
"plugin:setup": "ts-node plugin-manager-cli.ts setup",
"plugin:list": "ts-node plugin-manager-cli.ts list",
"plugin:clean": "ts-node plugin-manager-cli.ts clean",
"plugin:validate": "ts-node plugin-manager-cli.ts validate"
},
"repository": {
"type": "git",
Expand Down
95 changes: 95 additions & 0 deletions plugin-manager-cli.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
#!/usr/bin/env node

/**
* @fileoverview
* CLI tool for managing WP Rocket plugin versions for E2E tests.
*
* Usage:
* npm run plugin:setup - Setup all configured plugin versions
* npm run plugin:setup -- --force - Force rebuild/re-download even if files exist
* npm run plugin:list - List all plugin files and their status
* npm run plugin:clean - Remove all plugin files
* npm run plugin:validate - Check if all required plugin files exist
*/

import { setupPluginVersions, listPluginFiles, cleanPluginFiles, validatePluginFiles } from './utils/plugin-manager';

const args = process.argv.slice(2);
const command = args[0] || 'setup';
const force = args.includes('--force') || args.includes('-f');

async function main(): Promise<void> {
try {
switch (command) {
case 'setup':
await setupPluginVersions(force);
break;

case 'list':
await listPluginFiles();
break;

case 'clean':
await cleanPluginFiles();
break;

case 'validate': {
const isValid = await validatePluginFiles();
if (isValid) {
console.log('✅ All required plugin files are present\n');
process.exit(0);
} else {
console.log('❌ Some required plugin files are missing\n');
console.log('Run "npm run plugin:setup" to download/build them.\n');
process.exit(1);
}
break;
}

case 'help':
case '--help':
case '-h':
printHelp();
break;

default:
console.error(`Unknown command: ${command}`);
printHelp();
process.exit(1);
}
} catch (error) {
const errorMessage = error instanceof Error ? error.message : String(error);
console.error('Error:', errorMessage);
process.exit(1);
}
}

function printHelp(): void {
console.log(`
WP Rocket Plugin Manager

Usage: npm run plugin:<command> [options]

Commands:
setup Setup all configured plugin versions
list List all plugin files and their status
clean Remove all plugin files
validate Check if all required plugin files exist
help Show this help message

Options:
--force, -f Force rebuild/re-download even if files exist

Examples:
npm run plugin:setup
npm run plugin:setup -- --force
npm run plugin:list
npm run plugin:clean
npm run plugin:validate

Configuration:
Edit config/plugin.config.ts to configure which plugin versions to use.
`);
}

main();
11 changes: 11 additions & 0 deletions src/support/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import { After, AfterAll, Before, BeforeAll, Status, setDefaultTimeout } from "@
import {rename, exists, rm, testSshConnection, installRemotePlugin, activatePlugin, uninstallPlugin, readFile, isPluginActive} from "../../utils/commands";
import type { Selectors } from "../../utils/types";
import type { Section } from "../../utils/types";
import { setupPluginVersions, validatePluginFiles } from "../../utils/plugin-manager";
// import {configurations, getWPDir} from "../../utils/configurations";


Expand Down Expand Up @@ -65,6 +66,16 @@ BeforeAll(async function (this: ICustomWorld) {

await deleteFolder('./backstop_data/bitmaps_test');

// Setup plugin versions automatically
console.log('Checking plugin versions...');
const pluginsValid = await validatePluginFiles();
if (!pluginsValid) {
console.log('Some plugin files are missing, downloading/building them...');
await setupPluginVersions();
} else {
console.log('All required plugin files are present');
}

// Check if template loader plugin is active, activate if not
const isTemplateLoaderActive = await isPluginActive(TEMPLATE_LOADER_PLUGIN);
if (!isTemplateLoaderActive) {
Expand Down
Loading