Skip to content

E2E tests #220

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Aug 12, 2025
Merged
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
35 changes: 35 additions & 0 deletions .github/workflows/end-to-end-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: End-to-end Tests

on:
push:
branches:
- main
pull_request:

jobs:
test:
name: End-to-end Tests
runs-on: ubuntu-latest
timeout-minutes: 20

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Set UID and GID for PHP in WordPress images
run: |
echo "PHP_FPM_UID=$(id -u)" >> $GITHUB_ENV
echo "PHP_FPM_GID=$(id -g)" >> $GITHUB_ENV

- name: Install Playwright browsers
run: npx playwright install --with-deps

- name: Run end-to-end tests
run: composer run test-e2e

- name: Stop Docker containers
if: always()
run: composer run wp-test-clean
35 changes: 35 additions & 0 deletions .github/workflows/wp-tests-end-to-end.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: WordPress End-to-end Tests

on:
push:
branches:
- main
pull_request:

jobs:
test:
name: WordPress End-to-end Tests
runs-on: ubuntu-latest
timeout-minutes: 20

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Set UID and GID for PHP in WordPress images
run: |
echo "PHP_FPM_UID=$(id -u)" >> $GITHUB_ENV
echo "PHP_FPM_GID=$(id -g)" >> $GITHUB_ENV

- name: Install Playwright browsers
run: npx playwright install --with-deps

- name: Run WordPress end-to-end tests
run: composer run wp-test-e2e

- name: Stop Docker containers
if: always()
run: composer run wp-test-clean
4 changes: 2 additions & 2 deletions .github/workflows/wp-tests-phpunit-run.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Wrap the "composer run wp-tests-phpunit" command to process tests
* Wrap the "composer run wp-tests-php" command to process tests
* that are expected to error and fail at the moment.
*
* This makes sure that the CI job passes, while explicitly tracking
Expand Down Expand Up @@ -108,7 +108,7 @@ console.log( 'Expected failures:', expectedFailures );
try {
try {
execSync(
`composer run wp-test-phpunit -- --log-junit=phpunit-results.xml --verbose`,
`composer run wp-test-php -- --log-junit=phpunit-results.xml --verbose`,
{ stdio: 'inherit' }
);
console.log( '\n⚠️ All tests passed, checking if expected errors/failures occurred...' );
Expand Down
8 changes: 1 addition & 7 deletions .github/workflows/wp-tests-phpunit.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: WordPress Tests
name: WordPress PHPUnit Tests

on:
push:
Expand All @@ -24,12 +24,6 @@ jobs:
echo "PHP_FPM_UID=$(id -u)" >> $GITHUB_ENV
echo "PHP_FPM_GID=$(id -g)" >> $GITHUB_ENV

- name: Setup WordPress test environment
run: composer run wp-setup

- name: Start WordPress test environment
run: composer run wp-test-start

- name: Run WordPress PHPUnit tests
run: node .github/workflows/wp-tests-phpunit-run.js

Expand Down
29 changes: 25 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@
"test": [
"phpunit"
],
"test-e2e": [
"@wp-test-ensure-env @no_additional_args",
"rm -f tests/e2e/package.json tests/e2e/node_modules @no_additional_args",
"ln -s ../../wordpress/package.json tests/e2e/package.json @no_additional_args",
"ln -s ../../wordpress/node_modules tests/e2e/node_modules @no_additional_args",
"npm --prefix tests/e2e run test:e2e -- --config . @additional_args"
],
"wp-setup": [
"./wp-setup.sh"
],
Expand All @@ -47,13 +54,27 @@
],
"wp-test-start": [
"npm --prefix wordpress run env:start",
"npm --prefix wordpress run env:install"
"npm --prefix wordpress run env:install",
"npm --prefix wordpress run env:cli -- plugin install gutenberg",
"npm --prefix wordpress run env:cli -- plugin install query-monitor"
],
"wp-test-ensure-env": [
"if [ ! -f wordpress/src/wp-load.php ]; then composer run wp-setup; fi",
"@putenv COMPOSE_IGNORE_ORPHANS=true",
"cd wordpress && if [ -z \"$(node tools/local-env/scripts/docker.js ps -q)\" ]; then cd ..; composer run wp-test-start; fi"
],
"wp-test-php": [
"@wp-test-ensure-env @no_additional_args",
"rm -rf wordpress/src/wp-content/database/.ht.sqlite @no_additional_args",
"npm --prefix wordpress run test:php -- @additional_args"
],
"wp-test-phpunit": [
"rm -rf wordpress/src/wp-content/database && npm --prefix wordpress run test:php --"
"wp-test-e2e": [
"@wp-test-ensure-env @no_additional_args",
"npm --prefix wordpress run test:e2e -- @additional_args"
],
"wp-test-clean": [
"npm --prefix wordpress run env:clean"
"npm --prefix wordpress run env:clean",
"rm -rf wordpress/src/wp-content/database/.ht.sqlite"
]
}
}
3 changes: 3 additions & 0 deletions tests/e2e/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/artifacts
/node_modules
/package.json
27 changes: 27 additions & 0 deletions tests/e2e/playwright.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/**
* External dependencies
*/
import path from 'node:path';
import { defineConfig } from '@playwright/test';

