@@ -10,13 +10,13 @@ const mockPkg = json => {
1010 fs . writeFileSync ( '/package.json' , JSON . stringify ( json , null , 2 ) )
1111}
1212
13- const createMockService = ( plugins = [ ] , init = true , mode ) => {
13+ const createMockService = async ( plugins = [ ] , init = true , mode ) => {
1414 const service = new Service ( '/' , {
1515 plugins,
1616 useBuiltIn : false
1717 } )
1818 if ( init ) {
19- service . init ( mode )
19+ await service . init ( mode )
2020 }
2121 return service
2222}
@@ -36,11 +36,11 @@ afterEach(() => {
3636 }
3737} )
3838
39- test ( 'env loading' , ( ) => {
39+ test ( 'env loading' , async ( ) => {
4040 process . env . FOO = 0
4141 fs . writeFileSync ( '/.env.local' , `FOO=1\nBAR=2` )
4242 fs . writeFileSync ( '/.env' , `BAR=3\nBAZ=4` )
43- createMockService ( )
43+ await createMockService ( )
4444
4545 expect ( process . env . FOO ) . toBe ( '0' )
4646 expect ( process . env . BAR ) . toBe ( '2' )
@@ -50,11 +50,11 @@ test('env loading', () => {
5050 fs . unlinkSync ( '/.env' )
5151} )
5252
53- test ( 'env loading for custom mode' , ( ) => {
53+ test ( 'env loading for custom mode' , async ( ) => {
5454 process . env . VUE_CLI_TEST_TESTING_ENV = true
5555 fs . writeFileSync ( '/.env' , 'FOO=1' )
5656 fs . writeFileSync ( '/.env.staging' , 'FOO=2\nNODE_ENV=production' )
57- createMockService ( [ ] , true , 'staging' )
57+ await createMockService ( [ ] , true , 'staging' )
5858
5959 expect ( process . env . FOO ) . toBe ( '2' )
6060 expect ( process . env . NODE_ENV ) . toBe ( 'production' )
@@ -78,85 +78,85 @@ test('loading plugins from package.json', () => {
7878 expect ( service . plugins . some ( ( { id } ) => id === 'bar' ) ) . toBe ( false )
7979} )
8080
81- test ( 'load project options from package.json' , ( ) => {
81+ test ( 'load project options from package.json' , async ( ) => {
8282 mockPkg ( {
8383 vue : {
8484 lintOnSave : 'default'
8585 }
8686 } )
87- const service = createMockService ( )
87+ const service = await createMockService ( )
8888 expect ( service . projectOptions . lintOnSave ) . toBe ( 'default' )
8989} )
9090
91- test ( 'handle option publicPath and outputDir correctly' , ( ) => {
91+ test ( 'handle option publicPath and outputDir correctly' , async ( ) => {
9292 mockPkg ( {
9393 vue : {
9494 publicPath : 'https://foo.com/bar' ,
9595 outputDir : '/public/'
9696 }
9797 } )
98- const service = createMockService ( )
98+ const service = await createMockService ( )
9999 expect ( service . projectOptions . publicPath ) . toBe ( 'https://foo.com/bar/' )
100100 expect ( service . projectOptions . outputDir ) . toBe ( '/public' )
101101} )
102102
103- test ( 'normalize publicPath when relative' , ( ) => {
103+ test ( 'normalize publicPath when relative' , async ( ) => {
104104 mockPkg ( {
105105 vue : {
106106 publicPath : './foo/bar'
107107 }
108108 } )
109- const service = createMockService ( )
109+ const service = await createMockService ( )
110110 expect ( service . projectOptions . publicPath ) . toBe ( 'foo/bar/' )
111111} )
112112
113- test ( 'allow custom protocol in publicPath' , ( ) => {
113+ test ( 'allow custom protocol in publicPath' , async ( ) => {
114114 mockPkg ( {
115115 vue : {
116116 publicPath : 'customprotocol://foo/bar'
117117 }
118118 } )
119- const service = createMockService ( )
119+ const service = await createMockService ( )
120120 expect ( service . projectOptions . publicPath ) . toBe ( 'customprotocol://foo/bar/' )
121121} )
122122
123- test ( 'keep publicPath when empty' , ( ) => {
123+ test ( 'keep publicPath when empty' , async ( ) => {
124124 mockPkg ( {
125125 vue : {
126126 publicPath : ''
127127 }
128128 } )
129- const service = createMockService ( )
129+ const service = await createMockService ( )
130130 expect ( service . projectOptions . publicPath ) . toBe ( '' )
131131} )
132132
133- test ( 'load project options from vue.config.js' , ( ) => {
133+ test ( 'load project options from vue.config.js' , async ( ) => {
134134 fs . writeFileSync ( path . resolve ( '/' , 'vue.config.js' ) , '' ) // only to ensure fs.existsSync returns true
135135 jest . mock ( path . resolve ( '/' , 'vue.config.js' ) , ( ) => ( { lintOnSave : false } ) , { virtual : true } )
136136 mockPkg ( {
137137 vue : {
138138 lintOnSave : 'default'
139139 }
140140 } )
141- const service = createMockService ( )
141+ const service = await createMockService ( )
142142 // vue.config.js has higher priority
143143 expect ( service . projectOptions . lintOnSave ) . toBe ( false )
144144} )
145145
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 ( ) => {
147147 fs . writeFileSync ( path . resolve ( '/' , 'vue.config.js' ) , '' )
148148 jest . mock ( path . resolve ( '/' , 'vue.config.js' ) , ( ) => function ( ) { return { lintOnSave : false } } , { virtual : true } )
149149 mockPkg ( {
150150 vue : {
151151 lintOnSave : 'default'
152152 }
153153 } )
154- const service = createMockService ( )
154+ const service = await createMockService ( )
155155 // vue.config.js has higher priority
156156 expect ( service . projectOptions . lintOnSave ) . toBe ( false )
157157} )
158158
159- test ( 'api: assertVersion' , ( ) => {
159+ test ( 'api: assertVersion' , async ( ) => {
160160 const plugin = {
161161 id : 'test-assertVersion' ,
162162 apply : api => {
@@ -169,12 +169,12 @@ test('api: assertVersion', () => {
169169 expect ( ( ) => api . assertVersion ( '^100' ) ) . toThrow ( 'Require @vue/cli-service "^100"' )
170170 }
171171 }
172- createMockService ( [ plugin ] , true /* init */ )
172+ await createMockService ( [ plugin ] , true /* init */ )
173173} )
174174
175- test ( 'api: registerCommand' , ( ) => {
175+ test ( 'api: registerCommand' , async ( ) => {
176176 let args
177- const service = createMockService ( [ {
177+ const service = await createMockService ( [ {
178178 id : 'test' ,
179179 apply : api => {
180180 api . registerCommand ( 'foo' , _args => {
@@ -183,13 +183,13 @@ test('api: registerCommand', () => {
183183 }
184184 } ] )
185185
186- service . run ( 'foo' , { n : 1 } )
186+ await service . run ( 'foo' , { n : 1 } )
187187 expect ( args ) . toEqual ( { _ : [ ] , n : 1 } )
188188} )
189189
190- test ( 'api: --skip-plugins' , ( ) => {
190+ test ( 'api: --skip-plugins' , async ( ) => {
191191 let untouched = true
192- const service = createMockService ( [ {
192+ const service = await createMockService ( [ {
193193 id : 'test-command' ,
194194 apply : api => {
195195 api . registerCommand ( 'foo' , _args => {
@@ -204,11 +204,11 @@ test('api: --skip-plugins', () => {
204204 }
205205 } ] , false )
206206
207- service . run ( 'foo' , { 'skip-plugins' : 'test-plugin' } )
207+ await service . run ( 'foo' , { 'skip-plugins' : 'test-plugin' } )
208208 expect ( untouched ) . toEqual ( true )
209209} )
210210
211- test ( 'api: defaultModes' , ( ) => {
211+ test ( 'api: defaultModes' , async ( ) => {
212212 fs . writeFileSync ( '/.env.foo' , `FOO=5\nBAR=6` )
213213 fs . writeFileSync ( '/.env.foo.local' , `FOO=7\nBAZ=8` )
214214
@@ -229,7 +229,7 @@ test('api: defaultModes', () => {
229229 foo : 'foo'
230230 }
231231
232- createMockService ( [ plugin1 ] , false /* init */ ) . run ( 'foo' )
232+ await ( await createMockService ( [ plugin1 ] , false /* init */ ) ) . run ( 'foo' )
233233
234234 delete process . env . NODE_ENV
235235 delete process . env . BABEL_ENV
@@ -246,11 +246,11 @@ test('api: defaultModes', () => {
246246 test : 'test'
247247 }
248248
249- createMockService ( [ plugin2 ] , false /* init */ ) . run ( 'test' )
249+ await ( await createMockService ( [ plugin2 ] , false /* init */ ) ) . run ( 'test' )
250250} )
251251
252- test ( 'api: chainWebpack' , ( ) => {
253- const service = createMockService ( [ {
252+ test ( 'api: chainWebpack' , async ( ) => {
253+ const service = await createMockService ( [ {
254254 id : 'test' ,
255255 apply : api => {
256256 api . chainWebpack ( config => {
@@ -263,8 +263,8 @@ test('api: chainWebpack', () => {
263263 expect ( config . output . path ) . toBe ( 'test-dist' )
264264} )
265265
266- test ( 'api: configureWebpack' , ( ) => {
267- const service = createMockService ( [ {
266+ test ( 'api: configureWebpack' , async ( ) => {
267+ const service = await createMockService ( [ {
268268 id : 'test' ,
269269 apply : api => {
270270 api . configureWebpack ( config => {
@@ -279,8 +279,8 @@ test('api: configureWebpack', () => {
279279 expect ( config . output . path ) . toBe ( 'test-dist-2' )
280280} )
281281
282- test ( 'api: configureWebpack returning object' , ( ) => {
283- const service = createMockService ( [ {
282+ test ( 'api: configureWebpack returning object' , async ( ) => {
283+ const service = await createMockService ( [ {
284284 id : 'test' ,
285285 apply : api => {
286286 api . configureWebpack ( config => {
@@ -297,8 +297,8 @@ test('api: configureWebpack returning object', () => {
297297 expect ( config . output . path ) . toBe ( 'test-dist-3' )
298298} )
299299
300- test ( 'api: configureWebpack preserve ruleNames' , ( ) => {
301- const service = createMockService ( [
300+ test ( 'api: configureWebpack preserve ruleNames' , async ( ) => {
301+ const service = await createMockService ( [
302302 {
303303 id : 'babel' ,
304304 apply : require ( '@vue/cli-plugin-babel' )
@@ -319,10 +319,10 @@ test('api: configureWebpack preserve ruleNames', () => {
319319 expect ( config . module . rules [ 0 ] . __ruleNames ) . toEqual ( [ 'js' ] )
320320} )
321321
322- test ( 'internal: should correctly set VUE_CLI_ENTRY_FILES' , ( ) => {
322+ test ( 'internal: should correctly set VUE_CLI_ENTRY_FILES' , async ( ) => {
323323 delete process . env . VUE_CLI_ENTRY_FILES
324324
325- const service = createMockService ( [ {
325+ const service = await createMockService ( [ {
326326 id : 'test' ,
327327 apply : api => {
328328 api . configureWebpack ( config => {
@@ -343,9 +343,9 @@ test('internal: should correctly set VUE_CLI_ENTRY_FILES', () => {
343343 )
344344} )
345345
346- test ( 'api: configureDevServer' , ( ) => {
346+ test ( 'api: configureDevServer' , async ( ) => {
347347 const cb = ( ) => { }
348- const service = createMockService ( [ {
348+ const service = await createMockService ( [ {
349349 id : 'test' ,
350350 apply : api => {
351351 api . configureDevServer ( cb )
@@ -354,17 +354,17 @@ test('api: configureDevServer', () => {
354354 expect ( service . devServerConfigFns ) . toContain ( cb )
355355} )
356356
357- test ( 'api: resolve' , ( ) => {
358- createMockService ( [ {
357+ test ( 'api: resolve' , async ( ) => {
358+ await createMockService ( [ {
359359 id : 'test' ,
360360 apply : api => {
361361 expect ( api . resolve ( 'foo.js' ) ) . toBe ( path . resolve ( '/' , 'foo.js' ) )
362362 }
363363 } ] )
364364} )
365365
366- test ( 'api: hasPlugin' , ( ) => {
367- createMockService ( [
366+ test ( 'api: hasPlugin' , async ( ) => {
367+ await createMockService ( [
368368 {
369369 id : 'vue-cli-plugin-foo' ,
370370 apply : api => {
0 commit comments