From e2dcd0a261f0fd3465b9fa653db354f7590837ab Mon Sep 17 00:00:00 2001 From: Jon Surrell Date: Tue, 14 May 2024 13:00:27 +0200 Subject: [PATCH] Env package: Fix return type and tests (#61631) 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 Co-authored-by: t-hamano --- packages/env/lib/config/parse-config.js | 2 +- packages/env/lib/config/test/parse-config.js | 53 ++++++++------------ 2 files changed, 22 insertions(+), 33 deletions(-) diff --git a/packages/env/lib/config/parse-config.js b/packages/env/lib/config/parse-config.js index 3f69bb78b81f26..5da05396ec468c 100644 --- a/packages/env/lib/config/parse-config.js +++ b/packages/env/lib/config/parse-config.js @@ -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} Parsed config. */ async function parseConfig( configDirectoryPath, cacheDirectoryPath ) { // The local config will be used to override any defaults. diff --git a/packages/env/lib/config/test/parse-config.js b/packages/env/lib/config/test/parse-config.js index ee808b973b16a4..f2e9b923d7fdcd 100644 --- a/packages/env/lib/config/test/parse-config.js +++ b/packages/env/lib/config/test/parse-config.js @@ -1,5 +1,4 @@ 'use strict'; -/* eslint-disable jest/no-conditional-expect */ /** * Internal dependencies */ @@ -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 () => { @@ -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 () => { @@ -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 */