@wordpress/env 6.0.0 → 8.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 +130 -66
- package/lib/build-docker-compose-config.js +67 -96
- package/lib/cache.js +1 -0
- package/lib/cli.js +39 -10
- package/lib/commands/clean.js +13 -1
- package/lib/commands/destroy.js +21 -42
- 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 +45 -21
- package/lib/commands/start.js +29 -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 +106 -0
- package/lib/config/index.js +7 -5
- package/lib/config/load-config.js +92 -0
- package/lib/config/merge-configs.js +105 -0
- package/lib/config/parse-config.js +501 -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 +295 -0
- package/lib/config/test/add-or-replace-port.js +29 -1
- package/lib/config/test/config-integration.js +164 -0
- package/lib/config/test/get-cache-directory.js +57 -0
- package/lib/config/test/merge-configs.js +121 -0
- package/lib/config/test/parse-config.js +393 -0
- package/lib/config/test/parse-source-string.js +154 -0
- package/lib/config/test/post-process-config.js +299 -0
- package/lib/config/test/read-raw-config-file.js +19 -63
- package/lib/config/test/validate-config.js +363 -0
- package/lib/config/validate-config.js +119 -54
- package/lib/env.js +2 -0
- package/lib/execute-lifecycle-script.js +86 -0
- package/lib/get-host-user.js +27 -0
- package/lib/init-config.js +186 -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-lifecycle-script.js +59 -0
- package/lib/test/md5.js +35 -0
- package/lib/test/parse-xdebug-mode.js +41 -0
- package/lib/validate-run-container.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
|
@@ -0,0 +1,295 @@
|
|
|
1
|
+
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
|
+
|
|
3
|
+
exports[`Config Integration should load local and override configuration files 1`] = `
|
|
4
|
+
{
|
|
5
|
+
"configDirectoryPath": "/test/gutenberg",
|
|
6
|
+
"detectedLocalConfig": true,
|
|
7
|
+
"dockerComposeConfigPath": "/cache/5fea4c5689ef6cc4a4e6eaaa39323338/docker-compose.yml",
|
|
8
|
+
"env": {
|
|
9
|
+
"development": {
|
|
10
|
+
"config": {
|
|
11
|
+
"FS_METHOD": "direct",
|
|
12
|
+
"SCRIPT_DEBUG": true,
|
|
13
|
+
"WP_DEBUG": true,
|
|
14
|
+
"WP_ENVIRONMENT_TYPE": "local",
|
|
15
|
+
"WP_HOME": "http://localhost:999",
|
|
16
|
+
"WP_PHP_BINARY": "php",
|
|
17
|
+
"WP_SITEURL": "http://localhost:999",
|
|
18
|
+
"WP_TESTS_DOMAIN": "localhost:999",
|
|
19
|
+
"WP_TESTS_EMAIL": "admin@example.org",
|
|
20
|
+
"WP_TESTS_TITLE": "Test Blog",
|
|
21
|
+
},
|
|
22
|
+
"coreSource": {
|
|
23
|
+
"basename": "WordPress",
|
|
24
|
+
"clonePath": "/cache/5fea4c5689ef6cc4a4e6eaaa39323338/WordPress",
|
|
25
|
+
"path": "/cache/5fea4c5689ef6cc4a4e6eaaa39323338/WordPress",
|
|
26
|
+
"ref": "trunk",
|
|
27
|
+
"testsPath": "/cache/5fea4c5689ef6cc4a4e6eaaa39323338/tests-WordPress",
|
|
28
|
+
"type": "git",
|
|
29
|
+
"url": "https://github.com/WordPress/WordPress.git",
|
|
30
|
+
},
|
|
31
|
+
"mappings": {},
|
|
32
|
+
"phpVersion": null,
|
|
33
|
+
"pluginSources": [],
|
|
34
|
+
"port": 999,
|
|
35
|
+
"themeSources": [],
|
|
36
|
+
},
|
|
37
|
+
"tests": {
|
|
38
|
+
"config": {
|
|
39
|
+
"FS_METHOD": "direct",
|
|
40
|
+
"SCRIPT_DEBUG": false,
|
|
41
|
+
"WP_DEBUG": false,
|
|
42
|
+
"WP_ENVIRONMENT_TYPE": "local",
|
|
43
|
+
"WP_HOME": "http://localhost:456",
|
|
44
|
+
"WP_PHP_BINARY": "php",
|
|
45
|
+
"WP_SITEURL": "http://localhost:456",
|
|
46
|
+
"WP_TESTS_DOMAIN": "localhost:456",
|
|
47
|
+
"WP_TESTS_EMAIL": "admin@example.org",
|
|
48
|
+
"WP_TESTS_TITLE": "Test Blog",
|
|
49
|
+
},
|
|
50
|
+
"coreSource": {
|
|
51
|
+
"basename": "WordPress",
|
|
52
|
+
"clonePath": "/cache/5fea4c5689ef6cc4a4e6eaaa39323338/WordPress",
|
|
53
|
+
"path": "/cache/5fea4c5689ef6cc4a4e6eaaa39323338/WordPress",
|
|
54
|
+
"ref": "trunk",
|
|
55
|
+
"testsPath": "/cache/5fea4c5689ef6cc4a4e6eaaa39323338/tests-WordPress",
|
|
56
|
+
"type": "git",
|
|
57
|
+
"url": "https://github.com/WordPress/WordPress.git",
|
|
58
|
+
},
|
|
59
|
+
"mappings": {},
|
|
60
|
+
"phpVersion": null,
|
|
61
|
+
"pluginSources": [],
|
|
62
|
+
"port": 456,
|
|
63
|
+
"themeSources": [],
|
|
64
|
+
},
|
|
65
|
+
},
|
|
66
|
+
"lifecycleScripts": {
|
|
67
|
+
"afterClean": null,
|
|
68
|
+
"afterDestroy": "test",
|
|
69
|
+
"afterStart": null,
|
|
70
|
+
},
|
|
71
|
+
"name": "gutenberg",
|
|
72
|
+
"workDirectoryPath": "/cache/5fea4c5689ef6cc4a4e6eaaa39323338",
|
|
73
|
+
}
|
|
74
|
+
`;
|
|
75
|
+
|
|
76
|
+
exports[`Config Integration should load local configuration file 1`] = `
|
|
77
|
+
{
|
|
78
|
+
"configDirectoryPath": "/test/gutenberg",
|
|
79
|
+
"detectedLocalConfig": true,
|
|
80
|
+
"dockerComposeConfigPath": "/cache/5fea4c5689ef6cc4a4e6eaaa39323338/docker-compose.yml",
|
|
81
|
+
"env": {
|
|
82
|
+
"development": {
|
|
83
|
+
"config": {
|
|
84
|
+
"FS_METHOD": "direct",
|
|
85
|
+
"SCRIPT_DEBUG": true,
|
|
86
|
+
"WP_DEBUG": true,
|
|
87
|
+
"WP_ENVIRONMENT_TYPE": "local",
|
|
88
|
+
"WP_HOME": "http://localhost:123",
|
|
89
|
+
"WP_PHP_BINARY": "php",
|
|
90
|
+
"WP_SITEURL": "http://localhost:123",
|
|
91
|
+
"WP_TESTS_DOMAIN": "localhost:123",
|
|
92
|
+
"WP_TESTS_EMAIL": "admin@example.org",
|
|
93
|
+
"WP_TESTS_TITLE": "Test Blog",
|
|
94
|
+
},
|
|
95
|
+
"coreSource": {
|
|
96
|
+
"basename": "WordPress",
|
|
97
|
+
"clonePath": "/cache/5fea4c5689ef6cc4a4e6eaaa39323338/WordPress",
|
|
98
|
+
"path": "/cache/5fea4c5689ef6cc4a4e6eaaa39323338/WordPress",
|
|
99
|
+
"ref": "trunk",
|
|
100
|
+
"testsPath": "/cache/5fea4c5689ef6cc4a4e6eaaa39323338/tests-WordPress",
|
|
101
|
+
"type": "git",
|
|
102
|
+
"url": "https://github.com/WordPress/WordPress.git",
|
|
103
|
+
},
|
|
104
|
+
"mappings": {},
|
|
105
|
+
"phpVersion": null,
|
|
106
|
+
"pluginSources": [],
|
|
107
|
+
"port": 123,
|
|
108
|
+
"themeSources": [],
|
|
109
|
+
},
|
|
110
|
+
"tests": {
|
|
111
|
+
"config": {
|
|
112
|
+
"FS_METHOD": "direct",
|
|
113
|
+
"SCRIPT_DEBUG": false,
|
|
114
|
+
"WP_DEBUG": false,
|
|
115
|
+
"WP_ENVIRONMENT_TYPE": "local",
|
|
116
|
+
"WP_HOME": "http://localhost:8889",
|
|
117
|
+
"WP_PHP_BINARY": "php",
|
|
118
|
+
"WP_SITEURL": "http://localhost:8889",
|
|
119
|
+
"WP_TESTS_DOMAIN": "localhost:8889",
|
|
120
|
+
"WP_TESTS_EMAIL": "admin@example.org",
|
|
121
|
+
"WP_TESTS_TITLE": "Test Blog",
|
|
122
|
+
},
|
|
123
|
+
"coreSource": {
|
|
124
|
+
"basename": "WordPress",
|
|
125
|
+
"clonePath": "/cache/5fea4c5689ef6cc4a4e6eaaa39323338/WordPress",
|
|
126
|
+
"path": "/cache/5fea4c5689ef6cc4a4e6eaaa39323338/WordPress",
|
|
127
|
+
"ref": "trunk",
|
|
128
|
+
"testsPath": "/cache/5fea4c5689ef6cc4a4e6eaaa39323338/tests-WordPress",
|
|
129
|
+
"type": "git",
|
|
130
|
+
"url": "https://github.com/WordPress/WordPress.git",
|
|
131
|
+
},
|
|
132
|
+
"mappings": {},
|
|
133
|
+
"phpVersion": null,
|
|
134
|
+
"pluginSources": [],
|
|
135
|
+
"port": 8889,
|
|
136
|
+
"themeSources": [],
|
|
137
|
+
},
|
|
138
|
+
},
|
|
139
|
+
"lifecycleScripts": {
|
|
140
|
+
"afterClean": null,
|
|
141
|
+
"afterDestroy": null,
|
|
142
|
+
"afterStart": "test",
|
|
143
|
+
},
|
|
144
|
+
"name": "gutenberg",
|
|
145
|
+
"workDirectoryPath": "/cache/5fea4c5689ef6cc4a4e6eaaa39323338",
|
|
146
|
+
}
|
|
147
|
+
`;
|
|
148
|
+
|
|
149
|
+
exports[`Config Integration should use default configuration 1`] = `
|
|
150
|
+
{
|
|
151
|
+
"configDirectoryPath": "/test/gutenberg",
|
|
152
|
+
"detectedLocalConfig": true,
|
|
153
|
+
"dockerComposeConfigPath": "/cache/5fea4c5689ef6cc4a4e6eaaa39323338/docker-compose.yml",
|
|
154
|
+
"env": {
|
|
155
|
+
"development": {
|
|
156
|
+
"config": {
|
|
157
|
+
"FS_METHOD": "direct",
|
|
158
|
+
"SCRIPT_DEBUG": true,
|
|
159
|
+
"WP_DEBUG": true,
|
|
160
|
+
"WP_ENVIRONMENT_TYPE": "local",
|
|
161
|
+
"WP_HOME": "http://localhost:8888",
|
|
162
|
+
"WP_PHP_BINARY": "php",
|
|
163
|
+
"WP_SITEURL": "http://localhost:8888",
|
|
164
|
+
"WP_TESTS_DOMAIN": "localhost:8888",
|
|
165
|
+
"WP_TESTS_EMAIL": "admin@example.org",
|
|
166
|
+
"WP_TESTS_TITLE": "Test Blog",
|
|
167
|
+
},
|
|
168
|
+
"coreSource": {
|
|
169
|
+
"basename": "WordPress",
|
|
170
|
+
"clonePath": "/cache/5fea4c5689ef6cc4a4e6eaaa39323338/WordPress",
|
|
171
|
+
"path": "/cache/5fea4c5689ef6cc4a4e6eaaa39323338/WordPress",
|
|
172
|
+
"ref": "100.0.0",
|
|
173
|
+
"testsPath": "/cache/5fea4c5689ef6cc4a4e6eaaa39323338/tests-WordPress",
|
|
174
|
+
"type": "git",
|
|
175
|
+
"url": "https://github.com/WordPress/WordPress.git",
|
|
176
|
+
},
|
|
177
|
+
"mappings": {},
|
|
178
|
+
"phpVersion": null,
|
|
179
|
+
"pluginSources": [],
|
|
180
|
+
"port": 8888,
|
|
181
|
+
"themeSources": [],
|
|
182
|
+
},
|
|
183
|
+
"tests": {
|
|
184
|
+
"config": {
|
|
185
|
+
"FS_METHOD": "direct",
|
|
186
|
+
"SCRIPT_DEBUG": false,
|
|
187
|
+
"WP_DEBUG": false,
|
|
188
|
+
"WP_ENVIRONMENT_TYPE": "local",
|
|
189
|
+
"WP_HOME": "http://localhost:8889",
|
|
190
|
+
"WP_PHP_BINARY": "php",
|
|
191
|
+
"WP_SITEURL": "http://localhost:8889",
|
|
192
|
+
"WP_TESTS_DOMAIN": "localhost:8889",
|
|
193
|
+
"WP_TESTS_EMAIL": "admin@example.org",
|
|
194
|
+
"WP_TESTS_TITLE": "Test Blog",
|
|
195
|
+
},
|
|
196
|
+
"coreSource": {
|
|
197
|
+
"basename": "WordPress",
|
|
198
|
+
"clonePath": "/cache/5fea4c5689ef6cc4a4e6eaaa39323338/WordPress",
|
|
199
|
+
"path": "/cache/5fea4c5689ef6cc4a4e6eaaa39323338/WordPress",
|
|
200
|
+
"ref": "100.0.0",
|
|
201
|
+
"testsPath": "/cache/5fea4c5689ef6cc4a4e6eaaa39323338/tests-WordPress",
|
|
202
|
+
"type": "git",
|
|
203
|
+
"url": "https://github.com/WordPress/WordPress.git",
|
|
204
|
+
},
|
|
205
|
+
"mappings": {},
|
|
206
|
+
"phpVersion": null,
|
|
207
|
+
"pluginSources": [],
|
|
208
|
+
"port": 8889,
|
|
209
|
+
"themeSources": [],
|
|
210
|
+
},
|
|
211
|
+
},
|
|
212
|
+
"lifecycleScripts": {
|
|
213
|
+
"afterClean": null,
|
|
214
|
+
"afterDestroy": null,
|
|
215
|
+
"afterStart": null,
|
|
216
|
+
},
|
|
217
|
+
"name": "gutenberg",
|
|
218
|
+
"workDirectoryPath": "/cache/5fea4c5689ef6cc4a4e6eaaa39323338",
|
|
219
|
+
}
|
|
220
|
+
`;
|
|
221
|
+
|
|
222
|
+
exports[`Config Integration should use environment variables over local and override configuration files 1`] = `
|
|
223
|
+
{
|
|
224
|
+
"configDirectoryPath": "/test/gutenberg",
|
|
225
|
+
"detectedLocalConfig": true,
|
|
226
|
+
"dockerComposeConfigPath": "/cache/5fea4c5689ef6cc4a4e6eaaa39323338/docker-compose.yml",
|
|
227
|
+
"env": {
|
|
228
|
+
"development": {
|
|
229
|
+
"config": {
|
|
230
|
+
"FS_METHOD": "direct",
|
|
231
|
+
"SCRIPT_DEBUG": true,
|
|
232
|
+
"WP_DEBUG": true,
|
|
233
|
+
"WP_ENVIRONMENT_TYPE": "local",
|
|
234
|
+
"WP_HOME": "http://localhost:12345",
|
|
235
|
+
"WP_PHP_BINARY": "php",
|
|
236
|
+
"WP_SITEURL": "http://localhost:12345",
|
|
237
|
+
"WP_TESTS_DOMAIN": "localhost:12345",
|
|
238
|
+
"WP_TESTS_EMAIL": "admin@example.org",
|
|
239
|
+
"WP_TESTS_TITLE": "Test Blog",
|
|
240
|
+
},
|
|
241
|
+
"coreSource": {
|
|
242
|
+
"basename": "WordPress",
|
|
243
|
+
"clonePath": "/cache/5fea4c5689ef6cc4a4e6eaaa39323338/WordPress",
|
|
244
|
+
"path": "/cache/5fea4c5689ef6cc4a4e6eaaa39323338/WordPress",
|
|
245
|
+
"ref": "trunk",
|
|
246
|
+
"testsPath": "/cache/5fea4c5689ef6cc4a4e6eaaa39323338/tests-WordPress",
|
|
247
|
+
"type": "git",
|
|
248
|
+
"url": "https://github.com/WordPress/WordPress.git",
|
|
249
|
+
},
|
|
250
|
+
"mappings": {},
|
|
251
|
+
"phpVersion": null,
|
|
252
|
+
"pluginSources": [],
|
|
253
|
+
"port": 12345,
|
|
254
|
+
"testsPort": 61234,
|
|
255
|
+
"themeSources": [],
|
|
256
|
+
},
|
|
257
|
+
"tests": {
|
|
258
|
+
"config": {
|
|
259
|
+
"FS_METHOD": "direct",
|
|
260
|
+
"SCRIPT_DEBUG": false,
|
|
261
|
+
"WP_DEBUG": false,
|
|
262
|
+
"WP_ENVIRONMENT_TYPE": "local",
|
|
263
|
+
"WP_HOME": "http://localhost:61234",
|
|
264
|
+
"WP_PHP_BINARY": "php",
|
|
265
|
+
"WP_SITEURL": "http://localhost:61234",
|
|
266
|
+
"WP_TESTS_DOMAIN": "localhost:61234",
|
|
267
|
+
"WP_TESTS_EMAIL": "admin@example.org",
|
|
268
|
+
"WP_TESTS_TITLE": "Test Blog",
|
|
269
|
+
},
|
|
270
|
+
"coreSource": {
|
|
271
|
+
"basename": "WordPress",
|
|
272
|
+
"clonePath": "/cache/5fea4c5689ef6cc4a4e6eaaa39323338/WordPress",
|
|
273
|
+
"path": "/cache/5fea4c5689ef6cc4a4e6eaaa39323338/WordPress",
|
|
274
|
+
"ref": "trunk",
|
|
275
|
+
"testsPath": "/cache/5fea4c5689ef6cc4a4e6eaaa39323338/tests-WordPress",
|
|
276
|
+
"type": "git",
|
|
277
|
+
"url": "https://github.com/WordPress/WordPress.git",
|
|
278
|
+
},
|
|
279
|
+
"mappings": {},
|
|
280
|
+
"phpVersion": null,
|
|
281
|
+
"pluginSources": [],
|
|
282
|
+
"port": 61234,
|
|
283
|
+
"testsPort": 61234,
|
|
284
|
+
"themeSources": [],
|
|
285
|
+
},
|
|
286
|
+
},
|
|
287
|
+
"lifecycleScripts": {
|
|
288
|
+
"afterClean": null,
|
|
289
|
+
"afterDestroy": null,
|
|
290
|
+
"afterStart": "test",
|
|
291
|
+
},
|
|
292
|
+
"name": "gutenberg",
|
|
293
|
+
"workDirectoryPath": "/cache/5fea4c5689ef6cc4a4e6eaaa39323338",
|
|
294
|
+
}
|
|
295
|
+
`;
|
|
@@ -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,164 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
/* eslint-disable jest/no-conditional-expect */
|
|
3
|
+
/**
|
|
4
|
+
* External dependencies
|
|
5
|
+
*/
|
|
6
|
+
const { readFile } = require( 'fs' ).promises;
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Internal dependencies
|
|
10
|
+
*/
|
|
11
|
+
const loadConfig = require( '../load-config' );
|
|
12
|
+
const detectDirectoryType = require( '../detect-directory-type' );
|
|
13
|
+
|
|
14
|
+
jest.mock( 'fs', () => ( {
|
|
15
|
+
promises: {
|
|
16
|
+
readFile: jest.fn(),
|
|
17
|
+
stat: jest.fn().mockResolvedValue( true ),
|
|
18
|
+
},
|
|
19
|
+
} ) );
|
|
20
|
+
|
|
21
|
+
// This mocks a small response with a format matching the stable-check API.
|
|
22
|
+
// It makes getLatestWordPressVersion resolve to "100.0.0".
|
|
23
|
+
jest.mock( 'got', () =>
|
|
24
|
+
jest.fn( ( url ) => ( {
|
|
25
|
+
json: () => {
|
|
26
|
+
if ( url === 'https://api.wordpress.org/core/stable-check/1.0/' ) {
|
|
27
|
+
return Promise.resolve( {
|
|
28
|
+
'1.0': 'insecure',
|
|
29
|
+
'99.1.1': 'outdated',
|
|
30
|
+
'100.0.0': 'latest',
|
|
31
|
+
'100.0.1': 'fancy',
|
|
32
|
+
} );
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
} ) )
|
|
36
|
+
);
|
|
37
|
+
|
|
38
|
+
jest.mock( '../detect-directory-type', () => jest.fn() );
|
|
39
|
+
|
|
40
|
+
describe( 'Config Integration', () => {
|
|
41
|
+
beforeEach( () => {
|
|
42
|
+
process.env.WP_ENV_HOME = '/cache';
|
|
43
|
+
detectDirectoryType.mockResolvedValue( null );
|
|
44
|
+
} );
|
|
45
|
+
|
|
46
|
+
afterEach( () => {
|
|
47
|
+
delete process.env.WP_ENV_HOME;
|
|
48
|
+
delete process.env.WP_ENV_PORT;
|
|
49
|
+
delete process.env.WP_ENV_TESTS_PORT;
|
|
50
|
+
delete process.env.WP_ENV_LIFECYCLE_SCRIPT_AFTER_START;
|
|
51
|
+
} );
|
|
52
|
+
|
|
53
|
+
it( 'should use default configuration', async () => {
|
|
54
|
+
readFile.mockImplementation( async () => {
|
|
55
|
+
throw { code: 'ENOENT' };
|
|
56
|
+
} );
|
|
57
|
+
|
|
58
|
+
const config = await loadConfig( '/test/gutenberg' );
|
|
59
|
+
|
|
60
|
+
expect( config.env.development.port ).toEqual( 8888 );
|
|
61
|
+
expect( config.env.tests.port ).toEqual( 8889 );
|
|
62
|
+
expect( config ).toMatchSnapshot();
|
|
63
|
+
} );
|
|
64
|
+
|
|
65
|
+
it( 'should load local configuration file', async () => {
|
|
66
|
+
readFile.mockImplementation( async ( fileName ) => {
|
|
67
|
+
if ( fileName === '/test/gutenberg/.wp-env.json' ) {
|
|
68
|
+
return JSON.stringify( {
|
|
69
|
+
core: 'WordPress/WordPress#trunk',
|
|
70
|
+
port: 123,
|
|
71
|
+
lifecycleScripts: {
|
|
72
|
+
afterStart: 'test',
|
|
73
|
+
afterClean: null,
|
|
74
|
+
afterDestroy: null,
|
|
75
|
+
},
|
|
76
|
+
} );
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
throw { code: 'ENOENT' };
|
|
80
|
+
} );
|
|
81
|
+
|
|
82
|
+
const config = await loadConfig( '/test/gutenberg' );
|
|
83
|
+
|
|
84
|
+
expect( config.env.development.port ).toEqual( 123 );
|
|
85
|
+
expect( config.env.tests.port ).toEqual( 8889 );
|
|
86
|
+
expect( config ).toMatchSnapshot();
|
|
87
|
+
} );
|
|
88
|
+
|
|
89
|
+
it( 'should load local and override configuration files', async () => {
|
|
90
|
+
readFile.mockImplementation( async ( fileName ) => {
|
|
91
|
+
if ( fileName === '/test/gutenberg/.wp-env.json' ) {
|
|
92
|
+
return JSON.stringify( {
|
|
93
|
+
core: 'WordPress/WordPress#trunk',
|
|
94
|
+
port: 123,
|
|
95
|
+
testsPort: 456,
|
|
96
|
+
lifecycleScripts: {
|
|
97
|
+
afterStart: 'test',
|
|
98
|
+
afterClean: null,
|
|
99
|
+
afterDestroy: null,
|
|
100
|
+
},
|
|
101
|
+
} );
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
if ( fileName === '/test/gutenberg/.wp-env.override.json' ) {
|
|
105
|
+
return JSON.stringify( {
|
|
106
|
+
port: 999,
|
|
107
|
+
lifecycleScripts: {
|
|
108
|
+
afterStart: null,
|
|
109
|
+
afterClean: null,
|
|
110
|
+
afterDestroy: 'test',
|
|
111
|
+
},
|
|
112
|
+
} );
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
throw { code: 'ENOENT' };
|
|
116
|
+
} );
|
|
117
|
+
|
|
118
|
+
const config = await loadConfig( '/test/gutenberg' );
|
|
119
|
+
|
|
120
|
+
expect( config.env.development.port ).toEqual( 999 );
|
|
121
|
+
expect( config.env.tests.port ).toEqual( 456 );
|
|
122
|
+
expect( config ).toMatchSnapshot();
|
|
123
|
+
} );
|
|
124
|
+
|
|
125
|
+
it( 'should use environment variables over local and override configuration files', async () => {
|
|
126
|
+
process.env.WP_ENV_PORT = 12345;
|
|
127
|
+
process.env.WP_ENV_TESTS_PORT = 61234;
|
|
128
|
+
process.env.WP_ENV_LIFECYCLE_SCRIPT_AFTER_START = 'test';
|
|
129
|
+
|
|
130
|
+
readFile.mockImplementation( async ( fileName ) => {
|
|
131
|
+
if ( fileName === '/test/gutenberg/.wp-env.json' ) {
|
|
132
|
+
return JSON.stringify( {
|
|
133
|
+
core: 'WordPress/WordPress#trunk',
|
|
134
|
+
port: 123,
|
|
135
|
+
testsPort: 456,
|
|
136
|
+
lifecycleScripts: {
|
|
137
|
+
afterStart: 'local',
|
|
138
|
+
afterClean: null,
|
|
139
|
+
afterDestroy: null,
|
|
140
|
+
},
|
|
141
|
+
} );
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
if ( fileName === '/test/gutenberg/.wp-env.override.json' ) {
|
|
145
|
+
return JSON.stringify( {
|
|
146
|
+
port: 999,
|
|
147
|
+
} );
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
throw { code: 'ENOENT' };
|
|
151
|
+
} );
|
|
152
|
+
|
|
153
|
+
const config = await loadConfig( '/test/gutenberg' );
|
|
154
|
+
|
|
155
|
+
expect( config.env.development.port ).toEqual( 12345 );
|
|
156
|
+
expect( config.env.tests.port ).toEqual( 61234 );
|
|
157
|
+
expect( config.lifecycleScripts ).toHaveProperty(
|
|
158
|
+
'afterStart',
|
|
159
|
+
'test'
|
|
160
|
+
);
|
|
161
|
+
expect( config ).toMatchSnapshot();
|
|
162
|
+
} );
|
|
163
|
+
} );
|
|
164
|
+
/* 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,121 @@
|
|
|
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
|
+
lifecycleScripts: {
|
|
20
|
+
afterStart: 'test',
|
|
21
|
+
},
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
port: 8889,
|
|
25
|
+
config: {
|
|
26
|
+
WP_TEST_2: 'test-2',
|
|
27
|
+
},
|
|
28
|
+
lifecycleScripts: {
|
|
29
|
+
afterDestroy: 'test-2',
|
|
30
|
+
},
|
|
31
|
+
}
|
|
32
|
+
);
|
|
33
|
+
|
|
34
|
+
expect( merged ).toEqual( {
|
|
35
|
+
port: 8889,
|
|
36
|
+
coreSource: {
|
|
37
|
+
type: 'local',
|
|
38
|
+
path: '/home/test',
|
|
39
|
+
},
|
|
40
|
+
config: {
|
|
41
|
+
WP_TEST: 'test',
|
|
42
|
+
WP_TEST_2: 'test-2',
|
|
43
|
+
},
|
|
44
|
+
lifecycleScripts: {
|
|
45
|
+
afterStart: 'test',
|
|
46
|
+
afterDestroy: 'test-2',
|
|
47
|
+
},
|
|
48
|
+
} );
|
|
49
|
+
} );
|
|
50
|
+
|
|
51
|
+
it( 'should merge configs with environments', () => {
|
|
52
|
+
const merged = mergeConfigs(
|
|
53
|
+
{
|
|
54
|
+
port: 8888,
|
|
55
|
+
coreSource: {
|
|
56
|
+
type: 'local',
|
|
57
|
+
path: '/home/test',
|
|
58
|
+
},
|
|
59
|
+
config: {
|
|
60
|
+
WP_TEST: 'test',
|
|
61
|
+
},
|
|
62
|
+
env: {
|
|
63
|
+
development: {
|
|
64
|
+
config: {
|
|
65
|
+
WP_TEST_3: 'test-3',
|
|
66
|
+
},
|
|
67
|
+
},
|
|
68
|
+
tests: {
|
|
69
|
+
config: {
|
|
70
|
+
WP_TEST_4: 'test-4',
|
|
71
|
+
},
|
|
72
|
+
},
|
|
73
|
+
},
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
port: 8889,
|
|
77
|
+
config: {
|
|
78
|
+
WP_TEST_2: 'test-2',
|
|
79
|
+
},
|
|
80
|
+
env: {
|
|
81
|
+
development: {
|
|
82
|
+
config: {
|
|
83
|
+
WP_TEST_5: 'test-5',
|
|
84
|
+
},
|
|
85
|
+
},
|
|
86
|
+
tests: {
|
|
87
|
+
config: {
|
|
88
|
+
WP_TEST_6: 'test-6',
|
|
89
|
+
},
|
|
90
|
+
},
|
|
91
|
+
},
|
|
92
|
+
}
|
|
93
|
+
);
|
|
94
|
+
|
|
95
|
+
expect( merged ).toEqual( {
|
|
96
|
+
port: 8889,
|
|
97
|
+
coreSource: {
|
|
98
|
+
type: 'local',
|
|
99
|
+
path: '/home/test',
|
|
100
|
+
},
|
|
101
|
+
config: {
|
|
102
|
+
WP_TEST: 'test',
|
|
103
|
+
WP_TEST_2: 'test-2',
|
|
104
|
+
},
|
|
105
|
+
env: {
|
|
106
|
+
development: {
|
|
107
|
+
config: {
|
|
108
|
+
WP_TEST_3: 'test-3',
|
|
109
|
+
WP_TEST_5: 'test-5',
|
|
110
|
+
},
|
|
111
|
+
},
|
|
112
|
+
tests: {
|
|
113
|
+
config: {
|
|
114
|
+
WP_TEST_4: 'test-4',
|
|
115
|
+
WP_TEST_6: 'test-6',
|
|
116
|
+
},
|
|
117
|
+
},
|
|
118
|
+
},
|
|
119
|
+
} );
|
|
120
|
+
} );
|
|
121
|
+
} );
|