Skip to content

Commit c37f76d

Browse files
committed
Setup SQLite driver E2E tests and add an E2E test for Query Monitor
1 parent 8f7f203 commit c37f76d

File tree

5 files changed

+119
-0
lines changed

5 files changed

+119
-0
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
name: End-to-end Tests
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
9+
jobs:
10+
test:
11+
name: End-to-end Tests
12+
runs-on: ubuntu-latest
13+
timeout-minutes: 20
14+
15+
steps:
16+
- name: Checkout repository
17+
uses: actions/checkout@v4
18+
19+
- name: Set up Docker Buildx
20+
uses: docker/setup-buildx-action@v3
21+
22+
- name: Set UID and GID for PHP in WordPress images
23+
run: |
24+
echo "PHP_FPM_UID=$(id -u)" >> $GITHUB_ENV
25+
echo "PHP_FPM_GID=$(id -g)" >> $GITHUB_ENV
26+
27+
- name: Install Playwright browsers
28+
run: npx playwright install --with-deps
29+
30+
- name: Run end-to-end tests
31+
run: composer run test-e2e
32+
33+
- name: Stop Docker containers
34+
if: always()
35+
run: composer run wp-test-clean

composer.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,13 @@
3939
"test": [
4040
"phpunit"
4141
],
42+
"test-e2e": [
43+
"@wp-test-ensure-env @no_additional_args",
44+
"rm -f tests/e2e/package.json tests/e2e/node_modules @no_additional_args",
45+
"ln -s ../../wordpress/package.json tests/e2e/package.json @no_additional_args",
46+
"ln -s ../../wordpress/node_modules tests/e2e/node_modules @no_additional_args",
47+
"npm --prefix tests/e2e run test:e2e -- --config . @additional_args"
48+
],
4249
"wp-setup": [
4350
"./wp-setup.sh"
4451
],

tests/e2e/.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
/artifacts
2+
/node_modules
3+
/package.json

tests/e2e/playwright.config.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/**
2+
* External dependencies
3+
*/
4+
import path from 'node:path';
5+
import { defineConfig } from '@playwright/test';
6+
7+
/**
8+
* WordPress dependencies
9+
*/
10+
const baseConfig = require( '@wordpress/scripts/config/playwright.config' );
11+
12+
process.env.WP_ARTIFACTS_PATH ??= path.join( process.cwd(), 'artifacts' );
13+
process.env.STORAGE_STATE_PATH ??= path.join(
14+
process.env.WP_ARTIFACTS_PATH,
15+
'storage-states/admin.json'
16+
);
17+
18+
const config = defineConfig( {
19+
...baseConfig,
20+
globalSetup: require.resolve( '../../wordpress/tests/e2e/config/global-setup.js' ),
21+
webServer: {
22+
...baseConfig.webServer,
23+
command: 'npm run env:start',
24+
},
25+
} );
26+
27+
export default config;
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/**
2+
* WordPress dependencies
3+
*/
4+
import { test, expect } from '@wordpress/e2e-test-utils-playwright';
5+
6+
test.describe( 'Query Monitor plugin', () => {
7+
async function deactivateQueryMonitor( requestUtils ) {
8+
await requestUtils.deactivatePlugin( 'query-monitor' );
9+
const plugin = await requestUtils.rest( {
10+
path: 'wp/v2/plugins/query-monitor/query-monitor',
11+
} );
12+
expect( plugin.status ).toBe( 'inactive' );
13+
}
14+
15+
test.beforeEach( async ( { requestUtils }) => {
16+
await deactivateQueryMonitor( requestUtils );
17+
} );
18+
19+
test.afterEach( async ( { requestUtils }) => {
20+
await deactivateQueryMonitor( requestUtils );
21+
} );
22+
23+
test( 'should activate', async ( { admin, page } ) => {
24+
// Activate the Query Monitor plugin on the plugins page.
25+
await admin.visitAdminPage( '/plugins.php' );
26+
await page.getByLabel( 'Activate Query Monitor', { exact: true } ).click();
27+
await page.getByText( 'Plugin activated.', { exact: true } ).waitFor();
28+
29+
// Click on the Query Monitor menu item in the WordPress admin bar.
30+
await page.locator('a[role="menuitem"][href="#qm-overview"][aria-expanded="false"]').click();
31+
32+
// Wait for the Query Monitor panel to open.
33+
await page.locator( '#query-monitor-main' ).waitFor();
34+
await page.getByRole( 'heading', { name: 'Query Monitor', exact: true } ).waitFor();
35+
36+
// Click on the Database Queries tab.
37+
await page.getByRole( 'tab', { name: 'Database Queries' } ).click();
38+
39+
// Verify the first logged query.
40+
const sqlCell = page.locator( '.qm-row-sql' ).first();
41+
await expect( sqlCell ).toContainText( 'SELECT option_name, option_value' );
42+
43+
// Check that the query is logged with SQLite information.
44+
await sqlCell.getByLabel( 'Toggle SQLite queries' ).click();
45+
expect( page.locator('.qm-sqlite-query', { hasText: 'SELECT `option_name` , `option_value` FROM `wp_options`' }).first() ).toBeVisible();
46+
} );
47+
} );

0 commit comments

Comments
 (0)