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

Removed gutenberg Directory Name Expectation #50894

Merged
merged 1 commit into from
May 23, 2023
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
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