@@ -196,15 +196,12 @@ test.serial('#createServiceWorker()', async t => {
196
196
plugin . configure ( compiler , compilation ) ;
197
197
return callback ( ) ;
198
198
} ) ;
199
-
200
199
await runCompiler ( compiler ) ;
201
-
202
200
t . truthy ( await plugin . createServiceWorker ( ) , 'generate something' ) ;
203
201
} ) ;
204
202
205
- test . serial ( '#writeServiceWorker(serviceWorker, compiler, callback )' , async t => {
203
+ test . serial ( '#writeServiceWorker(serviceWorker, compiler)' , async t => {
206
204
t . plan ( 2 ) ;
207
-
208
205
const filepath = path . resolve ( __dirname , 'tmp/service-worker.js' ) ;
209
206
const compiler = webpack ( webpackConfig ( ) ) ;
210
207
const plugin = new SWPrecacheWebpackPlugin ( { filepath} ) ;
@@ -215,10 +212,12 @@ test.serial('#writeServiceWorker(serviceWorker, compiler, callback)', async t =>
215
212
plugin . apply ( compiler ) ;
216
213
217
214
compiler . plugin ( 'after-emit' , ( compilation , callback ) => {
218
- plugin . writeServiceWorker ( serviceWorker , compiler , callback ) ;
215
+ plugin . writeServiceWorker ( serviceWorker , compiler )
216
+ . then ( ( ) => callback ( ) )
217
+ . catch ( err => callback ( err ) ) ;
219
218
} ) ;
220
- await runCompiler ( compiler ) ;
221
219
220
+ await runCompiler ( compiler ) ;
222
221
t . truthy ( await fsExists ( filepath ) , 'service-worker should exist' ) ;
223
222
224
223
} ) ;
@@ -257,7 +256,7 @@ test.serial('importScripts[<index>] should support entry point & dynamically imp
257
256
'some-script-path.js' ,
258
257
{ filename : 'some-script-path.[hash].js' } ,
259
258
{ chunkName : 'sw' } ,
260
- { chunkName : 'service-worker-imported-script-2' }
259
+ { chunkName : 'service-worker-imported-script-2' } ,
261
260
] ,
262
261
} ) ;
263
262
@@ -313,9 +312,11 @@ test.serial('should keep [hash] in importScripts after configuring SW', async t
313
312
const plugin = new SWPrecacheWebpackPlugin ( { filepath, importScripts : [ 'some_sw-[hash].js' ] } ) ;
314
313
315
314
plugin . apply ( compiler ) ;
316
- compiler . plugin ( 'after-emit' , ( compilation ) => {
315
+ compiler . plugin ( 'after-emit' , ( compilation , callback ) => {
317
316
plugin . configure ( compiler , compilation ) ;
317
+ callback ( ) ;
318
318
} ) ;
319
+
319
320
await runCompiler ( compiler ) ;
320
321
321
322
t . truthy ( plugin . options . importScripts [ 0 ] === 'some_sw-[hash].js' , 'hash should be preserve after writing the sw' ) ;
@@ -329,8 +330,9 @@ test.serial('should not modify importScripts value when no [hash] is provided',
329
330
const plugin = new SWPrecacheWebpackPlugin ( { filepath, importScripts : [ 'some_script.js' ] } ) ;
330
331
331
332
plugin . apply ( compiler ) ;
332
- compiler . plugin ( 'after-emit' , ( compilation ) => {
333
+ compiler . plugin ( 'after-emit' , ( compilation , callback ) => {
333
334
plugin . configure ( compiler , compilation ) ;
335
+ callback ( ) ;
334
336
} ) ;
335
337
await runCompiler ( compiler ) ;
336
338
0 commit comments