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 }
0 commit comments