Skip to content

Commit 0b70248

Browse files
Removed gutenberg Directory Name Test Expectation (#50894)
1 parent a73b80e commit 0b70248

File tree

3 files changed

+35
-63
lines changed

3 files changed

+35
-63
lines changed

packages/env/lib/config/test/config-integration.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
/**
44
* External dependencies
55
*/
6-
const path = require( 'path' );
76
const { readFile } = require( 'fs' ).promises;
87

98
/**
@@ -80,7 +79,7 @@ describe( 'Config Integration', () => {
8079
throw { code: 'ENOENT' };
8180
} );
8281

83-
const config = await loadConfig( path.resolve( '/test/gutenberg' ) );
82+
const config = await loadConfig( '/test/gutenberg' );
8483

8584
expect( config.env.development.port ).toEqual( 123 );
8685
expect( config.env.tests.port ).toEqual( 8889 );
@@ -116,7 +115,7 @@ describe( 'Config Integration', () => {
116115
throw { code: 'ENOENT' };
117116
} );
118117

119-
const config = await loadConfig( path.resolve( '/test/gutenberg' ) );
118+
const config = await loadConfig( '/test/gutenberg' );
120119

121120
expect( config.env.development.port ).toEqual( 999 );
122121
expect( config.env.tests.port ).toEqual( 456 );
@@ -151,7 +150,7 @@ describe( 'Config Integration', () => {
151150
throw { code: 'ENOENT' };
152151
} );
153152

154-
const config = await loadConfig( path.resolve( '/test/gutenberg' ) );
153+
const config = await loadConfig( '/test/gutenberg' );
155154

156155
expect( config.env.development.port ).toEqual( 12345 );
157156
expect( config.env.tests.port ).toEqual( 61234 );

packages/env/lib/config/test/parse-config.js

Lines changed: 31 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
11
'use strict';
22
/* eslint-disable jest/no-conditional-expect */
3-
/**
4-
* External dependencies
5-
*/
6-
const path = require( 'path' );
7-
83
/**
94
* Internal dependencies
105
*/
@@ -84,64 +79,46 @@ describe( 'parseConfig', () => {
8479
} );
8580

8681
it( 'should return default config', async () => {
87-
const parsed = await parseConfig( './', '/cache' );
82+
const parsed = await parseConfig( '/test/gutenberg', '/cache' );
8883

8984
expect( parsed ).toEqual( DEFAULT_CONFIG );
9085
} );
9186

9287
it( 'should infer a core mounting default when ran from a WordPress directory', async () => {
9388
detectDirectoryType.mockResolvedValue( 'core' );
9489

95-
const parsed = await parseConfig( './', '/cache' );
90+
const parsed = await parseConfig( '/test/gutenberg', '/cache' );
9691

97-
expect( parsed ).toEqual( {
98-
...DEFAULT_CONFIG,
99-
coreSource: {
100-
basename: 'gutenberg',
101-
path: path.resolve( '.' ),
102-
testsPath: '/cache/tests-gutenberg',
103-
type: 'local',
104-
},
105-
} );
92+
expect( parsed.pluginSources ).toHaveLength( 0 );
93+
expect( parsed.themeSources ).toHaveLength( 0 );
94+
expect( parsed.coreSource ).toMatchObject( { type: 'local' } );
10695
} );
10796

10897
it( 'should infer a plugin mounting default when ran from a plugin directory', async () => {
10998
detectDirectoryType.mockResolvedValue( 'plugin' );
11099

111-
const parsed = await parseConfig( './', '/cache' );
100+
const parsed = await parseConfig( '/test/gutenberg', '/cache' );
112101

113-
expect( parsed ).toEqual( {
114-
...DEFAULT_CONFIG,
115-
pluginSources: [
116-
{
117-
basename: 'gutenberg',
118-
path: path.resolve( '.' ),
119-
type: 'local',
120-
},
121-
],
122-
} );
102+
expect( parsed.coreSource ).toMatchObject( { type: 'git' } );
103+
expect( parsed.themeSources ).toHaveLength( 0 );
104+
expect( parsed.pluginSources ).toHaveLength( 1 );
105+
expect( parsed.pluginSources[ 0 ] ).toMatchObject( { type: 'local' } );
123106
} );
124107

125108
it( 'should infer a theme mounting default when ran from a theme directory', async () => {
126109
detectDirectoryType.mockResolvedValue( 'theme' );
127110

128-
const parsed = await parseConfig( './', '/cache' );
111+
const parsed = await parseConfig( '/test/gutenberg', '/cache' );
129112

130-
expect( parsed ).toEqual( {
131-
...DEFAULT_CONFIG,
132-
themeSources: [
133-
{
134-
basename: 'gutenberg',
135-
path: path.resolve( '.' ),
136-
type: 'local',
137-
},
138-
],
139-
} );
113+
expect( parsed.coreSource ).toMatchObject( { type: 'git' } );
114+
expect( parsed.pluginSources ).toHaveLength( 0 );
115+
expect( parsed.themeSources ).toHaveLength( 1 );
116+
expect( parsed.themeSources[ 0 ] ).toMatchObject( { type: 'local' } );
140117
} );
141118

142119
it( 'should merge configs with precedence', async () => {
143120
readRawConfigFile.mockImplementation( async ( configFile ) => {
144-
if ( configFile === path.resolve( './.wp-env.json' ) ) {
121+
if ( configFile === '/test/gutenberg/.wp-env.json' ) {
145122
return {
146123
core: 'WordPress/WordPress#Test',
147124
phpVersion: '1.0',
@@ -159,7 +136,7 @@ describe( 'parseConfig', () => {
159136
};
160137
}
161138

162-
if ( configFile === path.resolve( './.wp-env.override.json' ) ) {
139+
if ( configFile === '/test/gutenberg/.wp-env.override.json' ) {
163140
return {
164141
phpVersion: '2.0',
165142
lifecycleScripts: {
@@ -176,7 +153,7 @@ describe( 'parseConfig', () => {
176153
throw new Error( 'Invalid File: ' + configFile );
177154
} );
178155

179-
const parsed = await parseConfig( './', '/cache' );
156+
const parsed = await parseConfig( '/test/gutenberg', '/cache' );
180157

181158
const expected = {
182159
...DEFAULT_CONFIG,
@@ -211,7 +188,7 @@ describe( 'parseConfig', () => {
211188

212189
it( 'should parse core, plugin, theme, and mapping sources', async () => {
213190
readRawConfigFile.mockImplementation( async ( configFile ) => {
214-
if ( configFile === path.resolve( '.', './.wp-env.json' ) ) {
191+
if ( configFile === '/test/gutenberg/.wp-env.json' ) {
215192
return {
216193
core: 'WordPress/WordPress#Test',
217194
plugins: [ 'WordPress/TestPlugin#Test' ],
@@ -223,16 +200,14 @@ describe( 'parseConfig', () => {
223200
};
224201
}
225202

226-
if (
227-
configFile === path.resolve( '.', './.wp-env.override.json' )
228-
) {
203+
if ( configFile === '/test/gutenberg/.wp-env.override.json' ) {
229204
return {};
230205
}
231206

232207
throw new Error( 'Invalid File: ' + configFile );
233208
} );
234209

235-
const parsed = await parseConfig( './', '/cache' );
210+
const parsed = await parseConfig( '/test/gutenberg', '/cache' );
236211

237212
expect( parsed ).toEqual( {
238213
...DEFAULT_CONFIG,
@@ -285,7 +260,7 @@ describe( 'parseConfig', () => {
285260
process.env.WP_ENV_PHP_VERSION = '3.0';
286261
process.env.WP_ENV_LIFECYCLE_SCRIPT_AFTER_START = 'test after';
287262

288-
const parsed = await parseConfig( './', '/cache' );
263+
const parsed = await parseConfig( '/test/gutenberg', '/cache' );
289264

290265
expect( parsed ).toEqual( {
291266
...DEFAULT_CONFIG,
@@ -345,7 +320,7 @@ describe( 'parseConfig', () => {
345320

346321
expect.assertions( 1 );
347322
try {
348-
await parseConfig( './', '/cache' );
323+
await parseConfig( '/test/gutenberg', '/cache' );
349324
} catch ( error ) {
350325
expect( error ).toEqual(
351326
new ValidationError(
@@ -356,15 +331,14 @@ describe( 'parseConfig', () => {
356331
} );
357332

358333
it( 'throws for unknown config options', async () => {
359-
const configFileLocation = path.resolve( './.wp-env.json' );
360334
readRawConfigFile.mockImplementation( async ( configFile ) => {
361-
if ( configFile === path.resolve( './.wp-env.json' ) ) {
335+
if ( configFile === '/test/gutenberg/.wp-env.json' ) {
362336
return {
363337
test: 'test',
364338
};
365339
}
366340

367-
if ( configFile === path.resolve( './.wp-env.override.json' ) ) {
341+
if ( configFile === '/test/gutenberg/.wp-env.override.json' ) {
368342
return {};
369343
}
370344

@@ -373,20 +347,19 @@ describe( 'parseConfig', () => {
373347

374348
expect.assertions( 1 );
375349
try {
376-
await parseConfig( './', '/cache' );
350+
await parseConfig( '/test/gutenberg', '/cache' );
377351
} catch ( error ) {
378352
expect( error ).toEqual(
379353
new ValidationError(
380-
`Invalid ${ configFileLocation }: "test" is not a configuration option.`
354+
`Invalid /test/gutenberg/.wp-env.json: "test" is not a configuration option.`
381355
)
382356
);
383357
}
384358
} );
385359

386360
it( 'throws for root-only config options', async () => {
387-
const configFileLocation = path.resolve( './.wp-env.json' );
388361
readRawConfigFile.mockImplementation( async ( configFile ) => {
389-
if ( configFile === configFileLocation ) {
362+
if ( configFile === '/test/gutenberg/.wp-env.json' ) {
390363
return {
391364
env: {
392365
development: {
@@ -397,7 +370,7 @@ describe( 'parseConfig', () => {
397370
};
398371
}
399372

400-
if ( configFile === path.resolve( './.wp-env.override.json' ) ) {
373+
if ( configFile === '/test/gutenberg/.wp-env.override.json' ) {
401374
return {};
402375
}
403376

@@ -406,11 +379,11 @@ describe( 'parseConfig', () => {
406379

407380
expect.assertions( 1 );
408381
try {
409-
await parseConfig( './', '/cache' );
382+
await parseConfig( '/test/gutenberg', '/cache' );
410383
} catch ( error ) {
411384
expect( error ).toEqual(
412385
new ValidationError(
413-
`Invalid ${ configFileLocation }: "development.env" is not a configuration option.`
386+
`Invalid /test/gutenberg/.wp-env.json: "development.env" is not a configuration option.`
414387
)
415388
);
416389
}

packages/env/lib/config/test/parse-source-string.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ describe( 'parseSourceString', () => {
4545
describe( 'local sources', () => {
4646
it( 'should parse relative directories', () => {
4747
expect( parseSourceString( '.', options ) ).toEqual( {
48-
basename: 'gutenberg',
48+
basename: path.basename( path.resolve( '.' ) ),
4949
path: path.resolve( '.' ),
5050
type: 'local',
5151
} );

0 commit comments

Comments
 (0)