From af57a68b9ceacd9f0aafd5a0fdfc519ac24c0056 Mon Sep 17 00:00:00 2001 From: Christopher Allford <6451942+ObliviousHarmony@users.noreply.github.com> Date: Tue, 23 May 2023 13:08:21 -0700 Subject: [PATCH] Removed `gutenberg` Directory Name Expectation --- .../env/lib/config/test/config-integration.js | 7 +- packages/env/lib/config/test/parse-config.js | 89 +++++++------------ .../lib/config/test/parse-source-string.js | 2 +- 3 files changed, 35 insertions(+), 63 deletions(-) diff --git a/packages/env/lib/config/test/config-integration.js b/packages/env/lib/config/test/config-integration.js index e9835e0c0ce8e5..8d3a1a880adac7 100644 --- a/packages/env/lib/config/test/config-integration.js +++ b/packages/env/lib/config/test/config-integration.js @@ -3,7 +3,6 @@ /** * External dependencies */ -const path = require( 'path' ); const { readFile } = require( 'fs' ).promises; /** @@ -80,7 +79,7 @@ describe( 'Config Integration', () => { throw { code: 'ENOENT' }; } ); - const config = await loadConfig( path.resolve( '/test/gutenberg' ) ); + const config = await loadConfig( '/test/gutenberg' ); expect( config.env.development.port ).toEqual( 123 ); expect( config.env.tests.port ).toEqual( 8889 ); @@ -116,7 +115,7 @@ describe( 'Config Integration', () => { throw { code: 'ENOENT' }; } ); - const config = await loadConfig( path.resolve( '/test/gutenberg' ) ); + const config = await loadConfig( '/test/gutenberg' ); expect( config.env.development.port ).toEqual( 999 ); expect( config.env.tests.port ).toEqual( 456 ); @@ -151,7 +150,7 @@ describe( 'Config Integration', () => { throw { code: 'ENOENT' }; } ); - const config = await loadConfig( path.resolve( '/test/gutenberg' ) ); + const config = await loadConfig( '/test/gutenberg' ); expect( config.env.development.port ).toEqual( 12345 ); expect( config.env.tests.port ).toEqual( 61234 ); diff --git a/packages/env/lib/config/test/parse-config.js b/packages/env/lib/config/test/parse-config.js index 5052199a983d54..8e62d8a78ca41d 100644 --- a/packages/env/lib/config/test/parse-config.js +++ b/packages/env/lib/config/test/parse-config.js @@ -1,10 +1,5 @@ 'use strict'; /* eslint-disable jest/no-conditional-expect */ -/** - * External dependencies - */ -const path = require( 'path' ); - /** * Internal dependencies */ @@ -84,7 +79,7 @@ describe( 'parseConfig', () => { } ); it( 'should return default config', async () => { - const parsed = await parseConfig( './', '/cache' ); + const parsed = await parseConfig( '/test/gutenberg', '/cache' ); expect( parsed ).toEqual( DEFAULT_CONFIG ); } ); @@ -92,56 +87,38 @@ describe( 'parseConfig', () => { it( 'should infer a core mounting default when ran from a WordPress directory', async () => { detectDirectoryType.mockResolvedValue( 'core' ); - const parsed = await parseConfig( './', '/cache' ); + const parsed = await parseConfig( '/test/gutenberg', '/cache' ); - expect( parsed ).toEqual( { - ...DEFAULT_CONFIG, - coreSource: { - basename: 'gutenberg', - path: path.resolve( '.' ), - testsPath: '/cache/tests-gutenberg', - type: 'local', - }, - } ); + expect( parsed.pluginSources ).toHaveLength( 0 ); + expect( parsed.themeSources ).toHaveLength( 0 ); + expect( parsed.coreSource ).toMatchObject( { type: 'local' } ); } ); it( 'should infer a plugin mounting default when ran from a plugin directory', async () => { detectDirectoryType.mockResolvedValue( 'plugin' ); - const parsed = await parseConfig( './', '/cache' ); + const parsed = await parseConfig( '/test/gutenberg', '/cache' ); - expect( parsed ).toEqual( { - ...DEFAULT_CONFIG, - pluginSources: [ - { - basename: 'gutenberg', - path: path.resolve( '.' ), - type: 'local', - }, - ], - } ); + expect( parsed.coreSource ).toMatchObject( { type: 'git' } ); + expect( parsed.themeSources ).toHaveLength( 0 ); + expect( parsed.pluginSources ).toHaveLength( 1 ); + expect( parsed.pluginSources[ 0 ] ).toMatchObject( { type: 'local' } ); } ); it( 'should infer a theme mounting default when ran from a theme directory', async () => { detectDirectoryType.mockResolvedValue( 'theme' ); - const parsed = await parseConfig( './', '/cache' ); + const parsed = await parseConfig( '/test/gutenberg', '/cache' ); - expect( parsed ).toEqual( { - ...DEFAULT_CONFIG, - themeSources: [ - { - basename: 'gutenberg', - path: path.resolve( '.' ), - type: 'local', - }, - ], - } ); + expect( parsed.coreSource ).toMatchObject( { type: 'git' } ); + expect( parsed.pluginSources ).toHaveLength( 0 ); + expect( parsed.themeSources ).toHaveLength( 1 ); + expect( parsed.themeSources[ 0 ] ).toMatchObject( { type: 'local' } ); } ); it( 'should merge configs with precedence', async () => { readRawConfigFile.mockImplementation( async ( configFile ) => { - if ( configFile === path.resolve( './.wp-env.json' ) ) { + if ( configFile === '/test/gutenberg/.wp-env.json' ) { return { core: 'WordPress/WordPress#Test', phpVersion: '1.0', @@ -159,7 +136,7 @@ describe( 'parseConfig', () => { }; } - if ( configFile === path.resolve( './.wp-env.override.json' ) ) { + if ( configFile === '/test/gutenberg/.wp-env.override.json' ) { return { phpVersion: '2.0', lifecycleScripts: { @@ -176,7 +153,7 @@ describe( 'parseConfig', () => { throw new Error( 'Invalid File: ' + configFile ); } ); - const parsed = await parseConfig( './', '/cache' ); + const parsed = await parseConfig( '/test/gutenberg', '/cache' ); const expected = { ...DEFAULT_CONFIG, @@ -211,7 +188,7 @@ describe( 'parseConfig', () => { it( 'should parse core, plugin, theme, and mapping sources', async () => { readRawConfigFile.mockImplementation( async ( configFile ) => { - if ( configFile === path.resolve( '.', './.wp-env.json' ) ) { + if ( configFile === '/test/gutenberg/.wp-env.json' ) { return { core: 'WordPress/WordPress#Test', plugins: [ 'WordPress/TestPlugin#Test' ], @@ -223,16 +200,14 @@ describe( 'parseConfig', () => { }; } - if ( - configFile === path.resolve( '.', './.wp-env.override.json' ) - ) { + if ( configFile === '/test/gutenberg/.wp-env.override.json' ) { return {}; } throw new Error( 'Invalid File: ' + configFile ); } ); - const parsed = await parseConfig( './', '/cache' ); + const parsed = await parseConfig( '/test/gutenberg', '/cache' ); expect( parsed ).toEqual( { ...DEFAULT_CONFIG, @@ -285,7 +260,7 @@ describe( 'parseConfig', () => { process.env.WP_ENV_PHP_VERSION = '3.0'; process.env.WP_ENV_LIFECYCLE_SCRIPT_AFTER_START = 'test after'; - const parsed = await parseConfig( './', '/cache' ); + const parsed = await parseConfig( '/test/gutenberg', '/cache' ); expect( parsed ).toEqual( { ...DEFAULT_CONFIG, @@ -345,7 +320,7 @@ describe( 'parseConfig', () => { expect.assertions( 1 ); try { - await parseConfig( './', '/cache' ); + await parseConfig( '/test/gutenberg', '/cache' ); } catch ( error ) { expect( error ).toEqual( new ValidationError( @@ -356,15 +331,14 @@ describe( 'parseConfig', () => { } ); it( 'throws for unknown config options', async () => { - const configFileLocation = path.resolve( './.wp-env.json' ); readRawConfigFile.mockImplementation( async ( configFile ) => { - if ( configFile === path.resolve( './.wp-env.json' ) ) { + if ( configFile === '/test/gutenberg/.wp-env.json' ) { return { test: 'test', }; } - if ( configFile === path.resolve( './.wp-env.override.json' ) ) { + if ( configFile === '/test/gutenberg/.wp-env.override.json' ) { return {}; } @@ -373,20 +347,19 @@ describe( 'parseConfig', () => { expect.assertions( 1 ); try { - await parseConfig( './', '/cache' ); + await parseConfig( '/test/gutenberg', '/cache' ); } catch ( error ) { expect( error ).toEqual( new ValidationError( - `Invalid ${ configFileLocation }: "test" is not a configuration option.` + `Invalid /test/gutenberg/.wp-env.json: "test" is not a configuration option.` ) ); } } ); it( 'throws for root-only config options', async () => { - const configFileLocation = path.resolve( './.wp-env.json' ); readRawConfigFile.mockImplementation( async ( configFile ) => { - if ( configFile === configFileLocation ) { + if ( configFile === '/test/gutenberg/.wp-env.json' ) { return { env: { development: { @@ -397,7 +370,7 @@ describe( 'parseConfig', () => { }; } - if ( configFile === path.resolve( './.wp-env.override.json' ) ) { + if ( configFile === '/test/gutenberg/.wp-env.override.json' ) { return {}; } @@ -406,11 +379,11 @@ describe( 'parseConfig', () => { expect.assertions( 1 ); try { - await parseConfig( './', '/cache' ); + await parseConfig( '/test/gutenberg', '/cache' ); } catch ( error ) { expect( error ).toEqual( new ValidationError( - `Invalid ${ configFileLocation }: "development.env" is not a configuration option.` + `Invalid /test/gutenberg/.wp-env.json: "development.env" is not a configuration option.` ) ); } diff --git a/packages/env/lib/config/test/parse-source-string.js b/packages/env/lib/config/test/parse-source-string.js index a0ccc6eb6d3f71..acaec8bd5af4ba 100644 --- a/packages/env/lib/config/test/parse-source-string.js +++ b/packages/env/lib/config/test/parse-source-string.js @@ -45,7 +45,7 @@ describe( 'parseSourceString', () => { describe( 'local sources', () => { it( 'should parse relative directories', () => { expect( parseSourceString( '.', options ) ).toEqual( { - basename: 'gutenberg', + basename: path.basename( path.resolve( '.' ) ), path: path.resolve( '.' ), type: 'local', } );