From 8bcd309fad4e2d33d01cdb7759199b36794883d2 Mon Sep 17 00:00:00 2001 From: anamwp Date: Fri, 28 Aug 2026 10:41:24 +0600 Subject: [PATCH 1/2] Build/Test Tools: Fix `install.test.js` leaving behind `wp_e2e_` tables that break subsequent test runs. `afterEach` reverted `wp-config.php`'s table prefix but never dropped the `wp_e2e_*` tables the test's own install wizard creates, so any run after the first found a pre-existing install and never reached the installer. Also retries the initial navigation itself, since a single `page.goto('/')` right after the config swap can occasionally observe a stale config on some hosts. See https://core.trac.wordpress.org/ticket/65982 --- tests/e2e/specs/install.test.js | 40 ++++++++++++++++++++++++++++----- 1 file changed, 34 insertions(+), 6 deletions(-) diff --git a/tests/e2e/specs/install.test.js b/tests/e2e/specs/install.test.js index cc237b81452a2..2df1dd1155c1e 100644 --- a/tests/e2e/specs/install.test.js +++ b/tests/e2e/specs/install.test.js @@ -2,6 +2,7 @@ * External dependencies */ import { writeFileSync, readFileSync } from 'node:fs'; +import { execFileSync } from 'node:child_process'; import { join } from 'node:path'; /** @@ -29,15 +30,42 @@ test.describe( 'WordPress installation process', () => { test.afterEach( async () => { writeFileSync( wpConfig, wpConfigOriginal ); + + // The test completes a full install under the `wp_e2e_` prefix. Drop those + // tables, otherwise the next run finds a pre-existing install and never + // reaches the installation screen it's meant to be testing. + const tables = [ + 'commentmeta', 'comments', 'links', 'options', 'postmeta', 'posts', + 'term_relationships', 'term_taxonomy', 'termmeta', 'terms', 'usermeta', 'users', + ]; + const dropTablesPhp = tables + .map( ( table ) => `global $wpdb; $wpdb->query( "DROP TABLE IF EXISTS wp_e2e_${ table }" );` ) + .join( ' ' ); + + execFileSync( + process.execPath, + [ + join( process.cwd(), 'tools/local-env/scripts/docker.js' ), + 'exec', + '--user', + 'wp_php', + 'cli', + 'wp', + 'eval', + dropTablesPhp, + ], + { stdio: 'inherit' } + ); } ); test( 'should install WordPress with pre-existing database credentials', async ( { page } ) => { - await page.goto( '/' ); - - await expect( - page, - 'should redirect to the installation page' - ).toHaveURL( /wp-admin\/install\.php$/ ); + // The config file was just rewritten on the host; retry the navigation + // (not just the URL check) since the container's view of the file can + // lag behind the write by a request or two. + await expect( async () => { + await page.goto( '/' ); + expect( page.url() ).toMatch( /wp-admin\/install\.php$/ ); + }, 'should redirect to the installation page' ).toPass( { timeout: 10_000 } ); await expect( page.getByText( /WordPress database error/ ), From 5b32a5b520399b131f7fbe0dc33e62300a8c793d Mon Sep 17 00:00:00 2001 From: anamwp Date: Sat, 29 Aug 2026 16:45:34 +0600 Subject: [PATCH 2/2] Build/Test Tools: Extract the e2e test table prefix into a single constant. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Per review feedback on the Trac ticket, avoid repeating the `wp_e2e_` literal in both the config rewrite and the cleanup query — use one `TEST_TABLE_PREFIX` constant instead so the two can't drift out of sync. See https://core.trac.wordpress.org/ticket/65982 --- tests/e2e/specs/install.test.js | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/tests/e2e/specs/install.test.js b/tests/e2e/specs/install.test.js index 2df1dd1155c1e..9e996a28e212e 100644 --- a/tests/e2e/specs/install.test.js +++ b/tests/e2e/specs/install.test.js @@ -12,6 +12,11 @@ import { test, expect } from '@wordpress/e2e-test-utils-playwright'; let wpConfigOriginal; +// The prefix used to trick WP into "not installed" mode. Kept as a single +// constant since it has to stay in sync between the config rewrite and the +// cleanup query below. +const TEST_TABLE_PREFIX = 'wp_e2e_'; + test.describe( 'WordPress installation process', () => { const wpConfig = join( process.cwd(), @@ -24,22 +29,22 @@ test.describe( 'WordPress installation process', () => { // Changing the table prefix tricks WP into new install mode. writeFileSync( wpConfig, - wpConfigOriginal.replace( `$table_prefix = 'wp_';`, `$table_prefix = 'wp_e2e_';` ) + wpConfigOriginal.replace( `$table_prefix = 'wp_';`, `$table_prefix = '${ TEST_TABLE_PREFIX }';` ) ); } ); test.afterEach( async () => { writeFileSync( wpConfig, wpConfigOriginal ); - // The test completes a full install under the `wp_e2e_` prefix. Drop those - // tables, otherwise the next run finds a pre-existing install and never - // reaches the installation screen it's meant to be testing. + // The test completes a full install under the `TEST_TABLE_PREFIX`. Drop + // those tables, otherwise the next run finds a pre-existing install and + // never reaches the installation screen it's meant to be testing. const tables = [ 'commentmeta', 'comments', 'links', 'options', 'postmeta', 'posts', 'term_relationships', 'term_taxonomy', 'termmeta', 'terms', 'usermeta', 'users', ]; const dropTablesPhp = tables - .map( ( table ) => `global $wpdb; $wpdb->query( "DROP TABLE IF EXISTS wp_e2e_${ table }" );` ) + .map( ( table ) => `global $wpdb; $wpdb->query( "DROP TABLE IF EXISTS ${ TEST_TABLE_PREFIX }${ table }" );` ) .join( ' ' ); execFileSync(