Skip to content

Commit

Permalink
env: Ignore \$schema key in environment config parsing (#62626)
Browse files Browse the repository at this point in the history
* env: Ignore `\$schema` key in environment config parsing

* Add changelog

Co-authored-by: t-hamano <wildworks@git.wordpress.org>
Co-authored-by: sirreal <jonsurrell@git.wordpress.org>
  • Loading branch information
3 people authored Jun 18, 2024
1 parent 2fdcec7 commit e636142
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
4 changes: 4 additions & 0 deletions packages/env/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Unreleased

### Enhancement

- Ignore `$schema` key in environment config parsing ([#62626](https://github.com/WordPress/gutenberg/pull/62626)).

## 10.1.0 (2024-06-15)

## 10.0.0 (2024-05-31)
Expand Down
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

1 comment on commit e636142

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Flaky tests detected in e636142.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/9557887502
📝 Reported issues:

Please sign in to comment.