Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Setup SQLite driver E2E tests and add an E2E test for Query Monitor
  • Loading branch information
JanJakes committed Aug 8, 2025
commit c37f76d6a5f20019eb454fd4807ff1756ac86b11
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
7 changes: 7 additions & 0 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 Down
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();
} );
} );
Loading