@@ -2392,45 +2392,134 @@ describe.each([
2392
2392
} ) ;
2393
2393
2394
2394
describe ( 'headers option' , ( ) => {
2395
- beforeEach ( ( done ) => {
2396
- const compiler = getCompiler ( webpackConfig ) ;
2395
+ describe ( 'works with object' , ( ) => {
2396
+ beforeEach ( ( done ) => {
2397
+ const compiler = getCompiler ( webpackConfig ) ;
2397
2398
2398
- instance = middleware ( compiler , {
2399
- headers : { 'X-nonsense-1' : 'yes' , 'X-nonsense-2' : 'no' } ,
2399
+ instance = middleware ( compiler , {
2400
+ headers : { 'X-nonsense-1' : 'yes' , 'X-nonsense-2' : 'no' } ,
2401
+ } ) ;
2402
+
2403
+ app = framework ( ) ;
2404
+ app . use ( instance ) ;
2405
+
2406
+ listen = listenShorthand ( done ) ;
2400
2407
} ) ;
2401
2408
2402
- app = framework ( ) ;
2403
- app . use ( instance ) ;
2409
+ afterEach ( close ) ;
2404
2410
2405
- listen = listenShorthand ( done ) ;
2411
+ it ( 'should return the "200" code for the "GET" request to the bundle file and return headers' , ( done ) => {
2412
+ request ( app )
2413
+ . get ( '/bundle.js' )
2414
+ . expect ( 'X-nonsense-1' , 'yes' )
2415
+ . expect ( 'X-nonsense-2' , 'no' )
2416
+ . expect ( 200 , done ) ;
2417
+ } ) ;
2418
+
2419
+ it ( 'should return the "200" code for the "GET" request to path not in outputFileSystem but not return headers' , async ( ) => {
2420
+ app . use ( '/file.jpg' , ( req , res ) => {
2421
+ // Express API
2422
+ if ( res . send ) {
2423
+ res . send ( 'welcome' ) ;
2424
+ }
2425
+ // Connect API
2426
+ else {
2427
+ res . end ( 'welcome' ) ;
2428
+ }
2429
+ } ) ;
2430
+
2431
+ const res = await request ( app ) . get ( '/file.jpg' ) ;
2432
+ expect ( res . statusCode ) . toEqual ( 200 ) ;
2433
+ expect ( res . headers [ 'X-nonsense-1' ] ) . toBeUndefined ( ) ;
2434
+ expect ( res . headers [ 'X-nonsense-2' ] ) . toBeUndefined ( ) ;
2435
+ } ) ;
2406
2436
} ) ;
2437
+ describe ( 'works with function' , ( ) => {
2438
+ beforeEach ( ( done ) => {
2439
+ const compiler = getCompiler ( webpackConfig ) ;
2407
2440
2408
- afterEach ( close ) ;
2441
+ instance = middleware ( compiler , {
2442
+ headers : ( ) => ( { 'X-nonsense-1' : 'yes' , 'X-nonsense-2' : 'no' } ) ,
2443
+ } ) ;
2409
2444
2410
- it ( 'should return the "200" code for the "GET" request to the bundle file and return headers' , ( done ) => {
2411
- request ( app )
2412
- . get ( '/bundle.js' )
2413
- . expect ( 'X-nonsense-1' , 'yes' )
2414
- . expect ( 'X-nonsense-2' , 'no' )
2415
- . expect ( 200 , done ) ;
2445
+ app = framework ( ) ;
2446
+ app . use ( instance ) ;
2447
+
2448
+ listen = listenShorthand ( done ) ;
2449
+ } ) ;
2450
+
2451
+ afterEach ( close ) ;
2452
+
2453
+ it ( 'should return the "200" code for the "GET" request to the bundle file and return headers' , ( done ) => {
2454
+ request ( app )
2455
+ . get ( '/bundle.js' )
2456
+ . expect ( 'X-nonsense-1' , 'yes' )
2457
+ . expect ( 'X-nonsense-2' , 'no' )
2458
+ . expect ( 200 , done ) ;
2459
+ } ) ;
2460
+
2461
+ it ( 'should return the "200" code for the "GET" request to path not in outputFileSystem but not return headers' , async ( ) => {
2462
+ app . use ( '/file.jpg' , ( req , res ) => {
2463
+ // Express API
2464
+ if ( res . send ) {
2465
+ res . send ( 'welcome' ) ;
2466
+ }
2467
+ // Connect API
2468
+ else {
2469
+ res . end ( 'welcome' ) ;
2470
+ }
2471
+ } ) ;
2472
+
2473
+ const res = await request ( app ) . get ( '/file.jpg' ) ;
2474
+ expect ( res . statusCode ) . toEqual ( 200 ) ;
2475
+ expect ( res . headers [ 'X-nonsense-1' ] ) . toBeUndefined ( ) ;
2476
+ expect ( res . headers [ 'X-nonsense-2' ] ) . toBeUndefined ( ) ;
2477
+ } ) ;
2416
2478
} ) ;
2479
+ describe ( 'works with headers function with params' , ( ) => {
2480
+ beforeEach ( ( done ) => {
2481
+ const compiler = getCompiler ( webpackConfig ) ;
2417
2482
2418
- it ( 'should return the "200" code for the "GET" request to path not in outputFileSystem but not return headers' , async ( ) => {
2419
- app . use ( '/file.jpg' , ( req , res ) => {
2420
- // Express API
2421
- if ( res . send ) {
2422
- res . send ( 'welcome' ) ;
2423
- }
2424
- // Connect API
2425
- else {
2426
- res . end ( 'welcome' ) ;
2427
- }
2483
+ instance = middleware ( compiler , {
2484
+ headers : ( req , res , context ) => {
2485
+ res . setHeader ( 'X-nonsense-1' , 'yes' ) ;
2486
+ res . setHeader ( 'X-nonsense-2' , 'no' ) ;
2487
+ } ,
2488
+ } ) ;
2489
+
2490
+ app = framework ( ) ;
2491
+ app . use ( instance ) ;
2492
+
2493
+ listen = listenShorthand ( done ) ;
2428
2494
} ) ;
2429
2495
2430
- const res = await request ( app ) . get ( '/file.jpg' ) ;
2431
- expect ( res . statusCode ) . toEqual ( 200 ) ;
2432
- expect ( res . headers [ 'X-nonsense-1' ] ) . toBeUndefined ( ) ;
2433
- expect ( res . headers [ 'X-nonsense-2' ] ) . toBeUndefined ( ) ;
2496
+ afterEach ( close ) ;
2497
+
2498
+ it ( 'should return the "200" code for the "GET" request to the bundle file and return headers' , ( done ) => {
2499
+ request ( app )
2500
+ . get ( '/bundle.js' )
2501
+ . expect ( 'X-nonsense-1' , 'yes' )
2502
+ . expect ( 'X-nonsense-2' , 'no' )
2503
+ . expect ( 200 , done ) ;
2504
+ } ) ;
2505
+
2506
+ it ( 'should return the "200" code for the "GET" request to path not in outputFileSystem but not return headers' , async ( ) => {
2507
+ app . use ( '/file.jpg' , ( req , res ) => {
2508
+ // Express API
2509
+ if ( res . send ) {
2510
+ res . send ( 'welcome' ) ;
2511
+ }
2512
+ // Connect API
2513
+ else {
2514
+ res . end ( 'welcome' ) ;
2515
+ }
2516
+ } ) ;
2517
+
2518
+ const res = await request ( app ) . get ( '/file.jpg' ) ;
2519
+ expect ( res . statusCode ) . toEqual ( 200 ) ;
2520
+ expect ( res . headers [ 'X-nonsense-1' ] ) . toBeUndefined ( ) ;
2521
+ expect ( res . headers [ 'X-nonsense-2' ] ) . toBeUndefined ( ) ;
2522
+ } ) ;
2434
2523
} ) ;
2435
2524
} ) ;
2436
2525
0 commit comments