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: Fix return type and tests #61631

Merged
merged 2 commits into from
May 14, 2024
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
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 */
Loading