@wordpress/env 10.39.0 → 11.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 +127 -76
- package/lib/cli.js +67 -10
- package/lib/commands/clean.js +13 -4
- package/lib/commands/cleanup.js +79 -0
- package/lib/commands/destroy.js +30 -18
- package/lib/commands/index.js +6 -2
- package/lib/commands/logs.js +17 -8
- package/lib/commands/reset.js +46 -0
- package/lib/commands/run.js +13 -9
- package/lib/commands/start.js +54 -14
- package/lib/commands/status.js +160 -0
- package/lib/commands/stop.js +13 -6
- package/lib/config/get-config-from-environment-vars.js +2 -5
- package/lib/config/load-config.js +35 -5
- package/lib/config/parse-config.js +53 -21
- package/lib/config/post-process-config.js +38 -16
- package/lib/config/test/__snapshots__/config-integration.js.snap +16 -0
- package/lib/config/test/parse-config.js +33 -0
- package/lib/config/test/post-process-config.js +52 -0
- package/lib/runtime/docker/build-docker-compose-config.js +164 -125
- package/lib/runtime/docker/download-sources.js +5 -1
- package/lib/runtime/docker/download-wp-phpunit.js +3 -0
- package/lib/runtime/docker/index.js +281 -91
- package/lib/runtime/docker/init-config.js +20 -12
- package/lib/runtime/docker/wordpress.js +0 -15
- package/lib/runtime/errors.js +11 -0
- package/lib/runtime/index.js +40 -18
- package/lib/runtime/playground/blueprint-builder.js +25 -33
- package/lib/runtime/playground/index.js +82 -4
- package/lib/test/build-docker-compose-config.js +147 -0
- package/lib/test/cli.js +49 -13
- package/package.json +2 -2
- package/lib/commands/install-path.js +0 -33
package/lib/runtime/index.js
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
/**
|
|
4
|
-
* External dependencies
|
|
5
|
-
*/
|
|
6
|
-
const { existsSync } = require( 'fs' );
|
|
7
|
-
const path = require( 'path' );
|
|
8
|
-
|
|
9
3
|
/**
|
|
10
4
|
* Internal dependencies
|
|
11
5
|
*/
|
|
12
6
|
const DockerRuntime = require( './docker' );
|
|
13
7
|
const PlaygroundRuntime = require( './playground' );
|
|
14
|
-
const {
|
|
8
|
+
const {
|
|
9
|
+
UnsupportedCommandError,
|
|
10
|
+
EnvironmentNotInitializedError,
|
|
11
|
+
} = require( './errors' );
|
|
12
|
+
const { setCache, getCache } = require( '../cache' );
|
|
13
|
+
|
|
14
|
+
const RUNTIME_CACHE_KEY = 'runtime';
|
|
15
15
|
|
|
16
16
|
const runtimes = {
|
|
17
17
|
docker: DockerRuntime,
|
|
@@ -42,28 +42,50 @@ function getAvailableRuntimes() {
|
|
|
42
42
|
}
|
|
43
43
|
|
|
44
44
|
/**
|
|
45
|
-
*
|
|
46
|
-
*
|
|
45
|
+
* Save the runtime type to the cache file.
|
|
46
|
+
* Called when start command initializes the environment.
|
|
47
|
+
*
|
|
48
|
+
* @param {string} runtimeName The runtime name ('docker' or 'playground').
|
|
49
|
+
* @param {string} workDirectoryPath Path to the wp-env work directory.
|
|
50
|
+
*/
|
|
51
|
+
async function saveRuntime( runtimeName, workDirectoryPath ) {
|
|
52
|
+
await setCache( RUNTIME_CACHE_KEY, runtimeName, { workDirectoryPath } );
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Get the saved runtime type from cache.
|
|
57
|
+
*
|
|
58
|
+
* @param {string} workDirectoryPath Path to the wp-env work directory.
|
|
59
|
+
* @return {Promise<string|undefined>} The saved runtime name, or undefined if not set.
|
|
60
|
+
*/
|
|
61
|
+
async function getSavedRuntime( workDirectoryPath ) {
|
|
62
|
+
return await getCache( RUNTIME_CACHE_KEY, { workDirectoryPath } );
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Detect which runtime was used by reading from the cache.
|
|
67
|
+
* Throws EnvironmentNotInitializedError if no runtime has been saved.
|
|
47
68
|
*
|
|
48
69
|
* @param {string} workDirectoryPath Path to the wp-env work directory.
|
|
49
|
-
* @return {string} Runtime name ('docker' or 'playground').
|
|
70
|
+
* @return {Promise<string>} Runtime name ('docker' or 'playground').
|
|
71
|
+
* @throws {EnvironmentNotInitializedError} If environment not initialized.
|
|
50
72
|
*/
|
|
51
|
-
function detectRuntime( workDirectoryPath ) {
|
|
52
|
-
const
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
);
|
|
56
|
-
if ( existsSync( playgroundBlueprintFile ) ) {
|
|
57
|
-
return 'playground';
|
|
73
|
+
async function detectRuntime( workDirectoryPath ) {
|
|
74
|
+
const savedRuntime = await getSavedRuntime( workDirectoryPath );
|
|
75
|
+
if ( ! savedRuntime ) {
|
|
76
|
+
throw new EnvironmentNotInitializedError();
|
|
58
77
|
}
|
|
59
|
-
return
|
|
78
|
+
return savedRuntime;
|
|
60
79
|
}
|
|
61
80
|
|
|
62
81
|
module.exports = {
|
|
63
82
|
getRuntime,
|
|
64
83
|
getAvailableRuntimes,
|
|
65
84
|
detectRuntime,
|
|
85
|
+
saveRuntime,
|
|
86
|
+
getSavedRuntime,
|
|
66
87
|
DockerRuntime,
|
|
67
88
|
PlaygroundRuntime,
|
|
68
89
|
UnsupportedCommandError,
|
|
90
|
+
EnvironmentNotInitializedError,
|
|
69
91
|
};
|
|
@@ -107,52 +107,44 @@ function getMountArgs( config ) {
|
|
|
107
107
|
}
|
|
108
108
|
|
|
109
109
|
// Mount themes
|
|
110
|
+
// All theme types (local, git, zip) can be mounted after downloading/extraction
|
|
110
111
|
for ( const theme of envConfig.themeSources || [] ) {
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
);
|
|
117
|
-
} else {
|
|
118
|
-
throw new Error(
|
|
119
|
-
`Theme source "${ theme.basename || theme.path }" of type "${
|
|
120
|
-
theme.type
|
|
121
|
-
}" ` +
|
|
122
|
-
`is not supported with Playground runtime. Only local and git themes are supported.`
|
|
123
|
-
);
|
|
124
|
-
}
|
|
112
|
+
args.push(
|
|
113
|
+
'--mount-dir',
|
|
114
|
+
theme.path,
|
|
115
|
+
`/wordpress/wp-content/themes/${ theme.basename }`
|
|
116
|
+
);
|
|
125
117
|
}
|
|
126
118
|
|
|
127
119
|
// Mount custom mappings
|
|
120
|
+
// All source types (local, git, zip) can be mounted after downloading/extraction
|
|
128
121
|
for ( const [ wpDir, source ] of Object.entries(
|
|
129
122
|
envConfig.mappings || {}
|
|
130
123
|
) ) {
|
|
131
|
-
|
|
132
|
-
args.push( '--mount-dir', source.path, `/wordpress/${ wpDir }` );
|
|
133
|
-
} else {
|
|
134
|
-
throw new Error(
|
|
135
|
-
`Mapping source "${ source.path }" for "${ wpDir }" of type "${ source.type }" ` +
|
|
136
|
-
`is not supported with Playground runtime. Only local and git mappings are supported.`
|
|
137
|
-
);
|
|
138
|
-
}
|
|
124
|
+
args.push( '--mount-dir', source.path, `/wordpress/${ wpDir }` );
|
|
139
125
|
}
|
|
140
126
|
|
|
141
|
-
//
|
|
127
|
+
// Translate core source to Playground's --wp flag or mount it.
|
|
142
128
|
if ( envConfig.coreSource ) {
|
|
143
|
-
if (
|
|
144
|
-
|
|
145
|
-
envConfig.coreSource.
|
|
146
|
-
) {
|
|
129
|
+
if ( envConfig.coreSource.type === 'zip' && envConfig.coreSource.url ) {
|
|
130
|
+
// For zip URLs, let Playground download WordPress natively.
|
|
131
|
+
args.push( '--wp', envConfig.coreSource.url );
|
|
132
|
+
} else if ( envConfig.coreSource.type === 'git' ) {
|
|
133
|
+
// For git sources, pass the version ref to Playground's --wp flag.
|
|
134
|
+
// e.g., WordPress/WordPress#6.5 → --wp 6.5
|
|
135
|
+
// WordPress/WordPress (no ref) → default "latest", no flag needed.
|
|
136
|
+
if ( envConfig.coreSource.ref ) {
|
|
137
|
+
args.push( '--wp', envConfig.coreSource.ref );
|
|
138
|
+
}
|
|
139
|
+
} else {
|
|
140
|
+
// For local sources, mount the directory and tell Playground to
|
|
141
|
+
// use the existing files instead of downloading its own copy.
|
|
147
142
|
args.push(
|
|
148
143
|
'--mount-dir-before-install',
|
|
149
144
|
envConfig.coreSource.path,
|
|
150
|
-
'/wordpress'
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
throw new Error(
|
|
154
|
-
`Core source of type "${ envConfig.coreSource.type }" is not supported ` +
|
|
155
|
-
`with Playground runtime. Only local and git core sources are supported.`
|
|
145
|
+
'/wordpress',
|
|
146
|
+
'--wordpress-install-mode',
|
|
147
|
+
'install-from-existing-files-if-needed'
|
|
156
148
|
);
|
|
157
149
|
}
|
|
158
150
|
}
|
|
@@ -75,6 +75,15 @@ class PlaygroundRuntime {
|
|
|
75
75
|
return 'WARNING! This will remove the WordPress Playground environment and all local files.';
|
|
76
76
|
}
|
|
77
77
|
|
|
78
|
+
/**
|
|
79
|
+
* Get the warning message for cleanup confirmation.
|
|
80
|
+
*
|
|
81
|
+
* @return {string} Warning message.
|
|
82
|
+
*/
|
|
83
|
+
getCleanupWarningMessage() {
|
|
84
|
+
return 'WARNING! This will remove the WordPress Playground environment and all local files.';
|
|
85
|
+
}
|
|
86
|
+
|
|
78
87
|
/**
|
|
79
88
|
* Start the WordPress Playground environment.
|
|
80
89
|
*
|
|
@@ -350,6 +359,25 @@ class PlaygroundRuntime {
|
|
|
350
359
|
spinner.text = 'Removed WordPress Playground environment.';
|
|
351
360
|
}
|
|
352
361
|
|
|
362
|
+
/**
|
|
363
|
+
* Cleanup the WordPress Playground environment.
|
|
364
|
+
*
|
|
365
|
+
* For Playground, cleanup is the same as destroy since there are no
|
|
366
|
+
* shared resources like Docker images to preserve.
|
|
367
|
+
*
|
|
368
|
+
* @param {Object} config The wp-env config object.
|
|
369
|
+
* @param {Object} options Cleanup options.
|
|
370
|
+
* @param {Object} options.spinner A CLI spinner which indicates progress.
|
|
371
|
+
*/
|
|
372
|
+
async cleanup( config, { spinner } ) {
|
|
373
|
+
await this.stop( config, { spinner } );
|
|
374
|
+
|
|
375
|
+
spinner.text = 'Removing local files.';
|
|
376
|
+
await rimraf( config.workDirectoryPath );
|
|
377
|
+
|
|
378
|
+
spinner.text = 'Cleaned up WordPress Playground environment.';
|
|
379
|
+
}
|
|
380
|
+
|
|
353
381
|
/**
|
|
354
382
|
* Run a command in the Playground environment.
|
|
355
383
|
*
|
|
@@ -367,21 +395,71 @@ class PlaygroundRuntime {
|
|
|
367
395
|
}
|
|
368
396
|
|
|
369
397
|
/**
|
|
370
|
-
*
|
|
398
|
+
* Reset the WordPress database.
|
|
371
399
|
*
|
|
372
400
|
* @param {Object} config The wp-env config object.
|
|
373
|
-
* @param {Object} options
|
|
401
|
+
* @param {Object} options Reset options.
|
|
374
402
|
* @param {Object} options.spinner A CLI spinner which indicates progress.
|
|
375
403
|
* @param {boolean} options.debug True if debug mode is enabled.
|
|
376
404
|
*/
|
|
377
405
|
async clean( config, { spinner, debug } ) {
|
|
378
|
-
spinner.text = '
|
|
406
|
+
spinner.text = 'Resetting WordPress Playground environment.';
|
|
379
407
|
|
|
380
408
|
// For Playground, we restart the server to reset the database
|
|
381
409
|
await this.stop( config, { spinner } );
|
|
382
410
|
await this.start( config, { spinner, debug } );
|
|
383
411
|
|
|
384
|
-
spinner.text = '
|
|
412
|
+
spinner.text = 'Reset WordPress Playground environment.';
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
/**
|
|
416
|
+
* Get the status of the Playground environment.
|
|
417
|
+
*
|
|
418
|
+
* @param {Object} config The wp-env config object.
|
|
419
|
+
* @param {Object} options Status options.
|
|
420
|
+
* @param {Object} options.spinner A CLI spinner which indicates progress.
|
|
421
|
+
* @return {Promise<Object>} Status object with environment information.
|
|
422
|
+
*/
|
|
423
|
+
async getStatus( config, { spinner } ) {
|
|
424
|
+
spinner.text = 'Getting environment status.';
|
|
425
|
+
|
|
426
|
+
const envConfig = config.env.development;
|
|
427
|
+
const port = envConfig.port || 8888;
|
|
428
|
+
const pidFile = path.join( config.workDirectoryPath, 'playground.pid' );
|
|
429
|
+
|
|
430
|
+
// Check if server is running.
|
|
431
|
+
let isRunning = false;
|
|
432
|
+
|
|
433
|
+
try {
|
|
434
|
+
const pidContent = await fs.readFile( pidFile, 'utf8' );
|
|
435
|
+
const pid = parseInt( pidContent.trim(), 10 );
|
|
436
|
+
|
|
437
|
+
// Check if process is still alive.
|
|
438
|
+
process.kill( pid, 0 );
|
|
439
|
+
|
|
440
|
+
// Check if server is responding.
|
|
441
|
+
await this._checkServer( port );
|
|
442
|
+
isRunning = true;
|
|
443
|
+
} catch {
|
|
444
|
+
// Process not running or server not responding.
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
return {
|
|
448
|
+
status: isRunning ? 'running' : 'stopped',
|
|
449
|
+
runtime: 'playground',
|
|
450
|
+
urls: {
|
|
451
|
+
development: isRunning ? `http://localhost:${ port }` : null,
|
|
452
|
+
},
|
|
453
|
+
ports: {
|
|
454
|
+
development: port,
|
|
455
|
+
},
|
|
456
|
+
config: {
|
|
457
|
+
multisite: envConfig.multisite,
|
|
458
|
+
xdebug: 'off',
|
|
459
|
+
},
|
|
460
|
+
configPath: config.configDirectoryPath,
|
|
461
|
+
installPath: config.workDirectoryPath,
|
|
462
|
+
};
|
|
385
463
|
}
|
|
386
464
|
|
|
387
465
|
/**
|
|
@@ -131,4 +131,151 @@ describe( 'buildDockerComposeConfig', () => {
|
|
|
131
131
|
expect( dockerConfig.volumes.wordpress ).toBe( undefined );
|
|
132
132
|
expect( dockerConfig.volumes[ 'tests-wordpress' ] ).toBe( undefined );
|
|
133
133
|
} );
|
|
134
|
+
|
|
135
|
+
it( 'should add healthcheck to mysql services', () => {
|
|
136
|
+
const config = buildDockerComposeConfig( {
|
|
137
|
+
workDirectoryPath: '/some/path',
|
|
138
|
+
env: {
|
|
139
|
+
development: {
|
|
140
|
+
port: 8888,
|
|
141
|
+
mysqlPort: 3306,
|
|
142
|
+
coreSource: null,
|
|
143
|
+
pluginSources: [],
|
|
144
|
+
themeSources: [],
|
|
145
|
+
mappings: {},
|
|
146
|
+
},
|
|
147
|
+
tests: {
|
|
148
|
+
port: 8889,
|
|
149
|
+
mysqlPort: 3307,
|
|
150
|
+
coreSource: null,
|
|
151
|
+
pluginSources: [],
|
|
152
|
+
themeSources: [],
|
|
153
|
+
mappings: {},
|
|
154
|
+
},
|
|
155
|
+
},
|
|
156
|
+
} );
|
|
157
|
+
|
|
158
|
+
expect( config.services.mysql.healthcheck ).toBeDefined();
|
|
159
|
+
expect( config.services.mysql.healthcheck.test ).toEqual( [
|
|
160
|
+
'CMD',
|
|
161
|
+
'healthcheck.sh',
|
|
162
|
+
'--connect',
|
|
163
|
+
'--innodb_initialized',
|
|
164
|
+
] );
|
|
165
|
+
expect( config.services.mysql.healthcheck.interval ).toBe( '5s' );
|
|
166
|
+
expect( config.services.mysql.healthcheck.timeout ).toBe( '10s' );
|
|
167
|
+
expect( config.services.mysql.healthcheck.retries ).toBe( 12 );
|
|
168
|
+
expect( config.services.mysql.healthcheck.start_period ).toBe( '60s' );
|
|
169
|
+
|
|
170
|
+
// Verify MARIADB_AUTO_UPGRADE is set for existing installations
|
|
171
|
+
expect( config.services.mysql.environment.MARIADB_AUTO_UPGRADE ).toBe(
|
|
172
|
+
'1'
|
|
173
|
+
);
|
|
174
|
+
|
|
175
|
+
expect( config.services[ 'tests-mysql' ].healthcheck ).toBeDefined();
|
|
176
|
+
expect( config.services[ 'tests-mysql' ].healthcheck.test ).toEqual( [
|
|
177
|
+
'CMD',
|
|
178
|
+
'healthcheck.sh',
|
|
179
|
+
'--connect',
|
|
180
|
+
'--innodb_initialized',
|
|
181
|
+
] );
|
|
182
|
+
expect(
|
|
183
|
+
config.services[ 'tests-mysql' ].environment.MARIADB_AUTO_UPGRADE
|
|
184
|
+
).toBe( '1' );
|
|
185
|
+
} );
|
|
186
|
+
|
|
187
|
+
it( 'should use service_healthy condition for WordPress depends_on', () => {
|
|
188
|
+
const config = buildDockerComposeConfig( {
|
|
189
|
+
workDirectoryPath: '/some/path',
|
|
190
|
+
env: {
|
|
191
|
+
development: {
|
|
192
|
+
port: 8888,
|
|
193
|
+
mysqlPort: 3306,
|
|
194
|
+
coreSource: null,
|
|
195
|
+
pluginSources: [],
|
|
196
|
+
themeSources: [],
|
|
197
|
+
mappings: {},
|
|
198
|
+
},
|
|
199
|
+
tests: {
|
|
200
|
+
port: 8889,
|
|
201
|
+
mysqlPort: 3307,
|
|
202
|
+
coreSource: null,
|
|
203
|
+
pluginSources: [],
|
|
204
|
+
themeSources: [],
|
|
205
|
+
mappings: {},
|
|
206
|
+
},
|
|
207
|
+
},
|
|
208
|
+
} );
|
|
209
|
+
|
|
210
|
+
expect( config.services.wordpress.depends_on ).toEqual( {
|
|
211
|
+
mysql: { condition: 'service_healthy' },
|
|
212
|
+
} );
|
|
213
|
+
expect( config.services[ 'tests-wordpress' ].depends_on ).toEqual( {
|
|
214
|
+
'tests-mysql': { condition: 'service_healthy' },
|
|
215
|
+
} );
|
|
216
|
+
} );
|
|
217
|
+
|
|
218
|
+
describe( 'testsEnvironment', () => {
|
|
219
|
+
it( 'should omit tests services when testsEnvironment is false', () => {
|
|
220
|
+
const dockerConfig = buildDockerComposeConfig( {
|
|
221
|
+
testsEnvironment: false,
|
|
222
|
+
workDirectoryPath: '/path',
|
|
223
|
+
env: {
|
|
224
|
+
development: CONFIG,
|
|
225
|
+
tests: CONFIG,
|
|
226
|
+
},
|
|
227
|
+
} );
|
|
228
|
+
|
|
229
|
+
// Development services should exist.
|
|
230
|
+
expect( dockerConfig.services.mysql ).toBeDefined();
|
|
231
|
+
expect( dockerConfig.services.wordpress ).toBeDefined();
|
|
232
|
+
expect( dockerConfig.services.cli ).toBeDefined();
|
|
233
|
+
expect( dockerConfig.services.phpmyadmin ).toBeDefined();
|
|
234
|
+
|
|
235
|
+
// Tests services should not exist.
|
|
236
|
+
expect( dockerConfig.services[ 'tests-mysql' ] ).toBeUndefined();
|
|
237
|
+
expect(
|
|
238
|
+
dockerConfig.services[ 'tests-wordpress' ]
|
|
239
|
+
).toBeUndefined();
|
|
240
|
+
expect( dockerConfig.services[ 'tests-cli' ] ).toBeUndefined();
|
|
241
|
+
expect(
|
|
242
|
+
dockerConfig.services[ 'tests-phpmyadmin' ]
|
|
243
|
+
).toBeUndefined();
|
|
244
|
+
} );
|
|
245
|
+
|
|
246
|
+
it( 'should omit tests volumes when testsEnvironment is false', () => {
|
|
247
|
+
const dockerConfig = buildDockerComposeConfig( {
|
|
248
|
+
testsEnvironment: false,
|
|
249
|
+
workDirectoryPath: '/path',
|
|
250
|
+
env: {
|
|
251
|
+
development: CONFIG,
|
|
252
|
+
tests: CONFIG,
|
|
253
|
+
},
|
|
254
|
+
} );
|
|
255
|
+
|
|
256
|
+
// Development volumes should exist.
|
|
257
|
+
expect( dockerConfig.volumes.wordpress ).toBeDefined();
|
|
258
|
+
expect( dockerConfig.volumes.mysql ).toBeDefined();
|
|
259
|
+
expect( dockerConfig.volumes[ 'user-home' ] ).toBeDefined();
|
|
260
|
+
|
|
261
|
+
// Tests volumes should not exist.
|
|
262
|
+
expect( dockerConfig.volumes[ 'tests-wordpress' ] ).toBeUndefined();
|
|
263
|
+
expect( dockerConfig.volumes[ 'mysql-test' ] ).toBeUndefined();
|
|
264
|
+
expect( dockerConfig.volumes[ 'tests-user-home' ] ).toBeUndefined();
|
|
265
|
+
} );
|
|
266
|
+
|
|
267
|
+
it( 'should include tests services by default', () => {
|
|
268
|
+
const dockerConfig = buildDockerComposeConfig( {
|
|
269
|
+
workDirectoryPath: '/path',
|
|
270
|
+
env: {
|
|
271
|
+
development: CONFIG,
|
|
272
|
+
tests: CONFIG,
|
|
273
|
+
},
|
|
274
|
+
} );
|
|
275
|
+
|
|
276
|
+
expect( dockerConfig.services[ 'tests-mysql' ] ).toBeDefined();
|
|
277
|
+
expect( dockerConfig.services[ 'tests-wordpress' ] ).toBeDefined();
|
|
278
|
+
expect( dockerConfig.services[ 'tests-cli' ] ).toBeDefined();
|
|
279
|
+
} );
|
|
280
|
+
} );
|
|
134
281
|
} );
|
package/lib/test/cli.js
CHANGED
|
@@ -19,8 +19,11 @@ jest.mock( '../env', () => {
|
|
|
19
19
|
return {
|
|
20
20
|
start: jest.fn( Promise.resolve.bind( Promise ) ),
|
|
21
21
|
stop: jest.fn( Promise.resolve.bind( Promise ) ),
|
|
22
|
+
reset: jest.fn( Promise.resolve.bind( Promise ) ),
|
|
22
23
|
clean: jest.fn( Promise.resolve.bind( Promise ) ),
|
|
23
24
|
run: jest.fn( Promise.resolve.bind( Promise ) ),
|
|
25
|
+
destroy: jest.fn( Promise.resolve.bind( Promise ) ),
|
|
26
|
+
cleanup: jest.fn( Promise.resolve.bind( Promise ) ),
|
|
24
27
|
ValidationError: actual.ValidationError,
|
|
25
28
|
LifecycleScriptError: actual.LifecycleScriptError,
|
|
26
29
|
};
|
|
@@ -41,31 +44,38 @@ describe( 'env cli', () => {
|
|
|
41
44
|
expect( spinner.text ).toBe( '' );
|
|
42
45
|
} );
|
|
43
46
|
|
|
44
|
-
it( 'parses
|
|
45
|
-
cli().parse( [ '
|
|
46
|
-
const { environment, spinner } = env.
|
|
47
|
-
expect( environment ).toBe( '
|
|
47
|
+
it( 'parses reset commands for the default environment.', () => {
|
|
48
|
+
cli().parse( [ 'reset' ] );
|
|
49
|
+
const { environment, spinner } = env.reset.mock.calls[ 0 ][ 0 ];
|
|
50
|
+
expect( environment ).toBe( 'development' );
|
|
48
51
|
expect( spinner.text ).toBe( '' );
|
|
49
52
|
} );
|
|
50
|
-
it( 'parses
|
|
51
|
-
cli().parse( [ '
|
|
52
|
-
const { environment, spinner } = env.
|
|
53
|
+
it( 'parses reset commands for all environments.', () => {
|
|
54
|
+
cli().parse( [ 'reset', 'all' ] );
|
|
55
|
+
const { environment, spinner } = env.reset.mock.calls[ 0 ][ 0 ];
|
|
53
56
|
expect( environment ).toBe( 'all' );
|
|
54
57
|
expect( spinner.text ).toBe( '' );
|
|
55
58
|
} );
|
|
56
|
-
it( 'parses
|
|
57
|
-
cli().parse( [ '
|
|
58
|
-
const { environment, spinner } = env.
|
|
59
|
+
it( 'parses reset commands for the development environment.', () => {
|
|
60
|
+
cli().parse( [ 'reset', 'development' ] );
|
|
61
|
+
const { environment, spinner } = env.reset.mock.calls[ 0 ][ 0 ];
|
|
59
62
|
expect( environment ).toBe( 'development' );
|
|
60
63
|
expect( spinner.text ).toBe( '' );
|
|
61
64
|
} );
|
|
62
|
-
it( 'parses
|
|
63
|
-
cli().parse( [ '
|
|
64
|
-
const { environment, spinner } = env.
|
|
65
|
+
it( 'parses reset commands for the tests environment.', () => {
|
|
66
|
+
cli().parse( [ 'reset', 'tests' ] );
|
|
67
|
+
const { environment, spinner } = env.reset.mock.calls[ 0 ][ 0 ];
|
|
65
68
|
expect( environment ).toBe( 'tests' );
|
|
66
69
|
expect( spinner.text ).toBe( '' );
|
|
67
70
|
} );
|
|
68
71
|
|
|
72
|
+
it( 'parses clean (deprecated) commands for the default environment.', () => {
|
|
73
|
+
cli().parse( [ 'clean' ] );
|
|
74
|
+
const { environment, spinner } = env.clean.mock.calls[ 0 ][ 0 ];
|
|
75
|
+
expect( environment ).toBe( 'development' );
|
|
76
|
+
expect( spinner.text ).toBe( '' );
|
|
77
|
+
} );
|
|
78
|
+
|
|
69
79
|
it( 'parses run commands without arguments.', () => {
|
|
70
80
|
cli().parse( [ 'run', 'tests-wordpress', 'test' ] );
|
|
71
81
|
const { container, command, spinner } = env.run.mock.calls[ 0 ][ 0 ];
|
|
@@ -81,6 +91,32 @@ describe( 'env cli', () => {
|
|
|
81
91
|
expect( spinner.text ).toBe( '' );
|
|
82
92
|
} );
|
|
83
93
|
|
|
94
|
+
it( 'parses destroy commands.', () => {
|
|
95
|
+
cli().parse( [ 'destroy' ] );
|
|
96
|
+
const { spinner, scripts, force } = env.destroy.mock.calls[ 0 ][ 0 ];
|
|
97
|
+
expect( spinner.text ).toBe( '' );
|
|
98
|
+
expect( scripts ).toBe( true );
|
|
99
|
+
expect( force ).toBe( false );
|
|
100
|
+
} );
|
|
101
|
+
it( 'parses destroy commands with --force flag.', () => {
|
|
102
|
+
cli().parse( [ 'destroy', '--force' ] );
|
|
103
|
+
const { force } = env.destroy.mock.calls[ 0 ][ 0 ];
|
|
104
|
+
expect( force ).toBe( true );
|
|
105
|
+
} );
|
|
106
|
+
|
|
107
|
+
it( 'parses cleanup commands.', () => {
|
|
108
|
+
cli().parse( [ 'cleanup' ] );
|
|
109
|
+
const { spinner, scripts, force } = env.cleanup.mock.calls[ 0 ][ 0 ];
|
|
110
|
+
expect( spinner.text ).toBe( '' );
|
|
111
|
+
expect( scripts ).toBe( true );
|
|
112
|
+
expect( force ).toBe( false );
|
|
113
|
+
} );
|
|
114
|
+
it( 'parses cleanup commands with --force flag.', () => {
|
|
115
|
+
cli().parse( [ 'cleanup', '--force' ] );
|
|
116
|
+
const { force } = env.cleanup.mock.calls[ 0 ][ 0 ];
|
|
117
|
+
expect( force ).toBe( true );
|
|
118
|
+
} );
|
|
119
|
+
|
|
84
120
|
it( 'handles successful commands with messages.', async () => {
|
|
85
121
|
env.start.mockResolvedValueOnce( 'success message' );
|
|
86
122
|
cli().parse( [ 'start' ] );
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wordpress/env",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "11.0.0",
|
|
4
4
|
"description": "A zero-config, self contained local WordPress environment for development and testing.",
|
|
5
5
|
"author": "The WordPress Contributors",
|
|
6
6
|
"license": "GPL-2.0-or-later",
|
|
@@ -64,5 +64,5 @@
|
|
|
64
64
|
"scripts": {
|
|
65
65
|
"test": "echo \"Error: run tests from root\" && exit 1"
|
|
66
66
|
},
|
|
67
|
-
"gitHead": "
|
|
67
|
+
"gitHead": "376124aa10dbc2cc0c81c964ec00b99fcfee5382"
|
|
68
68
|
}
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
/**
|
|
3
|
-
* External dependencies
|
|
4
|
-
*/
|
|
5
|
-
const path = require( 'path' );
|
|
6
|
-
const { existsSync } = require( 'fs' );
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Internal dependencies
|
|
10
|
-
*/
|
|
11
|
-
const { loadConfig } = require( '../config' );
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Logs the path to where wp-env files are installed.
|
|
15
|
-
*
|
|
16
|
-
* @param {Object} options
|
|
17
|
-
* @param {Object} options.spinner
|
|
18
|
-
*/
|
|
19
|
-
module.exports = async function installPath( { spinner } ) {
|
|
20
|
-
// Stop the spinner so that stdout is not polluted.
|
|
21
|
-
spinner.stop();
|
|
22
|
-
|
|
23
|
-
const config = await loadConfig( path.resolve( '.' ) );
|
|
24
|
-
|
|
25
|
-
if ( ! existsSync( config.workDirectoryPath ) ) {
|
|
26
|
-
console.error(
|
|
27
|
-
'wp-env has not yet been initialized. Please run `wp-env start` first.'
|
|
28
|
-
);
|
|
29
|
-
process.exit( 1 );
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
console.log( config.workDirectoryPath );
|
|
33
|
-
};
|