Make WordPress Core

Changeset 64259


Ignore:
Timestamp:
10/09/2026 05:58:28 PM (4 weeks ago)
Author:
lancewillett
Message:

Build/Test Tools: Disable login autofocus during 6.3 E2E tests.

Prevent delayed login autofocus from clearing passwords during automated input. Temporarily install a must-use plugin using the enable_login_autofocus filter, then remove it after the test runner exits or is interrupted.

Respect LOCAL_DIR, preserve unrelated plugins, pass test arguments through, and forward termination signals to the test process group.

Developed in: ​https://github.com/WordPress/wordpress-develop/pull/13942

Props lucatume.
See #58592.

Location:
branches/6.3/tests/e2e
Files:
2 added
1 edited

Legend:

Unmodified
Added
Removed
  • branches/6.3/tests/e2e/run-tests.js

    r53113 r64259  
    11const dotenv = require( 'dotenv' );
    2 const dotenv_expand = require( 'dotenv-expand' );
    3 const { execSync } = require( 'child_process' );
     2const dotenvExpand = require( 'dotenv-expand' );
     3const { spawn } = require( 'child_process' );
     4const { copyFileSync, mkdirSync, rmSync } = require( 'fs' );
     5const path = require( 'path' );
    46
    5 // WP_BASE_URL interpolates LOCAL_PORT, so needs to be parsed by dotenv_expand().
    6 dotenv_expand.expand( dotenv.config() );
     7// WP_BASE_URL interpolates LOCAL_PORT, so needs to be parsed by dotenvExpand().
     8dotenvExpand.expand( dotenv.config() );
     9
     10// Keep the login screen's delayed autofocus from interrupting automated input.
     11const muPluginDirectory = path.join(
     12        process.env.LOCAL_DIR || 'src',
     13        'wp-content',
     14        'mu-plugins'
     15);
     16const muPluginFile = path.join(
     17        muPluginDirectory,
     18        `e2e-disable-login-autofocus-${ process.pid }.php`
     19);
     20
     21mkdirSync( muPluginDirectory, { recursive: true } );
     22copyFileSync(
     23        path.join( __dirname, 'mu-plugins', 'disable-login-autofocus.php' ),
     24        muPluginFile
     25);
     26
     27// Remove only this run's fixture, including on failure or interruption.
     28process.once( 'exit', () => rmSync( muPluginFile, { force: true } ) );
    729
    830// Run the tests, passing additional arguments through to the test script.
    9 execSync(
    10         'wp-scripts test-e2e --config tests/e2e/jest.config.js ' +
    11                 process.argv.slice( 2 ).join( ' ' ),
    12         { stdio: 'inherit' }
     31const tests = spawn(
     32        process.execPath,
     33        [
     34                require.resolve( '@wordpress/scripts/bin/wp-scripts.js' ),
     35                'test-e2e',
     36                '--config',
     37                'tests/e2e/jest.config.js',
     38                ...process.argv.slice( 2 ),
     39        ],
     40        { stdio: 'inherit', detached: process.platform !== 'win32' }
    1341);
     42
     43for ( const signal of [ 'SIGHUP', 'SIGINT', 'SIGQUIT', 'SIGTERM' ] ) {
     44        process.on( signal, () => {
     45                // Stop the test process group before removing its fixture.
     46                try {
     47                        if ( process.platform === 'win32' ) {
     48                                tests.kill( signal );
     49                        } else {
     50                                process.kill( -tests.pid, signal );
     51                        }
     52                } catch ( error ) {
     53                        if ( error.code !== 'ESRCH' ) {
     54                                throw error;
     55                        }
     56                }
     57        } );
     58}
     59
     60tests.once( 'error', ( error ) => {
     61        throw error;
     62} );
     63tests.once( 'exit', ( code, signal ) => {
     64        const signalExitCodes = {
     65                SIGHUP: 129,
     66                SIGINT: 130,
     67                SIGQUIT: 131,
     68                SIGTERM: 143,
     69        };
     70        process.exitCode = code === null ? signalExitCodes[ signal ] || 1 : code;
     71} );
Note: See TracChangeset for help on using the changeset viewer.