diff --git a/.gitignore b/.gitignore index 7ff179d3..a890db7e 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 23d552f6..dc0e3fc8 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 a39cddd1..d0838fd1 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 55b6b8db..df743b45 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' ) ) );