@@ -10,13 +10,13 @@ const mockPkg = json => {
10
10
fs . writeFileSync ( '/package.json' , JSON . stringify ( json , null , 2 ) )
11
11
}
12
12
13
- const createMockService = ( plugins = [ ] , init = true , mode ) => {
13
+ const createMockService = async ( plugins = [ ] , init = true , mode ) => {
14
14
const service = new Service ( '/' , {
15
15
plugins,
16
16
useBuiltIn : false
17
17
} )
18
18
if ( init ) {
19
- service . init ( mode )
19
+ await service . init ( mode )
20
20
}
21
21
return service
22
22
}
@@ -36,11 +36,11 @@ afterEach(() => {
36
36
}
37
37
} )
38
38
39
- test ( 'env loading' , ( ) => {
39
+ test ( 'env loading' , async ( ) => {
40
40
process . env . FOO = 0
41
41
fs . writeFileSync ( '/.env.local' , `FOO=1\nBAR=2` )
42
42
fs . writeFileSync ( '/.env' , `BAR=3\nBAZ=4` )
43
- createMockService ( )
43
+ await createMockService ( )
44
44
45
45
expect ( process . env . FOO ) . toBe ( '0' )
46
46
expect ( process . env . BAR ) . toBe ( '2' )
@@ -50,11 +50,11 @@ test('env loading', () => {
50
50
fs . unlinkSync ( '/.env' )
51
51
} )
52
52
53
- test ( 'env loading for custom mode' , ( ) => {
53
+ test ( 'env loading for custom mode' , async ( ) => {
54
54
process . env . VUE_CLI_TEST_TESTING_ENV = true
55
55
fs . writeFileSync ( '/.env' , 'FOO=1' )
56
56
fs . writeFileSync ( '/.env.staging' , 'FOO=2\nNODE_ENV=production' )
57
- createMockService ( [ ] , true , 'staging' )
57
+ await createMockService ( [ ] , true , 'staging' )
58
58
59
59
expect ( process . env . FOO ) . toBe ( '2' )
60
60
expect ( process . env . NODE_ENV ) . toBe ( 'production' )
@@ -78,85 +78,85 @@ test('loading plugins from package.json', () => {
78
78
expect ( service . plugins . some ( ( { id } ) => id === 'bar' ) ) . toBe ( false )
79
79
} )
80
80
81
- test ( 'load project options from package.json' , ( ) => {
81
+ test ( 'load project options from package.json' , async ( ) => {
82
82
mockPkg ( {
83
83
vue : {
84
84
lintOnSave : 'default'
85
85
}
86
86
} )
87
- const service = createMockService ( )
87
+ const service = await createMockService ( )
88
88
expect ( service . projectOptions . lintOnSave ) . toBe ( 'default' )
89
89
} )
90
90
91
- test ( 'handle option publicPath and outputDir correctly' , ( ) => {
91
+ test ( 'handle option publicPath and outputDir correctly' , async ( ) => {
92
92
mockPkg ( {
93
93
vue : {
94
94
publicPath : 'https://foo.com/bar' ,
95
95
outputDir : '/public/'
96
96
}
97
97
} )
98
- const service = createMockService ( )
98
+ const service = await createMockService ( )
99
99
expect ( service . projectOptions . publicPath ) . toBe ( 'https://foo.com/bar/' )
100
100
expect ( service . projectOptions . outputDir ) . toBe ( '/public' )
101
101
} )
102
102
103
- test ( 'normalize publicPath when relative' , ( ) => {
103
+ test ( 'normalize publicPath when relative' , async ( ) => {
104
104
mockPkg ( {
105
105
vue : {
106
106
publicPath : './foo/bar'
107
107
}
108
108
} )
109
- const service = createMockService ( )
109
+ const service = await createMockService ( )
110
110
expect ( service . projectOptions . publicPath ) . toBe ( 'foo/bar/' )
111
111
} )
112
112
113
- test ( 'allow custom protocol in publicPath' , ( ) => {
113
+ test ( 'allow custom protocol in publicPath' , async ( ) => {
114
114
mockPkg ( {
115
115
vue : {
116
116
publicPath : 'customprotocol://foo/bar'
117
117
}
118
118
} )
119
- const service = createMockService ( )
119
+ const service = await createMockService ( )
120
120
expect ( service . projectOptions . publicPath ) . toBe ( 'customprotocol://foo/bar/' )
121
121
} )
122
122
123
- test ( 'keep publicPath when empty' , ( ) => {
123
+ test ( 'keep publicPath when empty' , async ( ) => {
124
124
mockPkg ( {
125
125
vue : {
126
126
publicPath : ''
127
127
}
128
128
} )
129
- const service = createMockService ( )
129
+ const service = await createMockService ( )
130
130
expect ( service . projectOptions . publicPath ) . toBe ( '' )
131
131
} )
132
132
133
- test ( 'load project options from vue.config.js' , ( ) => {
133
+ test ( 'load project options from vue.config.js' , async ( ) => {
134
134
fs . writeFileSync ( path . resolve ( '/' , 'vue.config.js' ) , '' ) // only to ensure fs.existsSync returns true
135
135
jest . mock ( path . resolve ( '/' , 'vue.config.js' ) , ( ) => ( { lintOnSave : false } ) , { virtual : true } )
136
136
mockPkg ( {
137
137
vue : {
138
138
lintOnSave : 'default'
139
139
}
140
140
} )
141
- const service = createMockService ( )
141
+ const service = await createMockService ( )
142
142
// vue.config.js has higher priority
143
143
expect ( service . projectOptions . lintOnSave ) . toBe ( false )
144
144
} )
145
145
146
- test ( 'load project options from vue.config.js as a function' , ( ) => {
146
+ test ( 'load project options from vue.config.js as a function' , async ( ) => {
147
147
fs . writeFileSync ( path . resolve ( '/' , 'vue.config.js' ) , '' )
148
148
jest . mock ( path . resolve ( '/' , 'vue.config.js' ) , ( ) => function ( ) { return { lintOnSave : false } } , { virtual : true } )
149
149
mockPkg ( {
150
150
vue : {
151
151
lintOnSave : 'default'
152
152
}
153
153
} )
154
- const service = createMockService ( )
154
+ const service = await createMockService ( )
155
155
// vue.config.js has higher priority
156
156
expect ( service . projectOptions . lintOnSave ) . toBe ( false )
157
157
} )
158
158
159
- test ( 'api: assertVersion' , ( ) => {
159
+ test ( 'api: assertVersion' , async ( ) => {
160
160
const plugin = {
161
161
id : 'test-assertVersion' ,
162
162
apply : api => {
@@ -169,12 +169,12 @@ test('api: assertVersion', () => {
169
169
expect ( ( ) => api . assertVersion ( '^100' ) ) . toThrow ( 'Require @vue/cli-service "^100"' )
170
170
}
171
171
}
172
- createMockService ( [ plugin ] , true /* init */ )
172
+ await createMockService ( [ plugin ] , true /* init */ )
173
173
} )
174
174
175
- test ( 'api: registerCommand' , ( ) => {
175
+ test ( 'api: registerCommand' , async ( ) => {
176
176
let args
177
- const service = createMockService ( [ {
177
+ const service = await createMockService ( [ {
178
178
id : 'test' ,
179
179
apply : api => {
180
180
api . registerCommand ( 'foo' , _args => {
@@ -183,13 +183,13 @@ test('api: registerCommand', () => {
183
183
}
184
184
} ] )
185
185
186
- service . run ( 'foo' , { n : 1 } )
186
+ await service . run ( 'foo' , { n : 1 } )
187
187
expect ( args ) . toEqual ( { _ : [ ] , n : 1 } )
188
188
} )
189
189
190
- test ( 'api: --skip-plugins' , ( ) => {
190
+ test ( 'api: --skip-plugins' , async ( ) => {
191
191
let untouched = true
192
- const service = createMockService ( [ {
192
+ const service = await createMockService ( [ {
193
193
id : 'test-command' ,
194
194
apply : api => {
195
195
api . registerCommand ( 'foo' , _args => {
@@ -204,11 +204,11 @@ test('api: --skip-plugins', () => {
204
204
}
205
205
} ] , false )
206
206
207
- service . run ( 'foo' , { 'skip-plugins' : 'test-plugin' } )
207
+ await service . run ( 'foo' , { 'skip-plugins' : 'test-plugin' } )
208
208
expect ( untouched ) . toEqual ( true )
209
209
} )
210
210
211
- test ( 'api: defaultModes' , ( ) => {
211
+ test ( 'api: defaultModes' , async ( ) => {
212
212
fs . writeFileSync ( '/.env.foo' , `FOO=5\nBAR=6` )
213
213
fs . writeFileSync ( '/.env.foo.local' , `FOO=7\nBAZ=8` )
214
214
@@ -229,7 +229,7 @@ test('api: defaultModes', () => {
229
229
foo : 'foo'
230
230
}
231
231
232
- createMockService ( [ plugin1 ] , false /* init */ ) . run ( 'foo' )
232
+ await ( await createMockService ( [ plugin1 ] , false /* init */ ) ) . run ( 'foo' )
233
233
234
234
delete process . env . NODE_ENV
235
235
delete process . env . BABEL_ENV
@@ -246,11 +246,11 @@ test('api: defaultModes', () => {
246
246
test : 'test'
247
247
}
248
248
249
- createMockService ( [ plugin2 ] , false /* init */ ) . run ( 'test' )
249
+ await ( await createMockService ( [ plugin2 ] , false /* init */ ) ) . run ( 'test' )
250
250
} )
251
251
252
- test ( 'api: chainWebpack' , ( ) => {
253
- const service = createMockService ( [ {
252
+ test ( 'api: chainWebpack' , async ( ) => {
253
+ const service = await createMockService ( [ {
254
254
id : 'test' ,
255
255
apply : api => {
256
256
api . chainWebpack ( config => {
@@ -263,8 +263,8 @@ test('api: chainWebpack', () => {
263
263
expect ( config . output . path ) . toBe ( 'test-dist' )
264
264
} )
265
265
266
- test ( 'api: configureWebpack' , ( ) => {
267
- const service = createMockService ( [ {
266
+ test ( 'api: configureWebpack' , async ( ) => {
267
+ const service = await createMockService ( [ {
268
268
id : 'test' ,
269
269
apply : api => {
270
270
api . configureWebpack ( config => {
@@ -279,8 +279,8 @@ test('api: configureWebpack', () => {
279
279
expect ( config . output . path ) . toBe ( 'test-dist-2' )
280
280
} )
281
281
282
- test ( 'api: configureWebpack returning object' , ( ) => {
283
- const service = createMockService ( [ {
282
+ test ( 'api: configureWebpack returning object' , async ( ) => {
283
+ const service = await createMockService ( [ {
284
284
id : 'test' ,
285
285
apply : api => {
286
286
api . configureWebpack ( config => {
@@ -297,8 +297,8 @@ test('api: configureWebpack returning object', () => {
297
297
expect ( config . output . path ) . toBe ( 'test-dist-3' )
298
298
} )
299
299
300
- test ( 'api: configureWebpack preserve ruleNames' , ( ) => {
301
- const service = createMockService ( [
300
+ test ( 'api: configureWebpack preserve ruleNames' , async ( ) => {
301
+ const service = await createMockService ( [
302
302
{
303
303
id : 'babel' ,
304
304
apply : require ( '@vue/cli-plugin-babel' )
@@ -319,10 +319,10 @@ test('api: configureWebpack preserve ruleNames', () => {
319
319
expect ( config . module . rules [ 0 ] . __ruleNames ) . toEqual ( [ 'js' ] )
320
320
} )
321
321
322
- test ( 'internal: should correctly set VUE_CLI_ENTRY_FILES' , ( ) => {
322
+ test ( 'internal: should correctly set VUE_CLI_ENTRY_FILES' , async ( ) => {
323
323
delete process . env . VUE_CLI_ENTRY_FILES
324
324
325
- const service = createMockService ( [ {
325
+ const service = await createMockService ( [ {
326
326
id : 'test' ,
327
327
apply : api => {
328
328
api . configureWebpack ( config => {
@@ -343,9 +343,9 @@ test('internal: should correctly set VUE_CLI_ENTRY_FILES', () => {
343
343
)
344
344
} )
345
345
346
- test ( 'api: configureDevServer' , ( ) => {
346
+ test ( 'api: configureDevServer' , async ( ) => {
347
347
const cb = ( ) => { }
348
- const service = createMockService ( [ {
348
+ const service = await createMockService ( [ {
349
349
id : 'test' ,
350
350
apply : api => {
351
351
api . configureDevServer ( cb )
@@ -354,17 +354,17 @@ test('api: configureDevServer', () => {
354
354
expect ( service . devServerConfigFns ) . toContain ( cb )
355
355
} )
356
356
357
- test ( 'api: resolve' , ( ) => {
358
- createMockService ( [ {
357
+ test ( 'api: resolve' , async ( ) => {
358
+ await createMockService ( [ {
359
359
id : 'test' ,
360
360
apply : api => {
361
361
expect ( api . resolve ( 'foo.js' ) ) . toBe ( path . resolve ( '/' , 'foo.js' ) )
362
362
}
363
363
} ] )
364
364
} )
365
365
366
- test ( 'api: hasPlugin' , ( ) => {
367
- createMockService ( [
366
+ test ( 'api: hasPlugin' , async ( ) => {
367
+ await createMockService ( [
368
368
{
369
369
id : 'vue-cli-plugin-foo' ,
370
370
apply : api => {
0 commit comments