@wordpress/env 6.0.0 → 7.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +109 -43
- package/lib/build-docker-compose-config.js +67 -96
- package/lib/cache.js +1 -0
- package/lib/cli.js +16 -3
- package/lib/commands/clean.js +14 -1
- package/lib/commands/destroy.js +12 -37
- package/lib/commands/index.js +1 -0
- package/lib/commands/install-path.js +1 -0
- package/lib/commands/logs.js +1 -0
- package/lib/commands/run.js +59 -3
- package/lib/commands/start.js +30 -8
- package/lib/commands/stop.js +1 -0
- package/lib/config/add-or-replace-port.js +12 -3
- package/lib/config/db-env.js +1 -0
- package/lib/config/detect-directory-type.js +1 -1
- package/lib/config/get-cache-directory.js +39 -0
- package/lib/config/get-config-from-environment-vars.js +86 -0
- package/lib/config/index.js +7 -5
- package/lib/config/load-config.js +92 -0
- package/lib/config/merge-configs.js +104 -0
- package/lib/config/parse-config.js +418 -157
- package/lib/config/parse-source-string.js +164 -0
- package/lib/config/post-process-config.js +202 -0
- package/lib/config/read-raw-config-file.js +7 -33
- package/lib/config/test/__snapshots__/config-integration.js.snap +271 -0
- package/lib/config/test/add-or-replace-port.js +29 -1
- package/lib/config/test/config-integration.js +143 -0
- package/lib/config/test/get-cache-directory.js +57 -0
- package/lib/config/test/merge-configs.js +111 -0
- package/lib/config/test/parse-config.js +342 -0
- package/lib/config/test/parse-source-string.js +154 -0
- package/lib/config/test/post-process-config.js +295 -0
- package/lib/config/test/read-raw-config-file.js +19 -63
- package/lib/config/test/validate-config.js +305 -0
- package/lib/config/validate-config.js +93 -54
- package/lib/env.js +2 -0
- package/lib/execute-after-setup.js +51 -0
- package/lib/get-host-user.js +31 -0
- package/lib/init-config.js +181 -63
- package/lib/md5.js +1 -0
- package/lib/parse-xdebug-mode.js +1 -0
- package/lib/retry.js +1 -0
- package/lib/test/__snapshots__/md5.js.snap +9 -0
- package/lib/test/build-docker-compose-config.js +134 -0
- package/lib/test/cache.js +154 -0
- package/lib/test/cli.js +149 -0
- package/lib/test/execute-after-setup.js +66 -0
- package/lib/test/md5.js +35 -0
- package/lib/test/parse-xdebug-mode.js +41 -0
- package/lib/wordpress.js +4 -19
- package/package.json +2 -2
- package/lib/config/config.js +0 -353
- package/lib/config/test/__snapshots__/config.js.snap +0 -83
- package/lib/config/test/config.js +0 -1241
|
@@ -1,10 +1,11 @@
|
|
|
1
|
+
'use strict';
|
|
1
2
|
/**
|
|
2
3
|
* Internal dependencies
|
|
3
4
|
*/
|
|
4
5
|
const addOrReplacePort = require( '../add-or-replace-port.js' );
|
|
5
6
|
|
|
6
7
|
describe( 'addOrReplacePort', () => {
|
|
7
|
-
|
|
8
|
+
afterEach( () => {
|
|
8
9
|
jest.clearAllMocks();
|
|
9
10
|
} );
|
|
10
11
|
|
|
@@ -39,6 +40,33 @@ describe( 'addOrReplacePort', () => {
|
|
|
39
40
|
}
|
|
40
41
|
} );
|
|
41
42
|
|
|
43
|
+
it( 'should support number ports', () => {
|
|
44
|
+
const testMap = [ { in: 'test', expect: 'test:104' } ];
|
|
45
|
+
|
|
46
|
+
for ( const test of testMap ) {
|
|
47
|
+
const result = addOrReplacePort( test.in, 104, false );
|
|
48
|
+
expect( result ).toEqual( test.expect );
|
|
49
|
+
}
|
|
50
|
+
} );
|
|
51
|
+
|
|
52
|
+
it( 'should not add default HTTP port', () => {
|
|
53
|
+
const testMap = [ { in: 'test', expect: 'test' } ];
|
|
54
|
+
|
|
55
|
+
for ( const test of testMap ) {
|
|
56
|
+
const result = addOrReplacePort( test.in, 80, false );
|
|
57
|
+
expect( result ).toEqual( test.expect );
|
|
58
|
+
}
|
|
59
|
+
} );
|
|
60
|
+
|
|
61
|
+
it( 'should not add default HTTPS port', () => {
|
|
62
|
+
const testMap = [ { in: 'test', expect: 'test' } ];
|
|
63
|
+
|
|
64
|
+
for ( const test of testMap ) {
|
|
65
|
+
const result = addOrReplacePort( test.in, 443, false );
|
|
66
|
+
expect( result ).toEqual( test.expect );
|
|
67
|
+
}
|
|
68
|
+
} );
|
|
69
|
+
|
|
42
70
|
it( 'should do nothing if port is present but replacement is not requested', () => {
|
|
43
71
|
const testMap = [
|
|
44
72
|
{ in: 'test', expect: 'test:103' },
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
/* eslint-disable jest/no-conditional-expect */
|
|
3
|
+
/**
|
|
4
|
+
* External dependencies
|
|
5
|
+
*/
|
|
6
|
+
const path = require( 'path' );
|
|
7
|
+
const { readFile } = require( 'fs' ).promises;
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Internal dependencies
|
|
11
|
+
*/
|
|
12
|
+
const loadConfig = require( '../load-config' );
|
|
13
|
+
const detectDirectoryType = require( '../detect-directory-type' );
|
|
14
|
+
|
|
15
|
+
jest.mock( 'fs', () => ( {
|
|
16
|
+
promises: {
|
|
17
|
+
readFile: jest.fn(),
|
|
18
|
+
stat: jest.fn().mockResolvedValue( true ),
|
|
19
|
+
},
|
|
20
|
+
} ) );
|
|
21
|
+
|
|
22
|
+
// This mocks a small response with a format matching the stable-check API.
|
|
23
|
+
// It makes getLatestWordPressVersion resolve to "100.0.0".
|
|
24
|
+
jest.mock( 'got', () =>
|
|
25
|
+
jest.fn( ( url ) => ( {
|
|
26
|
+
json: () => {
|
|
27
|
+
if ( url === 'https://api.wordpress.org/core/stable-check/1.0/' ) {
|
|
28
|
+
return Promise.resolve( {
|
|
29
|
+
'1.0': 'insecure',
|
|
30
|
+
'99.1.1': 'outdated',
|
|
31
|
+
'100.0.0': 'latest',
|
|
32
|
+
'100.0.1': 'fancy',
|
|
33
|
+
} );
|
|
34
|
+
}
|
|
35
|
+
},
|
|
36
|
+
} ) )
|
|
37
|
+
);
|
|
38
|
+
|
|
39
|
+
jest.mock( '../detect-directory-type', () => jest.fn() );
|
|
40
|
+
|
|
41
|
+
describe( 'Config Integration', () => {
|
|
42
|
+
beforeEach( () => {
|
|
43
|
+
process.env.WP_ENV_HOME = '/cache';
|
|
44
|
+
detectDirectoryType.mockResolvedValue( null );
|
|
45
|
+
} );
|
|
46
|
+
|
|
47
|
+
afterEach( () => {
|
|
48
|
+
delete process.env.WP_ENV_HOME;
|
|
49
|
+
delete process.env.WP_ENV_PORT;
|
|
50
|
+
delete process.env.WP_ENV_TESTS_PORT;
|
|
51
|
+
delete process.env.WP_ENV_AFTER_SETUP;
|
|
52
|
+
} );
|
|
53
|
+
|
|
54
|
+
it( 'should use default configuration', async () => {
|
|
55
|
+
readFile.mockImplementation( async () => {
|
|
56
|
+
throw { code: 'ENOENT' };
|
|
57
|
+
} );
|
|
58
|
+
|
|
59
|
+
const config = await loadConfig( '/test/gutenberg' );
|
|
60
|
+
|
|
61
|
+
expect( config.env.development.port ).toEqual( 8888 );
|
|
62
|
+
expect( config.env.tests.port ).toEqual( 8889 );
|
|
63
|
+
expect( config ).toMatchSnapshot();
|
|
64
|
+
} );
|
|
65
|
+
|
|
66
|
+
it( 'should load local configuration file', async () => {
|
|
67
|
+
readFile.mockImplementation( async ( fileName ) => {
|
|
68
|
+
if ( fileName === '/test/gutenberg/.wp-env.json' ) {
|
|
69
|
+
return JSON.stringify( {
|
|
70
|
+
core: 'WordPress/WordPress#trunk',
|
|
71
|
+
port: 123,
|
|
72
|
+
afterSetup: 'test',
|
|
73
|
+
} );
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
throw { code: 'ENOENT' };
|
|
77
|
+
} );
|
|
78
|
+
|
|
79
|
+
const config = await loadConfig( path.resolve( '/test/gutenberg' ) );
|
|
80
|
+
|
|
81
|
+
expect( config.env.development.port ).toEqual( 123 );
|
|
82
|
+
expect( config.env.tests.port ).toEqual( 8889 );
|
|
83
|
+
expect( config ).toMatchSnapshot();
|
|
84
|
+
} );
|
|
85
|
+
|
|
86
|
+
it( 'should load local and override configuration files', async () => {
|
|
87
|
+
readFile.mockImplementation( async ( fileName ) => {
|
|
88
|
+
if ( fileName === '/test/gutenberg/.wp-env.json' ) {
|
|
89
|
+
return JSON.stringify( {
|
|
90
|
+
core: 'WordPress/WordPress#trunk',
|
|
91
|
+
port: 123,
|
|
92
|
+
testsPort: 456,
|
|
93
|
+
} );
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
if ( fileName === '/test/gutenberg/.wp-env.override.json' ) {
|
|
97
|
+
return JSON.stringify( {
|
|
98
|
+
port: 999,
|
|
99
|
+
} );
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
throw { code: 'ENOENT' };
|
|
103
|
+
} );
|
|
104
|
+
|
|
105
|
+
const config = await loadConfig( path.resolve( '/test/gutenberg' ) );
|
|
106
|
+
|
|
107
|
+
expect( config.env.development.port ).toEqual( 999 );
|
|
108
|
+
expect( config.env.tests.port ).toEqual( 456 );
|
|
109
|
+
expect( config ).toMatchSnapshot();
|
|
110
|
+
} );
|
|
111
|
+
|
|
112
|
+
it( 'should use environment variables over local and override configuration files', async () => {
|
|
113
|
+
process.env.WP_ENV_PORT = 12345;
|
|
114
|
+
process.env.WP_ENV_TESTS_PORT = 61234;
|
|
115
|
+
process.env.WP_ENV_AFTER_SETUP = 'test';
|
|
116
|
+
|
|
117
|
+
readFile.mockImplementation( async ( fileName ) => {
|
|
118
|
+
if ( fileName === '/test/gutenberg/.wp-env.json' ) {
|
|
119
|
+
return JSON.stringify( {
|
|
120
|
+
core: 'WordPress/WordPress#trunk',
|
|
121
|
+
port: 123,
|
|
122
|
+
testsPort: 456,
|
|
123
|
+
afterSetup: 'local',
|
|
124
|
+
} );
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
if ( fileName === '/test/gutenberg/.wp-env.override.json' ) {
|
|
128
|
+
return JSON.stringify( {
|
|
129
|
+
port: 999,
|
|
130
|
+
} );
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
throw { code: 'ENOENT' };
|
|
134
|
+
} );
|
|
135
|
+
|
|
136
|
+
const config = await loadConfig( path.resolve( '/test/gutenberg' ) );
|
|
137
|
+
|
|
138
|
+
expect( config.env.development.port ).toEqual( 12345 );
|
|
139
|
+
expect( config.env.tests.port ).toEqual( 61234 );
|
|
140
|
+
expect( config ).toMatchSnapshot();
|
|
141
|
+
} );
|
|
142
|
+
} );
|
|
143
|
+
/* eslint-enable jest/no-conditional-expect */
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
/* eslint-disable jest/no-conditional-expect */
|
|
3
|
+
/**
|
|
4
|
+
* External dependencies
|
|
5
|
+
*/
|
|
6
|
+
const { stat } = require( 'fs' ).promises;
|
|
7
|
+
const { homedir } = require( 'os' );
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Internal dependencies
|
|
11
|
+
*/
|
|
12
|
+
const getCacheDirectory = require( '../get-cache-directory' );
|
|
13
|
+
|
|
14
|
+
jest.mock( 'fs', () => ( {
|
|
15
|
+
promises: {
|
|
16
|
+
stat: jest.fn(),
|
|
17
|
+
},
|
|
18
|
+
} ) );
|
|
19
|
+
jest.mock( 'os', () => ( {
|
|
20
|
+
homedir: jest.fn(),
|
|
21
|
+
} ) );
|
|
22
|
+
|
|
23
|
+
describe( 'getCacheDirectory', () => {
|
|
24
|
+
afterEach( () => {
|
|
25
|
+
delete process.env.WP_ENV_HOME;
|
|
26
|
+
} );
|
|
27
|
+
|
|
28
|
+
it( 'uses WP_ENV_HOME for cache directory when set', async () => {
|
|
29
|
+
process.env.WP_ENV_HOME = '/test';
|
|
30
|
+
|
|
31
|
+
const parsed = await getCacheDirectory();
|
|
32
|
+
|
|
33
|
+
expect( homedir ).not.toHaveBeenCalled();
|
|
34
|
+
expect( parsed ).toEqual( '/test' );
|
|
35
|
+
} );
|
|
36
|
+
|
|
37
|
+
it( 'uses hidden home directory for cache', async () => {
|
|
38
|
+
stat.mockRejectedValue( false );
|
|
39
|
+
homedir.mockReturnValue( '/home/test' );
|
|
40
|
+
|
|
41
|
+
const parsed = await getCacheDirectory();
|
|
42
|
+
|
|
43
|
+
expect( homedir ).toHaveBeenCalled();
|
|
44
|
+
expect( parsed ).toEqual( '/home/test/.wp-env' );
|
|
45
|
+
} );
|
|
46
|
+
|
|
47
|
+
it( 'uses non-hidden cache directory when using Snap-installed Docker', async () => {
|
|
48
|
+
stat.mockResolvedValue( true );
|
|
49
|
+
homedir.mockReturnValue( '/home/test' );
|
|
50
|
+
|
|
51
|
+
const parsed = await getCacheDirectory();
|
|
52
|
+
|
|
53
|
+
expect( homedir ).toHaveBeenCalled();
|
|
54
|
+
expect( parsed ).toEqual( '/home/test/wp-env' );
|
|
55
|
+
} );
|
|
56
|
+
} );
|
|
57
|
+
/* eslint-enable jest/no-conditional-expect */
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
/**
|
|
3
|
+
* Internal dependencies
|
|
4
|
+
*/
|
|
5
|
+
const mergeConfigs = require( '../merge-configs' );
|
|
6
|
+
|
|
7
|
+
describe( 'mergeConfigs', () => {
|
|
8
|
+
it( 'should merge configs without environments', () => {
|
|
9
|
+
const merged = mergeConfigs(
|
|
10
|
+
{
|
|
11
|
+
port: 8888,
|
|
12
|
+
coreSource: {
|
|
13
|
+
type: 'local',
|
|
14
|
+
path: '/home/test',
|
|
15
|
+
},
|
|
16
|
+
config: {
|
|
17
|
+
WP_TEST: 'test',
|
|
18
|
+
},
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
port: 8889,
|
|
22
|
+
config: {
|
|
23
|
+
WP_TEST_2: 'test-2',
|
|
24
|
+
},
|
|
25
|
+
}
|
|
26
|
+
);
|
|
27
|
+
|
|
28
|
+
expect( merged ).toEqual( {
|
|
29
|
+
port: 8889,
|
|
30
|
+
coreSource: {
|
|
31
|
+
type: 'local',
|
|
32
|
+
path: '/home/test',
|
|
33
|
+
},
|
|
34
|
+
config: {
|
|
35
|
+
WP_TEST: 'test',
|
|
36
|
+
WP_TEST_2: 'test-2',
|
|
37
|
+
},
|
|
38
|
+
} );
|
|
39
|
+
} );
|
|
40
|
+
|
|
41
|
+
it( 'should merge configs with environments', () => {
|
|
42
|
+
const merged = mergeConfigs(
|
|
43
|
+
{
|
|
44
|
+
port: 8888,
|
|
45
|
+
coreSource: {
|
|
46
|
+
type: 'local',
|
|
47
|
+
path: '/home/test',
|
|
48
|
+
},
|
|
49
|
+
config: {
|
|
50
|
+
WP_TEST: 'test',
|
|
51
|
+
},
|
|
52
|
+
env: {
|
|
53
|
+
development: {
|
|
54
|
+
config: {
|
|
55
|
+
WP_TEST_3: 'test-3',
|
|
56
|
+
},
|
|
57
|
+
},
|
|
58
|
+
tests: {
|
|
59
|
+
config: {
|
|
60
|
+
WP_TEST_4: 'test-4',
|
|
61
|
+
},
|
|
62
|
+
},
|
|
63
|
+
},
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
port: 8889,
|
|
67
|
+
config: {
|
|
68
|
+
WP_TEST_2: 'test-2',
|
|
69
|
+
},
|
|
70
|
+
env: {
|
|
71
|
+
development: {
|
|
72
|
+
config: {
|
|
73
|
+
WP_TEST_5: 'test-5',
|
|
74
|
+
},
|
|
75
|
+
},
|
|
76
|
+
tests: {
|
|
77
|
+
config: {
|
|
78
|
+
WP_TEST_6: 'test-6',
|
|
79
|
+
},
|
|
80
|
+
},
|
|
81
|
+
},
|
|
82
|
+
}
|
|
83
|
+
);
|
|
84
|
+
|
|
85
|
+
expect( merged ).toEqual( {
|
|
86
|
+
port: 8889,
|
|
87
|
+
coreSource: {
|
|
88
|
+
type: 'local',
|
|
89
|
+
path: '/home/test',
|
|
90
|
+
},
|
|
91
|
+
config: {
|
|
92
|
+
WP_TEST: 'test',
|
|
93
|
+
WP_TEST_2: 'test-2',
|
|
94
|
+
},
|
|
95
|
+
env: {
|
|
96
|
+
development: {
|
|
97
|
+
config: {
|
|
98
|
+
WP_TEST_3: 'test-3',
|
|
99
|
+
WP_TEST_5: 'test-5',
|
|
100
|
+
},
|
|
101
|
+
},
|
|
102
|
+
tests: {
|
|
103
|
+
config: {
|
|
104
|
+
WP_TEST_4: 'test-4',
|
|
105
|
+
WP_TEST_6: 'test-6',
|
|
106
|
+
},
|
|
107
|
+
},
|
|
108
|
+
},
|
|
109
|
+
} );
|
|
110
|
+
} );
|
|
111
|
+
} );
|
|
@@ -0,0 +1,342 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
/* eslint-disable jest/no-conditional-expect */
|
|
3
|
+
/**
|
|
4
|
+
* External dependencies
|
|
5
|
+
*/
|
|
6
|
+
const path = require( 'path' );
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Internal dependencies
|
|
10
|
+
*/
|
|
11
|
+
const { parseConfig } = require( '../parse-config' );
|
|
12
|
+
const readRawConfigFile = require( '../read-raw-config-file' );
|
|
13
|
+
const { getLatestWordPressVersion } = require( '../../wordpress' );
|
|
14
|
+
const { ValidationError } = require( '../validate-config' );
|
|
15
|
+
const detectDirectoryType = require( '../detect-directory-type' );
|
|
16
|
+
|
|
17
|
+
jest.mock( 'got', () => jest.fn() );
|
|
18
|
+
jest.mock( '../read-raw-config-file', () => jest.fn() );
|
|
19
|
+
jest.mock( '../detect-directory-type', () => jest.fn() );
|
|
20
|
+
jest.mock( '../../wordpress', () => ( {
|
|
21
|
+
getLatestWordPressVersion: jest.fn(),
|
|
22
|
+
} ) );
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Since our configurations are merged, we will want to refer to the parsed default config frequently.
|
|
26
|
+
*/
|
|
27
|
+
const DEFAULT_CONFIG = {
|
|
28
|
+
port: 8888,
|
|
29
|
+
testsPort: 8889,
|
|
30
|
+
phpVersion: null,
|
|
31
|
+
coreSource: {
|
|
32
|
+
type: 'git',
|
|
33
|
+
url: 'https://github.com/WordPress/WordPress.git',
|
|
34
|
+
ref: '100.0.0',
|
|
35
|
+
path: '/cache/WordPress',
|
|
36
|
+
clonePath: '/cache/WordPress',
|
|
37
|
+
basename: 'WordPress',
|
|
38
|
+
testsPath: '/cache/tests-WordPress',
|
|
39
|
+
},
|
|
40
|
+
pluginSources: [],
|
|
41
|
+
themeSources: [],
|
|
42
|
+
config: {
|
|
43
|
+
WP_DEBUG: true,
|
|
44
|
+
SCRIPT_DEBUG: true,
|
|
45
|
+
WP_ENVIRONMENT_TYPE: 'local',
|
|
46
|
+
WP_PHP_BINARY: 'php',
|
|
47
|
+
WP_TESTS_EMAIL: 'admin@example.org',
|
|
48
|
+
WP_TESTS_TITLE: 'Test Blog',
|
|
49
|
+
WP_TESTS_DOMAIN: 'localhost',
|
|
50
|
+
WP_SITEURL: 'http://localhost',
|
|
51
|
+
WP_HOME: 'http://localhost',
|
|
52
|
+
},
|
|
53
|
+
mappings: {},
|
|
54
|
+
afterSetup: null,
|
|
55
|
+
env: {
|
|
56
|
+
development: {},
|
|
57
|
+
tests: {
|
|
58
|
+
config: {
|
|
59
|
+
WP_DEBUG: false,
|
|
60
|
+
SCRIPT_DEBUG: false,
|
|
61
|
+
},
|
|
62
|
+
},
|
|
63
|
+
},
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
describe( 'parseConfig', () => {
|
|
67
|
+
beforeEach( () => {
|
|
68
|
+
readRawConfigFile.mockResolvedValue( null );
|
|
69
|
+
detectDirectoryType.mockResolvedValue( null );
|
|
70
|
+
getLatestWordPressVersion.mockResolvedValue( '100.0.0' );
|
|
71
|
+
} );
|
|
72
|
+
|
|
73
|
+
afterEach( () => {
|
|
74
|
+
jest.clearAllMocks();
|
|
75
|
+
delete process.env.WP_ENV_PORT;
|
|
76
|
+
delete process.env.WP_ENV_TESTS_PORT;
|
|
77
|
+
delete process.env.WP_ENV_CORE;
|
|
78
|
+
delete process.env.WP_ENV_PHP_VERSION;
|
|
79
|
+
delete process.env.WP_ENV_AFTER_SETUP;
|
|
80
|
+
} );
|
|
81
|
+
|
|
82
|
+
it( 'should return default config', async () => {
|
|
83
|
+
const parsed = await parseConfig( './', '/cache' );
|
|
84
|
+
|
|
85
|
+
expect( parsed ).toEqual( DEFAULT_CONFIG );
|
|
86
|
+
} );
|
|
87
|
+
|
|
88
|
+
it( 'should infer a core mounting default when ran from a WordPress directory', async () => {
|
|
89
|
+
detectDirectoryType.mockResolvedValue( 'core' );
|
|
90
|
+
|
|
91
|
+
const parsed = await parseConfig( './', '/cache' );
|
|
92
|
+
|
|
93
|
+
expect( parsed ).toEqual( {
|
|
94
|
+
...DEFAULT_CONFIG,
|
|
95
|
+
coreSource: {
|
|
96
|
+
basename: 'gutenberg',
|
|
97
|
+
path: path.resolve( '.' ),
|
|
98
|
+
testsPath: '/cache/tests-gutenberg',
|
|
99
|
+
type: 'local',
|
|
100
|
+
},
|
|
101
|
+
} );
|
|
102
|
+
} );
|
|
103
|
+
|
|
104
|
+
it( 'should infer a plugin mounting default when ran from a plugin directory', async () => {
|
|
105
|
+
detectDirectoryType.mockResolvedValue( 'plugin' );
|
|
106
|
+
|
|
107
|
+
const parsed = await parseConfig( './', '/cache' );
|
|
108
|
+
|
|
109
|
+
expect( parsed ).toEqual( {
|
|
110
|
+
...DEFAULT_CONFIG,
|
|
111
|
+
pluginSources: [
|
|
112
|
+
{
|
|
113
|
+
basename: 'gutenberg',
|
|
114
|
+
path: path.resolve( '.' ),
|
|
115
|
+
type: 'local',
|
|
116
|
+
},
|
|
117
|
+
],
|
|
118
|
+
} );
|
|
119
|
+
} );
|
|
120
|
+
|
|
121
|
+
it( 'should infer a theme mounting default when ran from a theme directory', async () => {
|
|
122
|
+
detectDirectoryType.mockResolvedValue( 'theme' );
|
|
123
|
+
|
|
124
|
+
const parsed = await parseConfig( './', '/cache' );
|
|
125
|
+
|
|
126
|
+
expect( parsed ).toEqual( {
|
|
127
|
+
...DEFAULT_CONFIG,
|
|
128
|
+
themeSources: [
|
|
129
|
+
{
|
|
130
|
+
basename: 'gutenberg',
|
|
131
|
+
path: path.resolve( '.' ),
|
|
132
|
+
type: 'local',
|
|
133
|
+
},
|
|
134
|
+
],
|
|
135
|
+
} );
|
|
136
|
+
} );
|
|
137
|
+
|
|
138
|
+
it( 'should merge configs with precedence', async () => {
|
|
139
|
+
readRawConfigFile.mockImplementation( async ( configFile ) => {
|
|
140
|
+
if ( configFile === path.resolve( './.wp-env.json' ) ) {
|
|
141
|
+
return {
|
|
142
|
+
core: 'WordPress/WordPress#Test',
|
|
143
|
+
phpVersion: '1.0',
|
|
144
|
+
afterSetup: 'test',
|
|
145
|
+
env: {
|
|
146
|
+
development: {
|
|
147
|
+
port: 1234,
|
|
148
|
+
},
|
|
149
|
+
tests: {
|
|
150
|
+
port: 5678,
|
|
151
|
+
},
|
|
152
|
+
},
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
if ( configFile === path.resolve( './.wp-env.override.json' ) ) {
|
|
157
|
+
return {
|
|
158
|
+
phpVersion: '2.0',
|
|
159
|
+
env: {
|
|
160
|
+
tests: {
|
|
161
|
+
port: 1011,
|
|
162
|
+
},
|
|
163
|
+
},
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
throw new Error( 'Invalid File: ' + configFile );
|
|
168
|
+
} );
|
|
169
|
+
|
|
170
|
+
const parsed = await parseConfig( './', '/cache' );
|
|
171
|
+
|
|
172
|
+
const expected = {
|
|
173
|
+
...DEFAULT_CONFIG,
|
|
174
|
+
coreSource: {
|
|
175
|
+
basename: 'WordPress',
|
|
176
|
+
path: '/cache/WordPress',
|
|
177
|
+
clonePath: '/cache/WordPress',
|
|
178
|
+
ref: 'Test',
|
|
179
|
+
testsPath: '/cache/tests-WordPress',
|
|
180
|
+
url: 'https://github.com/WordPress/WordPress.git',
|
|
181
|
+
type: 'git',
|
|
182
|
+
},
|
|
183
|
+
phpVersion: '2.0',
|
|
184
|
+
afterSetup: 'test',
|
|
185
|
+
env: {
|
|
186
|
+
development: {
|
|
187
|
+
...DEFAULT_CONFIG.env.development,
|
|
188
|
+
port: 1234,
|
|
189
|
+
},
|
|
190
|
+
tests: {
|
|
191
|
+
...DEFAULT_CONFIG.env.tests,
|
|
192
|
+
port: 1011,
|
|
193
|
+
},
|
|
194
|
+
},
|
|
195
|
+
};
|
|
196
|
+
expect( parsed ).toEqual( expected );
|
|
197
|
+
} );
|
|
198
|
+
|
|
199
|
+
it( 'should parse core, plugin, theme, and mapping sources', async () => {
|
|
200
|
+
readRawConfigFile.mockImplementation( async ( configFile ) => {
|
|
201
|
+
if ( configFile === path.resolve( '.', './.wp-env.json' ) ) {
|
|
202
|
+
return {
|
|
203
|
+
core: 'WordPress/WordPress#Test',
|
|
204
|
+
plugins: [ 'WordPress/TestPlugin#Test' ],
|
|
205
|
+
themes: [ 'WordPress/TestTheme#Test' ],
|
|
206
|
+
mappings: {
|
|
207
|
+
'/var/www/html/wp-content/plugins/test-mapping':
|
|
208
|
+
'WordPress/TestMapping#Test',
|
|
209
|
+
},
|
|
210
|
+
};
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
if (
|
|
214
|
+
configFile === path.resolve( '.', './.wp-env.override.json' )
|
|
215
|
+
) {
|
|
216
|
+
return {};
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
throw new Error( 'Invalid File: ' + configFile );
|
|
220
|
+
} );
|
|
221
|
+
|
|
222
|
+
const parsed = await parseConfig( './', '/cache' );
|
|
223
|
+
|
|
224
|
+
expect( parsed ).toEqual( {
|
|
225
|
+
...DEFAULT_CONFIG,
|
|
226
|
+
coreSource: {
|
|
227
|
+
basename: 'WordPress',
|
|
228
|
+
path: '/cache/WordPress',
|
|
229
|
+
clonePath: '/cache/WordPress',
|
|
230
|
+
ref: 'Test',
|
|
231
|
+
testsPath: '/cache/tests-WordPress',
|
|
232
|
+
url: 'https://github.com/WordPress/WordPress.git',
|
|
233
|
+
type: 'git',
|
|
234
|
+
},
|
|
235
|
+
pluginSources: [
|
|
236
|
+
{
|
|
237
|
+
basename: 'TestPlugin',
|
|
238
|
+
path: '/cache/TestPlugin',
|
|
239
|
+
clonePath: '/cache/TestPlugin',
|
|
240
|
+
ref: 'Test',
|
|
241
|
+
url: 'https://github.com/WordPress/TestPlugin.git',
|
|
242
|
+
type: 'git',
|
|
243
|
+
},
|
|
244
|
+
],
|
|
245
|
+
themeSources: [
|
|
246
|
+
{
|
|
247
|
+
basename: 'TestTheme',
|
|
248
|
+
path: '/cache/TestTheme',
|
|
249
|
+
clonePath: '/cache/TestTheme',
|
|
250
|
+
ref: 'Test',
|
|
251
|
+
url: 'https://github.com/WordPress/TestTheme.git',
|
|
252
|
+
type: 'git',
|
|
253
|
+
},
|
|
254
|
+
],
|
|
255
|
+
mappings: {
|
|
256
|
+
'/var/www/html/wp-content/plugins/test-mapping': {
|
|
257
|
+
basename: 'TestMapping',
|
|
258
|
+
path: '/cache/TestMapping',
|
|
259
|
+
clonePath: '/cache/TestMapping',
|
|
260
|
+
ref: 'Test',
|
|
261
|
+
url: 'https://github.com/WordPress/TestMapping.git',
|
|
262
|
+
type: 'git',
|
|
263
|
+
},
|
|
264
|
+
},
|
|
265
|
+
} );
|
|
266
|
+
} );
|
|
267
|
+
|
|
268
|
+
it( 'should override with environment variables', async () => {
|
|
269
|
+
process.env.WP_ENV_PORT = 123;
|
|
270
|
+
process.env.WP_ENV_TESTS_PORT = 456;
|
|
271
|
+
process.env.WP_ENV_CORE = 'WordPress/WordPress#test';
|
|
272
|
+
process.env.WP_ENV_PHP_VERSION = '3.0';
|
|
273
|
+
process.env.WP_ENV_AFTER_SETUP = 'test after';
|
|
274
|
+
|
|
275
|
+
const parsed = await parseConfig( './', '/cache' );
|
|
276
|
+
|
|
277
|
+
expect( parsed ).toEqual( {
|
|
278
|
+
...DEFAULT_CONFIG,
|
|
279
|
+
port: 123,
|
|
280
|
+
testsPort: 456,
|
|
281
|
+
coreSource: {
|
|
282
|
+
basename: 'WordPress',
|
|
283
|
+
path: '/cache/WordPress',
|
|
284
|
+
clonePath: '/cache/WordPress',
|
|
285
|
+
ref: 'test',
|
|
286
|
+
testsPath: '/cache/tests-WordPress',
|
|
287
|
+
url: 'https://github.com/WordPress/WordPress.git',
|
|
288
|
+
type: 'git',
|
|
289
|
+
},
|
|
290
|
+
phpVersion: '3.0',
|
|
291
|
+
afterSetup: 'test after',
|
|
292
|
+
env: {
|
|
293
|
+
development: {
|
|
294
|
+
port: 123,
|
|
295
|
+
phpVersion: '3.0',
|
|
296
|
+
coreSource: {
|
|
297
|
+
basename: 'WordPress',
|
|
298
|
+
path: '/cache/WordPress',
|
|
299
|
+
clonePath: '/cache/WordPress',
|
|
300
|
+
ref: 'test',
|
|
301
|
+
testsPath: '/cache/tests-WordPress',
|
|
302
|
+
url: 'https://github.com/WordPress/WordPress.git',
|
|
303
|
+
type: 'git',
|
|
304
|
+
},
|
|
305
|
+
},
|
|
306
|
+
tests: {
|
|
307
|
+
port: 456,
|
|
308
|
+
phpVersion: '3.0',
|
|
309
|
+
coreSource: {
|
|
310
|
+
basename: 'WordPress',
|
|
311
|
+
path: '/cache/WordPress',
|
|
312
|
+
clonePath: '/cache/WordPress',
|
|
313
|
+
ref: 'test',
|
|
314
|
+
testsPath: '/cache/tests-WordPress',
|
|
315
|
+
url: 'https://github.com/WordPress/WordPress.git',
|
|
316
|
+
type: 'git',
|
|
317
|
+
},
|
|
318
|
+
config: {
|
|
319
|
+
WP_DEBUG: false,
|
|
320
|
+
SCRIPT_DEBUG: false,
|
|
321
|
+
},
|
|
322
|
+
},
|
|
323
|
+
},
|
|
324
|
+
} );
|
|
325
|
+
} );
|
|
326
|
+
|
|
327
|
+
it( 'throws when latest WordPress version needed but not found', async () => {
|
|
328
|
+
getLatestWordPressVersion.mockResolvedValue( null );
|
|
329
|
+
|
|
330
|
+
expect.assertions( 1 );
|
|
331
|
+
try {
|
|
332
|
+
await parseConfig( './', '/cache' );
|
|
333
|
+
} catch ( error ) {
|
|
334
|
+
expect( error ).toEqual(
|
|
335
|
+
new ValidationError(
|
|
336
|
+
'Could not find the latest WordPress version. There may be a network issue.'
|
|
337
|
+
)
|
|
338
|
+
);
|
|
339
|
+
}
|
|
340
|
+
} );
|
|
341
|
+
} );
|
|
342
|
+
/* eslint-enable jest/no-conditional-expect */
|