Skip to content

Commit

Permalink
Removed gutenberg Directory Name Test Expectation (#50894)
Browse files Browse the repository at this point in the history
  • Loading branch information
ObliviousHarmony authored May 23, 2023
1 parent a73b80e commit 0b70248
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 63 deletions.
7 changes: 3 additions & 4 deletions packages/env/lib/config/test/config-integration.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
/**
* External dependencies
*/
const path = require( 'path' );
const { readFile } = require( 'fs' ).promises;

/**
Expand Down Expand Up @@ -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 );
Expand Down Expand Up @@ -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 );
Expand Down Expand Up @@ -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 );
Expand Down
89 changes: 31 additions & 58 deletions packages/env/lib/config/test/parse-config.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
'use strict';
/* eslint-disable jest/no-conditional-expect */
/**
* External dependencies
*/
const path = require( 'path' );

/**
* Internal dependencies
*/
Expand Down Expand Up @@ -84,64 +79,46 @@ 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 );
} );

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',
Expand All @@ -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: {
Expand All @@ -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,
Expand Down Expand Up @@ -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' ],
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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(
Expand All @@ -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 {};
}

Expand All @@ -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: {
Expand All @@ -397,7 +370,7 @@ describe( 'parseConfig', () => {
};
}

if ( configFile === path.resolve( './.wp-env.override.json' ) ) {
if ( configFile === '/test/gutenberg/.wp-env.override.json' ) {
return {};
}

Expand All @@ -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.`
)
);
}
Expand Down
2 changes: 1 addition & 1 deletion packages/env/lib/config/test/parse-source-string.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
} );
Expand Down

0 comments on commit 0b70248

Please sign in to comment.