/**
* WordPress dependencies
*/
const baseConfig = require( '@wordpress/scripts/config/playwright.config' );

process.env.WP_ARTIFACTS_PATH ??= path.join( process.cwd(), 'artifacts' );
process.env.STORAGE_STATE_PATH ??= path.join(
process.env.WP_ARTIFACTS_PATH,
'storage-states/admin.json'
);

const config = defineConfig( {
...baseConfig,
globalSetup: require.resolve( '../../wordpress/tests/e2e/config/global-setup.js' ),
webServer: {
...baseConfig.webServer,
command: 'npm run env:start',
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be useful to run this both with wp-env and Playground CLI. Not a blocker here

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@adamziel Should we do that here or in the Playground repo? I guess if what you mean is using Playground CLI for any tests that we write for the SQLite repo, then it probably belongs to the SQLite repo; just making sure. I can create a ticket for that.

},
} );

export default config;
47 changes: 47 additions & 0 deletions tests/e2e/specs/query-monitor-plugin.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/**
* WordPress dependencies
*/
import { test, expect } from '@wordpress/e2e-test-utils-playwright';

test.describe( 'Query Monitor plugin', () => {
async function deactivateQueryMonitor( requestUtils ) {
await requestUtils.deactivatePlugin( 'query-monitor' );
const plugin = await requestUtils.rest( {
path: 'wp/v2/plugins/query-monitor/query-monitor',
} );
expect( plugin.status ).toBe( 'inactive' );
}

test.beforeEach( async ( { requestUtils }) => {
await deactivateQueryMonitor( requestUtils );
} );

test.afterEach( async ( { requestUtils }) => {
await deactivateQueryMonitor( requestUtils );
} );

test( 'should activate', async ( { admin, page } ) => {
// Activate the Query Monitor plugin on the plugins page.
await admin.visitAdminPage( '/plugins.php' );
await page.getByLabel( 'Activate Query Monitor', { exact: true } ).click();
await page.getByText( 'Plugin activated.', { exact: true } ).waitFor();

// Click on the Query Monitor menu item in the WordPress admin bar.
await page.locator('a[role="menuitem"][href="#qm-overview"][aria-expanded="false"]').click();

// Wait for the Query Monitor panel to open.
await page.locator( '#query-monitor-main' ).waitFor();
await page.getByRole( 'heading', { name: 'Query Monitor', exact: true } ).waitFor();

// Click on the Database Queries tab.
await page.getByRole( 'tab', { name: 'Database Queries' } ).click();

// Verify the first logged query.
const sqlCell = page.locator( '.qm-row-sql' ).first();
await expect( sqlCell ).toContainText( 'SELECT option_name, option_value' );

// Check that the query is logged with SQLite information.
await sqlCell.getByLabel( 'Toggle SQLite queries' ).click();
expect( page.locator('.qm-sqlite-query', { hasText: 'SELECT `option_name` , `option_value` FROM `wp_options`' }).first() ).toBeVisible();
} );
} );
1 change: 1 addition & 0 deletions wp-setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,4 @@ sed -i.bak "s#class WpdbExposedMethodsForTesting extends wpdb {#class WpdbExpose
# 6. Install dependencies.
echo "Installing dependencies..."
npm --prefix "$WP_DIR" install
npm --prefix "$WP_DIR" run build:dev
Loading