From ab80f7e42196f40cf7021efbf151014405459a84 Mon Sep 17 00:00:00 2001 From: Soare Robert-Daniel Date: Thu, 30 Jul 2026 10:22:24 +0300 Subject: [PATCH] fix(e2e): make the suite target the actual wp-env instance Three unrelated local-env breakages, all of which made the suite fail without any product regression: - The port was hardcoded to 8889 by the @wordpress/scripts defaults, so a checkout that pins another port in .wp-env.override.json (8889 is often taken by a second checkout) ran every spec against an unrelated site. Resolve WP_ENV_TESTS_PORT -> .wp-env.override.json -> 8889; CI is unchanged as it has neither. - The two e2e mu-plugins were mapped as individual files. Docker Desktop single-file bind mounts go stale when an editor saves atomically, so the container saw 0-byte helpers and the lazy-render / database-source specs silently ran without them. Map the directory instead. - lazy-render waited for the `data-visualizer-script` placeholders, but the loader legitimately swaps them on the first user interaction, and Chromium fires a real `mouseover` right after navigation. Assert lazy mode via the persistent container class instead. Co-Authored-By: Claude Opus 5 (1M context) --- .gitignore | 3 +++ .wp-env.json | 3 +-- .../config/{ => mu-plugins}/enable-database-source.php | 0 .../e2e/config/{ => mu-plugins}/force-lazy-render.php | 0 tests/e2e/playwright.config.js | 10 ++++++++++ tests/e2e/specs/lazy-render.spec.js | 7 +++++-- 6 files changed, 19 insertions(+), 4 deletions(-) rename tests/e2e/config/{ => mu-plugins}/enable-database-source.php (100%) rename tests/e2e/config/{ => mu-plugins}/force-lazy-render.php (100%) diff --git a/.gitignore b/.gitignore index 7ff179d3f..a890db7e5 100755 --- a/.gitignore +++ b/.gitignore @@ -10,3 +10,6 @@ artifacts classes/Visualizer/Gutenberg/build classes/Visualizer/ChartBuilder/build classes/Visualizer/D3Renderer/build + +# Local wp-env port pinning (per-checkout). +.wp-env.override.json diff --git a/.wp-env.json b/.wp-env.json index 23d552f6d..dc0e3fc83 100644 --- a/.wp-env.json +++ b/.wp-env.json @@ -6,8 +6,7 @@ ], "themes": [], "mappings": { - "wp-content/mu-plugins/visualizer-e2e-enable-database-source.php": "./tests/e2e/config/enable-database-source.php", - "wp-content/mu-plugins/visualizer-e2e-force-lazy-render.php": "./tests/e2e/config/force-lazy-render.php" + "wp-content/mu-plugins": "./tests/e2e/config/mu-plugins" }, "config": { "WP_DEBUG": true, diff --git a/tests/e2e/config/enable-database-source.php b/tests/e2e/config/mu-plugins/enable-database-source.php similarity index 100% rename from tests/e2e/config/enable-database-source.php rename to tests/e2e/config/mu-plugins/enable-database-source.php diff --git a/tests/e2e/config/force-lazy-render.php b/tests/e2e/config/mu-plugins/force-lazy-render.php similarity index 100% rename from tests/e2e/config/force-lazy-render.php rename to tests/e2e/config/mu-plugins/force-lazy-render.php diff --git a/tests/e2e/playwright.config.js b/tests/e2e/playwright.config.js index a39cddd1f..d0838fd10 100644 --- a/tests/e2e/playwright.config.js +++ b/tests/e2e/playwright.config.js @@ -7,6 +7,15 @@ import os from 'os'; import { fileURLToPath } from 'url'; import { defineConfig, devices } from '@playwright/test'; +// The tests instance may be pinned to a non-default port in .wp-env.override.json +// (8889 is often taken by another checkout). Target whatever wp-env actually bound. +let testsPort = process.env.WP_ENV_TESTS_PORT; +try { + testsPort ??= require( '../../.wp-env.override.json' ).testsPort; +} catch ( e ) {} // No override file, fall back to the wp-env default. +testsPort = Number( testsPort ) || 8889; +process.env.WP_BASE_URL ??= `http://localhost:${ testsPort }`; + /** * WordPress dependencies */ @@ -14,6 +23,7 @@ const baseConfig = require( '@wordpress/scripts/config/playwright.config' ); const config = defineConfig( { ...baseConfig, + webServer: { ...baseConfig.webServer, port: testsPort }, reporter: process.env.CI ? [ [ 'github' ], [ './config/flaky-tests-reporter.js' ] ] : 'list', diff --git a/tests/e2e/specs/lazy-render.spec.js b/tests/e2e/specs/lazy-render.spec.js index 55b6b8db7..df743b450 100644 --- a/tests/e2e/specs/lazy-render.spec.js +++ b/tests/e2e/specs/lazy-render.spec.js @@ -38,8 +38,11 @@ test.describe( 'Lazy rendered charts (frontend)', () => { } async function triggerLazyLoader( page ) { - // Scripts are swapped to `data-visualizer-script` placeholders. - await expect( page.locator( 'script[data-visualizer-script]' ).first() ).toBeAttached(); + // Assert lazy rendering is on via the container class, not the + // `data-visualizer-script` placeholders: those are swapped away by the + // first user interaction, and Chromium fires a real `mouseover` right + // after navigation whenever the cursor sits over the page. + await expect( page.locator( '.visualizer-lazy-render' ).first() ).toBeAttached(); // The loader starts on the first user interaction. await page.evaluate( () => window.dispatchEvent( new Event( 'scroll' ) ) );