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

env: Ignore \$schema key in environment config parsing #62626

Merged
merged 2 commits into from
Jun 18, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
5 changes: 5 additions & 0 deletions packages/env/lib/config/parse-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,11 @@ async function parseEnvironmentConfig(
continue;
}

// The $schema key is a special key that is used to validate the configuration.
if ( key === '$schema' ) {
continue;
}

// We should also check root-only options for the root config
// because these aren't part of the above defaults but are
// configuration options that we will parse.
Expand Down
20 changes: 20 additions & 0 deletions packages/env/lib/config/test/parse-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,26 @@ describe( 'parseConfig', () => {
} );
} );

it( 'should ignore `$schema` key', async () => {
readRawConfigFile.mockImplementation( async ( configFile ) => {
if ( configFile === '/test/gutenberg/.wp-env.json' ) {
return {
$schema: 'test',
};
}

if ( configFile === '/test/gutenberg/.wp-env.override.json' ) {
return {};
}

throw new Error( 'Invalid File: ' + configFile );
} );

const parsed = await parseConfig( '/test/gutenberg', '/cache' );

expect( parsed ).toEqual( DEFAULT_CONFIG );
} );

it( 'should override with environment variables', async () => {
process.env.WP_ENV_PORT = 123;
process.env.WP_ENV_TESTS_PORT = 456;
Expand Down
Loading