Skip to content

Commit

Permalink
Env package: Fix return type and tests (#61631)
Browse files Browse the repository at this point in the history
Fix:

- There are some unnecessary lint disables around test expectations. The tests can be refactored to remove conditional expects and enable the lint.
- A return type is wrong.

Co-authored-by: sirreal <jonsurrell@git.wordpress.org>
Co-authored-by: t-hamano <wildworks@git.wordpress.org>
  • Loading branch information
3 people authored May 14, 2024
1 parent b2689f0 commit e2dcd0a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 33 deletions.
2 changes: 1 addition & 1 deletion packages/env/lib/config/parse-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ const DEFAULT_ENVIRONMENT_CONFIG = {
* @param {string} configDirectoryPath A path to the directory we are parsing the config for.
* @param {string} cacheDirectoryPath Path to the work directory located in ~/.wp-env.
*
* @return {WPRootConfig} Parsed config.
* @return {Promise<WPRootConfig>} Parsed config.
*/
async function parseConfig( configDirectoryPath, cacheDirectoryPath ) {
// The local config will be used to override any defaults.
Expand Down
53 changes: 21 additions & 32 deletions packages/env/lib/config/test/parse-config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
'use strict';
/* eslint-disable jest/no-conditional-expect */
/**
* Internal dependencies
*/
Expand Down Expand Up @@ -319,16 +318,13 @@ describe( 'parseConfig', () => {
it( 'throws when latest WordPress version needed but not found', async () => {
getLatestWordPressVersion.mockResolvedValue( null );

expect.assertions( 1 );
try {
await parseConfig( '/test/gutenberg', '/cache' );
} catch ( error ) {
expect( error ).toEqual(
new ValidationError(
'Could not find the latest WordPress version. There may be a network issue.'
)
);
}
await expect(
parseConfig( '/test/gutenberg', '/cache' )
).rejects.toEqual(
new ValidationError(
'Could not find the latest WordPress version. There may be a network issue.'
)
);
} );

it( 'throws for unknown config options', async () => {
Expand All @@ -346,16 +342,13 @@ describe( 'parseConfig', () => {
throw new Error( 'Invalid File: ' + configFile );
} );

expect.assertions( 1 );
try {
await parseConfig( '/test/gutenberg', '/cache' );
} catch ( error ) {
expect( error ).toEqual(
new ValidationError(
`Invalid /test/gutenberg/.wp-env.json: "test" is not a configuration option.`
)
);
}
await expect(
parseConfig( '/test/gutenberg', '/cache' )
).rejects.toEqual(
new ValidationError(
`Invalid /test/gutenberg/.wp-env.json: "test" is not a configuration option.`
)
);
} );

it( 'throws for root-only config options', async () => {
Expand All @@ -378,16 +371,12 @@ describe( 'parseConfig', () => {
throw new Error( 'Invalid File: ' + configFile );
} );

expect.assertions( 1 );
try {
await parseConfig( '/test/gutenberg', '/cache' );
} catch ( error ) {
expect( error ).toEqual(
new ValidationError(
`Invalid /test/gutenberg/.wp-env.json: "development.env" is not a configuration option.`
)
);
}
await expect(
parseConfig( '/test/gutenberg', '/cache' )
).rejects.toEqual(
new ValidationError(
`Invalid /test/gutenberg/.wp-env.json: "development.env" is not a configuration option.`
)
);
} );
} );
/* eslint-enable jest/no-conditional-expect */

1 comment on commit e2dcd0a

@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 e2dcd0a.
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/9078198452
📝 Reported issues:

Please sign in to comment.