@@ -2373,6 +2373,84 @@ describe.each([
2373
2373
} ) ;
2374
2374
} ) ;
2375
2375
2376
+ describe ( 'should work with "true" value when the `output.clean` is `true`' , ( ) => {
2377
+ const outputPath = path . resolve (
2378
+ __dirname ,
2379
+ "./outputs/write-to-disk-true-with-clean"
2380
+ ) ;
2381
+
2382
+ let compiler ;
2383
+
2384
+ beforeAll ( ( done ) => {
2385
+ compiler = getCompiler ( {
2386
+ ...webpackConfig ,
2387
+ output : {
2388
+ clean : true ,
2389
+ filename : "bundle.js" ,
2390
+ path : outputPath ,
2391
+ } ,
2392
+ } ) ;
2393
+
2394
+ instance = middleware ( compiler , { writeToDisk : true } ) ;
2395
+
2396
+ fs . mkdirSync ( outputPath , {
2397
+ recursive : true ,
2398
+ } ) ;
2399
+ fs . writeFileSync ( path . resolve ( outputPath , "test.json" ) , "{}" ) ;
2400
+
2401
+ app = framework ( ) ;
2402
+ app . use ( instance ) ;
2403
+
2404
+ listen = listenShorthand ( done ) ;
2405
+
2406
+ req = request ( app ) ;
2407
+ } ) ;
2408
+
2409
+ afterAll ( ( done ) => {
2410
+ del . sync ( outputPath ) ;
2411
+
2412
+ close ( done ) ;
2413
+ } ) ;
2414
+
2415
+ it ( "should find the bundle file on disk" , ( done ) => {
2416
+ request ( app )
2417
+ . get ( "/bundle.js" )
2418
+ . expect ( 200 , ( error ) => {
2419
+ if ( error ) {
2420
+ return done ( error ) ;
2421
+ }
2422
+
2423
+ const bundlePath = path . resolve ( outputPath , "bundle.js" ) ;
2424
+
2425
+ expect ( fs . existsSync ( path . resolve ( outputPath , "test.json" ) ) ) . toBe (
2426
+ false
2427
+ ) ;
2428
+
2429
+ expect (
2430
+ compiler . hooks . assetEmitted . taps . filter (
2431
+ ( hook ) => hook . name === "DevMiddleware"
2432
+ ) . length
2433
+ ) . toBe ( 1 ) ;
2434
+ expect ( fs . existsSync ( bundlePath ) ) . toBe ( true ) ;
2435
+
2436
+ instance . invalidate ( ) ;
2437
+
2438
+ return compiler . hooks . done . tap (
2439
+ "DevMiddlewareWriteToDiskTest" ,
2440
+ ( ) => {
2441
+ expect (
2442
+ compiler . hooks . assetEmitted . taps . filter (
2443
+ ( hook ) => hook . name === "DevMiddleware"
2444
+ ) . length
2445
+ ) . toBe ( 1 ) ;
2446
+
2447
+ done ( ) ;
2448
+ }
2449
+ ) ;
2450
+ } ) ;
2451
+ } ) ;
2452
+ } ) ;
2453
+
2376
2454
describe ( 'should work with "false" value' , ( ) => {
2377
2455
let compiler ;
2378
2456
0 commit comments