Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wp-env: Add support for custom WP_HOME port #26507

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion packages/env/lib/config/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,12 @@ function withOverrides( config ) {
const baseUrl = new URL(
config.env[ envKey ].config[ configKey ]
);
baseUrl.port = config.env[ envKey ].port;

// Don't overwrite the port of WP_HOME when set.
if ( ! ( configKey === 'WP_HOME' && !! baseUrl.port ) ) {
baseUrl.port = config.env[ envKey ].port;
}

config.env[ envKey ].config[ configKey ] = baseUrl.toString();
} catch ( error ) {
throw new ValidationError(
Expand Down
36 changes: 36 additions & 0 deletions packages/env/lib/config/test/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -731,6 +731,42 @@ describe( 'readConfig', () => {
} );
} );

it( 'should not overwrite port number for WP_HOME if set', async () => {
readFile.mockImplementation( () =>
Promise.resolve(
JSON.stringify( {
port: 1000,
testsPort: 2000,
config: {
WP_HOME: 'http://localhost:3000/',
},
} )
)
);
const config = await readConfig( '.wp-env.json' );
// Custom port is overriden while testsPort gets the deault value.
expect( config ).toMatchObject( {
env: {
development: {
port: 1000,
config: {
WP_TESTS_DOMAIN: 'http://localhost:1000/',
WP_SITEURL: 'http://localhost:1000/',
WP_HOME: 'http://localhost:3000/',
},
},
tests: {
port: 2000,
config: {
WP_TESTS_DOMAIN: 'http://localhost:2000/',
WP_SITEURL: 'http://localhost:2000/',
WP_HOME: 'http://localhost:3000/',
},
},
},
} );
} );

it( 'should throw an error if the port number environment variable is invalid', async () => {
readFile.mockImplementation( () =>
Promise.resolve( JSON.stringify( {} ) )
Expand Down