@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
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
/* eslint-disable jest/no-conditional-expect */
|
|
3
|
+
/**
|
|
4
|
+
* External dependencies
|
|
5
|
+
*/
|
|
6
|
+
const path = require( 'path' );
|
|
7
|
+
const { homedir } = require( 'os' );
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Internal dependencies
|
|
11
|
+
*/
|
|
12
|
+
const { ValidationError } = require( '../validate-config' );
|
|
13
|
+
const { parseSourceString } = require( '../parse-source-string' );
|
|
14
|
+
|
|
15
|
+
jest.mock( 'os', () => ( {
|
|
16
|
+
homedir: jest.fn(),
|
|
17
|
+
} ) );
|
|
18
|
+
|
|
19
|
+
describe( 'parseSourceString', () => {
|
|
20
|
+
const options = {
|
|
21
|
+
cacheDirectoryPath: '/test/cache',
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
beforeEach( () => {
|
|
25
|
+
homedir.mockReturnValue( '/home/test' );
|
|
26
|
+
} );
|
|
27
|
+
|
|
28
|
+
it( 'should do nothing when given an empty source', () => {
|
|
29
|
+
expect( parseSourceString( null, options ) ).toEqual( null );
|
|
30
|
+
} );
|
|
31
|
+
|
|
32
|
+
it( 'should throw when source not parseable', () => {
|
|
33
|
+
expect.assertions( 1 );
|
|
34
|
+
try {
|
|
35
|
+
parseSourceString( 'test://test', options );
|
|
36
|
+
} catch ( error ) {
|
|
37
|
+
expect( error ).toEqual(
|
|
38
|
+
new ValidationError(
|
|
39
|
+
'Invalid or unrecognized source: "test://test".'
|
|
40
|
+
)
|
|
41
|
+
);
|
|
42
|
+
}
|
|
43
|
+
} );
|
|
44
|
+
|
|
45
|
+
describe( 'local sources', () => {
|
|
46
|
+
it( 'should parse relative directories', () => {
|
|
47
|
+
expect( parseSourceString( '.', options ) ).toEqual( {
|
|
48
|
+
basename: 'gutenberg',
|
|
49
|
+
path: path.resolve( '.' ),
|
|
50
|
+
type: 'local',
|
|
51
|
+
} );
|
|
52
|
+
} );
|
|
53
|
+
|
|
54
|
+
it( 'should parse home directories', () => {
|
|
55
|
+
expect( parseSourceString( '~/test', options ) ).toEqual( {
|
|
56
|
+
basename: 'test',
|
|
57
|
+
path: '/home/test/test',
|
|
58
|
+
type: 'local',
|
|
59
|
+
} );
|
|
60
|
+
} );
|
|
61
|
+
|
|
62
|
+
it( 'should parse absolute directories', () => {
|
|
63
|
+
expect( parseSourceString( '/absolute/test', options ) ).toEqual( {
|
|
64
|
+
basename: 'test',
|
|
65
|
+
path: '/absolute/test',
|
|
66
|
+
type: 'local',
|
|
67
|
+
} );
|
|
68
|
+
} );
|
|
69
|
+
} );
|
|
70
|
+
|
|
71
|
+
describe( 'zip sources', () => {
|
|
72
|
+
it( 'should parse WordPress.org sources', () => {
|
|
73
|
+
expect(
|
|
74
|
+
parseSourceString(
|
|
75
|
+
'http://downloads.wordpress.org/plugin/gutenberg.zip',
|
|
76
|
+
options
|
|
77
|
+
)
|
|
78
|
+
).toEqual( {
|
|
79
|
+
basename: 'gutenberg',
|
|
80
|
+
path: '/test/cache/gutenberg',
|
|
81
|
+
type: 'zip',
|
|
82
|
+
url: 'http://downloads.wordpress.org/plugin/gutenberg.zip',
|
|
83
|
+
} );
|
|
84
|
+
} );
|
|
85
|
+
|
|
86
|
+
it( 'should parse other sources', () => {
|
|
87
|
+
expect(
|
|
88
|
+
parseSourceString( 'http://test.com/testing.zip', options )
|
|
89
|
+
).toEqual( {
|
|
90
|
+
basename: 'testing',
|
|
91
|
+
path: '/test/cache/testing',
|
|
92
|
+
type: 'zip',
|
|
93
|
+
url: 'http://test.com/testing.zip',
|
|
94
|
+
} );
|
|
95
|
+
} );
|
|
96
|
+
} );
|
|
97
|
+
|
|
98
|
+
describe( 'Git SSH sources', () => {
|
|
99
|
+
it( 'should parse ssh protocol', () => {
|
|
100
|
+
expect(
|
|
101
|
+
parseSourceString( 'ssh://test/test.git#trunk', options )
|
|
102
|
+
).toEqual( {
|
|
103
|
+
basename: 'test',
|
|
104
|
+
path: '/test/cache/test',
|
|
105
|
+
clonePath: '/test/cache/test',
|
|
106
|
+
ref: 'trunk',
|
|
107
|
+
type: 'git',
|
|
108
|
+
url: 'ssh://test/test.git',
|
|
109
|
+
} );
|
|
110
|
+
} );
|
|
111
|
+
|
|
112
|
+
it( 'should parse git+ssh protocol', () => {
|
|
113
|
+
expect(
|
|
114
|
+
parseSourceString( 'git+ssh://test/test.git#trunk', options )
|
|
115
|
+
).toEqual( {
|
|
116
|
+
basename: 'test',
|
|
117
|
+
path: '/test/cache/test',
|
|
118
|
+
clonePath: '/test/cache/test',
|
|
119
|
+
ref: 'trunk',
|
|
120
|
+
type: 'git',
|
|
121
|
+
url: 'git+ssh://test/test.git',
|
|
122
|
+
} );
|
|
123
|
+
} );
|
|
124
|
+
|
|
125
|
+
it( 'should work without ref', () => {
|
|
126
|
+
expect(
|
|
127
|
+
parseSourceString( 'ssh://test/test.git', options )
|
|
128
|
+
).toEqual( {
|
|
129
|
+
basename: 'test',
|
|
130
|
+
path: '/test/cache/test',
|
|
131
|
+
clonePath: '/test/cache/test',
|
|
132
|
+
ref: undefined,
|
|
133
|
+
type: 'git',
|
|
134
|
+
url: 'ssh://test/test.git',
|
|
135
|
+
} );
|
|
136
|
+
} );
|
|
137
|
+
} );
|
|
138
|
+
|
|
139
|
+
describe( 'GitHub sources', () => {
|
|
140
|
+
it( 'should parse', () => {
|
|
141
|
+
expect(
|
|
142
|
+
parseSourceString( 'WordPress/gutenberg#trunk', options )
|
|
143
|
+
).toEqual( {
|
|
144
|
+
basename: 'gutenberg',
|
|
145
|
+
path: '/test/cache/gutenberg',
|
|
146
|
+
clonePath: '/test/cache/gutenberg',
|
|
147
|
+
ref: 'trunk',
|
|
148
|
+
type: 'git',
|
|
149
|
+
url: 'https://github.com/WordPress/gutenberg.git',
|
|
150
|
+
} );
|
|
151
|
+
} );
|
|
152
|
+
} );
|
|
153
|
+
} );
|
|
154
|
+
/* eslint-enable jest/no-conditional-expect */
|
|
@@ -0,0 +1,295 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
/**
|
|
3
|
+
* Internal dependencies
|
|
4
|
+
*/
|
|
5
|
+
const { ValidationError } = require( '..' );
|
|
6
|
+
const postProcessConfig = require( '../post-process-config' );
|
|
7
|
+
|
|
8
|
+
describe( 'postProcessConfig', () => {
|
|
9
|
+
afterEach( () => {
|
|
10
|
+
jest.clearAllMocks();
|
|
11
|
+
} );
|
|
12
|
+
|
|
13
|
+
it( 'should merge relevant root options into environment options', () => {
|
|
14
|
+
const processed = postProcessConfig( {
|
|
15
|
+
port: 123,
|
|
16
|
+
testsPort: 456,
|
|
17
|
+
coreSource: {
|
|
18
|
+
type: 'test',
|
|
19
|
+
},
|
|
20
|
+
config: {
|
|
21
|
+
TESTS_ROOT: 'root',
|
|
22
|
+
},
|
|
23
|
+
pluginSources: [
|
|
24
|
+
{
|
|
25
|
+
type: 'root-plugin',
|
|
26
|
+
},
|
|
27
|
+
],
|
|
28
|
+
themeSources: [
|
|
29
|
+
{
|
|
30
|
+
type: 'root-theme',
|
|
31
|
+
},
|
|
32
|
+
],
|
|
33
|
+
mappings: {
|
|
34
|
+
'root-mapping': {
|
|
35
|
+
type: 'root-mapping',
|
|
36
|
+
},
|
|
37
|
+
},
|
|
38
|
+
env: {
|
|
39
|
+
development: {
|
|
40
|
+
coreSource: {
|
|
41
|
+
type: 'test',
|
|
42
|
+
},
|
|
43
|
+
config: {
|
|
44
|
+
TEST_ENV: 'development',
|
|
45
|
+
},
|
|
46
|
+
pluginSources: [
|
|
47
|
+
{
|
|
48
|
+
type: 'development-plugin',
|
|
49
|
+
},
|
|
50
|
+
],
|
|
51
|
+
themeSources: [
|
|
52
|
+
{
|
|
53
|
+
type: 'development-theme',
|
|
54
|
+
},
|
|
55
|
+
],
|
|
56
|
+
mappings: {
|
|
57
|
+
'development-mapping': {
|
|
58
|
+
type: 'development-mapping',
|
|
59
|
+
},
|
|
60
|
+
},
|
|
61
|
+
},
|
|
62
|
+
tests: {
|
|
63
|
+
coreSource: {
|
|
64
|
+
type: 'test',
|
|
65
|
+
},
|
|
66
|
+
config: {
|
|
67
|
+
TEST_ENV: 'tests',
|
|
68
|
+
},
|
|
69
|
+
},
|
|
70
|
+
},
|
|
71
|
+
} );
|
|
72
|
+
|
|
73
|
+
expect( processed ).toEqual( {
|
|
74
|
+
port: 123,
|
|
75
|
+
testsPort: 456,
|
|
76
|
+
coreSource: {
|
|
77
|
+
type: 'test',
|
|
78
|
+
},
|
|
79
|
+
config: {
|
|
80
|
+
TESTS_ROOT: 'root',
|
|
81
|
+
},
|
|
82
|
+
pluginSources: [
|
|
83
|
+
{
|
|
84
|
+
type: 'root-plugin',
|
|
85
|
+
},
|
|
86
|
+
],
|
|
87
|
+
themeSources: [
|
|
88
|
+
{
|
|
89
|
+
type: 'root-theme',
|
|
90
|
+
},
|
|
91
|
+
],
|
|
92
|
+
mappings: {
|
|
93
|
+
'root-mapping': {
|
|
94
|
+
type: 'root-mapping',
|
|
95
|
+
},
|
|
96
|
+
},
|
|
97
|
+
env: {
|
|
98
|
+
development: {
|
|
99
|
+
port: 123,
|
|
100
|
+
coreSource: {
|
|
101
|
+
type: 'test',
|
|
102
|
+
},
|
|
103
|
+
config: {
|
|
104
|
+
TESTS_ROOT: 'root',
|
|
105
|
+
TEST_ENV: 'development',
|
|
106
|
+
},
|
|
107
|
+
pluginSources: [
|
|
108
|
+
{
|
|
109
|
+
type: 'development-plugin',
|
|
110
|
+
},
|
|
111
|
+
],
|
|
112
|
+
themeSources: [
|
|
113
|
+
{
|
|
114
|
+
type: 'development-theme',
|
|
115
|
+
},
|
|
116
|
+
],
|
|
117
|
+
mappings: {
|
|
118
|
+
'root-mapping': {
|
|
119
|
+
type: 'root-mapping',
|
|
120
|
+
},
|
|
121
|
+
'development-mapping': {
|
|
122
|
+
type: 'development-mapping',
|
|
123
|
+
},
|
|
124
|
+
},
|
|
125
|
+
},
|
|
126
|
+
tests: {
|
|
127
|
+
port: 456,
|
|
128
|
+
coreSource: {
|
|
129
|
+
type: 'test',
|
|
130
|
+
},
|
|
131
|
+
config: {
|
|
132
|
+
TESTS_ROOT: 'root',
|
|
133
|
+
TEST_ENV: 'tests',
|
|
134
|
+
},
|
|
135
|
+
pluginSources: [
|
|
136
|
+
{
|
|
137
|
+
type: 'root-plugin',
|
|
138
|
+
},
|
|
139
|
+
],
|
|
140
|
+
themeSources: [
|
|
141
|
+
{
|
|
142
|
+
type: 'root-theme',
|
|
143
|
+
},
|
|
144
|
+
],
|
|
145
|
+
mappings: {
|
|
146
|
+
'root-mapping': {
|
|
147
|
+
type: 'root-mapping',
|
|
148
|
+
},
|
|
149
|
+
},
|
|
150
|
+
},
|
|
151
|
+
},
|
|
152
|
+
} );
|
|
153
|
+
} );
|
|
154
|
+
|
|
155
|
+
it( 'should not merge some root options into environment options', () => {
|
|
156
|
+
const processed = postProcessConfig( {
|
|
157
|
+
port: 8888,
|
|
158
|
+
testsPort: 8889,
|
|
159
|
+
afterSetup: 'test',
|
|
160
|
+
env: {
|
|
161
|
+
development: {},
|
|
162
|
+
tests: {},
|
|
163
|
+
},
|
|
164
|
+
} );
|
|
165
|
+
|
|
166
|
+
expect( processed ).toEqual( {
|
|
167
|
+
port: 8888,
|
|
168
|
+
testsPort: 8889,
|
|
169
|
+
afterSetup: 'test',
|
|
170
|
+
env: {
|
|
171
|
+
development: {
|
|
172
|
+
port: 8888,
|
|
173
|
+
},
|
|
174
|
+
tests: {
|
|
175
|
+
port: 8889,
|
|
176
|
+
},
|
|
177
|
+
},
|
|
178
|
+
} );
|
|
179
|
+
} );
|
|
180
|
+
|
|
181
|
+
describe( 'appendPortToWPConfigs', () => {
|
|
182
|
+
it( 'should add port to certain environment config options', () => {
|
|
183
|
+
const processed = postProcessConfig( {
|
|
184
|
+
port: 123,
|
|
185
|
+
config: {
|
|
186
|
+
WP_TESTS_DOMAIN: 'localhost',
|
|
187
|
+
WP_SITEURL: 'localhost',
|
|
188
|
+
WP_HOME: 'localhost',
|
|
189
|
+
},
|
|
190
|
+
env: {
|
|
191
|
+
development: {
|
|
192
|
+
port: 123,
|
|
193
|
+
},
|
|
194
|
+
tests: {
|
|
195
|
+
port: 456,
|
|
196
|
+
},
|
|
197
|
+
},
|
|
198
|
+
} );
|
|
199
|
+
|
|
200
|
+
expect( processed ).toEqual( {
|
|
201
|
+
// Since the root-level config shouldn't apply to an environment,
|
|
202
|
+
// we shouldn't add the port to the config options for it.
|
|
203
|
+
port: 123,
|
|
204
|
+
config: {
|
|
205
|
+
WP_TESTS_DOMAIN: 'localhost',
|
|
206
|
+
WP_SITEURL: 'localhost',
|
|
207
|
+
WP_HOME: 'localhost',
|
|
208
|
+
},
|
|
209
|
+
env: {
|
|
210
|
+
development: {
|
|
211
|
+
port: 123,
|
|
212
|
+
config: {
|
|
213
|
+
WP_TESTS_DOMAIN: 'localhost:123',
|
|
214
|
+
WP_SITEURL: 'localhost:123',
|
|
215
|
+
WP_HOME: 'localhost:123',
|
|
216
|
+
},
|
|
217
|
+
},
|
|
218
|
+
tests: {
|
|
219
|
+
port: 456,
|
|
220
|
+
config: {
|
|
221
|
+
WP_TESTS_DOMAIN: 'localhost:456',
|
|
222
|
+
WP_SITEURL: 'localhost:456',
|
|
223
|
+
WP_HOME: 'localhost:456',
|
|
224
|
+
},
|
|
225
|
+
},
|
|
226
|
+
},
|
|
227
|
+
} );
|
|
228
|
+
} );
|
|
229
|
+
|
|
230
|
+
it( 'should not overwrite port in WP_HOME', () => {
|
|
231
|
+
const processed = postProcessConfig( {
|
|
232
|
+
env: {
|
|
233
|
+
development: {
|
|
234
|
+
port: 123,
|
|
235
|
+
config: {
|
|
236
|
+
WP_TESTS_DOMAIN: 'localhost:777',
|
|
237
|
+
WP_SITEURL: 'localhost:777',
|
|
238
|
+
WP_HOME: 'localhost:777',
|
|
239
|
+
},
|
|
240
|
+
},
|
|
241
|
+
tests: {
|
|
242
|
+
port: 456,
|
|
243
|
+
config: {
|
|
244
|
+
WP_TESTS_DOMAIN: 'localhost:777',
|
|
245
|
+
WP_SITEURL: 'localhost:777',
|
|
246
|
+
WP_HOME: 'localhost:777',
|
|
247
|
+
},
|
|
248
|
+
},
|
|
249
|
+
},
|
|
250
|
+
} );
|
|
251
|
+
|
|
252
|
+
expect( processed ).toEqual( {
|
|
253
|
+
env: {
|
|
254
|
+
development: {
|
|
255
|
+
port: 123,
|
|
256
|
+
config: {
|
|
257
|
+
WP_TESTS_DOMAIN: 'localhost:123',
|
|
258
|
+
WP_SITEURL: 'localhost:123',
|
|
259
|
+
WP_HOME: 'localhost:777',
|
|
260
|
+
},
|
|
261
|
+
},
|
|
262
|
+
tests: {
|
|
263
|
+
port: 456,
|
|
264
|
+
config: {
|
|
265
|
+
WP_TESTS_DOMAIN: 'localhost:456',
|
|
266
|
+
WP_SITEURL: 'localhost:456',
|
|
267
|
+
WP_HOME: 'localhost:777',
|
|
268
|
+
},
|
|
269
|
+
},
|
|
270
|
+
},
|
|
271
|
+
} );
|
|
272
|
+
} );
|
|
273
|
+
} );
|
|
274
|
+
|
|
275
|
+
describe( 'validatePortUniqueness', () => {
|
|
276
|
+
it( 'should fail when two environments have the same port', () => {
|
|
277
|
+
expect( () => {
|
|
278
|
+
postProcessConfig( {
|
|
279
|
+
env: {
|
|
280
|
+
development: {
|
|
281
|
+
port: 123,
|
|
282
|
+
},
|
|
283
|
+
tests: {
|
|
284
|
+
port: 123,
|
|
285
|
+
},
|
|
286
|
+
},
|
|
287
|
+
} );
|
|
288
|
+
} ).toThrow(
|
|
289
|
+
new ValidationError(
|
|
290
|
+
'The "development" and "tests" environments may not have the same port.'
|
|
291
|
+
)
|
|
292
|
+
);
|
|
293
|
+
} );
|
|
294
|
+
} );
|
|
295
|
+
} );
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
/* eslint-disable jest/no-conditional-expect */
|
|
1
3
|
/**
|
|
2
4
|
* External dependencies
|
|
3
5
|
*/
|
|
@@ -6,7 +8,8 @@ const { readFile } = require( 'fs' ).promises;
|
|
|
6
8
|
/**
|
|
7
9
|
* Internal dependencies
|
|
8
10
|
*/
|
|
9
|
-
const
|
|
11
|
+
const readRawConfigFile = require( '../read-raw-config-file' );
|
|
12
|
+
const { ValidationError } = require( '../validate-config' );
|
|
10
13
|
|
|
11
14
|
jest.mock( 'fs', () => ( {
|
|
12
15
|
promises: {
|
|
@@ -15,76 +18,29 @@ jest.mock( 'fs', () => ( {
|
|
|
15
18
|
} ) );
|
|
16
19
|
|
|
17
20
|
describe( 'readRawConfigFile', () => {
|
|
18
|
-
|
|
21
|
+
afterEach( () => {
|
|
19
22
|
jest.clearAllMocks();
|
|
20
23
|
} );
|
|
21
24
|
|
|
22
25
|
it( 'returns null if it cannot find a file', async () => {
|
|
23
|
-
readFile.
|
|
24
|
-
|
|
25
|
-
);
|
|
26
|
-
const result = await readConfigFile( 'wp-env', '/.wp-env.json' );
|
|
26
|
+
readFile.mockRejectedValue( { code: 'ENOENT' } );
|
|
27
|
+
|
|
28
|
+
const result = await readRawConfigFile( '/.wp-env.json' );
|
|
27
29
|
expect( result ).toBe( null );
|
|
28
30
|
} );
|
|
29
31
|
|
|
30
|
-
it( '
|
|
31
|
-
readFile.
|
|
32
|
-
Promise.resolve( JSON.stringify( { testsPort: 100 } ) )
|
|
33
|
-
);
|
|
34
|
-
const result = await readConfigFile( 'wp-env', '/.wp-env.json' );
|
|
35
|
-
expect( result ).toEqual( {
|
|
36
|
-
env: {
|
|
37
|
-
tests: {
|
|
38
|
-
port: 100,
|
|
39
|
-
},
|
|
40
|
-
},
|
|
41
|
-
} );
|
|
42
|
-
} );
|
|
32
|
+
it( 'rejects when read file fails', async () => {
|
|
33
|
+
readFile.mockRejectedValue( { message: 'Test' } );
|
|
43
34
|
|
|
44
|
-
|
|
45
|
-
readFile.mockImplementation( () =>
|
|
46
|
-
Promise.resolve(
|
|
47
|
-
JSON.stringify( {
|
|
48
|
-
testsPort: 100,
|
|
49
|
-
env: {
|
|
50
|
-
tests: {
|
|
51
|
-
something: 'test',
|
|
52
|
-
},
|
|
53
|
-
},
|
|
54
|
-
} )
|
|
55
|
-
)
|
|
56
|
-
);
|
|
57
|
-
const result = await readConfigFile( 'wp-env', '/.wp-env.json' );
|
|
58
|
-
expect( result ).toEqual( {
|
|
59
|
-
env: {
|
|
60
|
-
tests: {
|
|
61
|
-
port: 100,
|
|
62
|
-
something: 'test',
|
|
63
|
-
},
|
|
64
|
-
},
|
|
65
|
-
} );
|
|
66
|
-
} );
|
|
35
|
+
expect.assertions( 1 );
|
|
67
36
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
port: 200,
|
|
76
|
-
},
|
|
77
|
-
},
|
|
78
|
-
} )
|
|
79
|
-
)
|
|
80
|
-
);
|
|
81
|
-
const result = await readConfigFile( 'wp-env', '/.wp-env.json' );
|
|
82
|
-
expect( result ).toEqual( {
|
|
83
|
-
env: {
|
|
84
|
-
tests: {
|
|
85
|
-
port: 200,
|
|
86
|
-
},
|
|
87
|
-
},
|
|
88
|
-
} );
|
|
37
|
+
try {
|
|
38
|
+
await readRawConfigFile( '/.wp-env.json' );
|
|
39
|
+
} catch ( error ) {
|
|
40
|
+
expect( error ).toEqual(
|
|
41
|
+
new ValidationError( 'Could not read .wp-env.json: Test' )
|
|
42
|
+
);
|
|
43
|
+
}
|
|
89
44
|
} );
|
|
90
45
|
} );
|
|
46
|
+
/* eslint-enable jest/no-conditional-expect */
|