@@ -2392,45 +2392,137 @@ 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 : ( ) => {
2443
+ return { 'X-nonsense-1' : 'yes' , 'X-nonsense-2' : 'no' } ;
2444
+ } ,
2445
+ } ) ;
2409
2446
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 ) ;
2447
+ app = framework ( ) ;
2448
+ app . use ( instance ) ;
2449
+
2450
+ listen = listenShorthand ( done ) ;
2451
+ } ) ;
2452
+
2453
+ afterEach ( close ) ;
2454
+
2455
+ it ( 'should return the "200" code for the "GET" request to the bundle file and return headers' , ( done ) => {
2456
+ request ( app )
2457
+ . get ( '/bundle.js' )
2458
+ . expect ( 'X-nonsense-1' , 'yes' )
2459
+ . expect ( 'X-nonsense-2' , 'no' )
2460
+ . expect ( 200 , done ) ;
2461
+ } ) ;
2462
+
2463
+ it ( 'should return the "200" code for the "GET" request to path not in outputFileSystem but not return headers' , async ( ) => {
2464
+ app . use ( '/file.jpg' , ( req , res ) => {
2465
+ // Express API
2466
+ if ( res . send ) {
2467
+ res . send ( 'welcome' ) ;
2468
+ }
2469
+ // Connect API
2470
+ else {
2471
+ res . end ( 'welcome' ) ;
2472
+ }
2473
+ } ) ;
2474
+
2475
+ const res = await request ( app ) . get ( '/file.jpg' ) ;
2476
+ expect ( res . statusCode ) . toEqual ( 200 ) ;
2477
+ expect ( res . headers [ 'X-nonsense-1' ] ) . toBeUndefined ( ) ;
2478
+ expect ( res . headers [ 'X-nonsense-2' ] ) . toBeUndefined ( ) ;
2479
+ } ) ;
2416
2480
} ) ;
2481
+ describe ( 'works with headers function with params' , ( ) => {
2482
+ beforeEach ( ( done ) => {
2483
+ const compiler = getCompiler ( webpackConfig ) ;
2417
2484
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
- }
2485
+ instance = middleware ( compiler , {
2486
+ // eslint-disable-next-line no-unused-vars
2487
+ headers : ( req , res , context ) => {
2488
+ res . setHeader ( 'X-nonsense-1' , 'yes' ) ;
2489
+ res . setHeader ( 'X-nonsense-2' , 'no' ) ;
2490
+ } ,
2491
+ } ) ;
2492
+
2493
+ app = framework ( ) ;
2494
+ app . use ( instance ) ;
2495
+
2496
+ listen = listenShorthand ( done ) ;
2428
2497
} ) ;
2429
2498
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 ( ) ;
2499
+ afterEach ( close ) ;
2500
+
2501
+ it ( 'should return the "200" code for the "GET" request to the bundle file and return headers' , ( done ) => {
2502
+ request ( app )
2503
+ . get ( '/bundle.js' )
2504
+ . expect ( 'X-nonsense-1' , 'yes' )
2505
+ . expect ( 'X-nonsense-2' , 'no' )
2506
+ . expect ( 200 , done ) ;
2507
+ } ) ;
2508
+
2509
+ it ( 'should return the "200" code for the "GET" request to path not in outputFileSystem but not return headers' , async ( ) => {
2510
+ app . use ( '/file.jpg' , ( req , res ) => {
2511
+ // Express API
2512
+ if ( res . send ) {
2513
+ res . send ( 'welcome' ) ;
2514
+ }
2515
+ // Connect API
2516
+ else {
2517
+ res . end ( 'welcome' ) ;
2518
+ }
2519
+ } ) ;
2520
+
2521
+ const res = await request ( app ) . get ( '/file.jpg' ) ;
2522
+ expect ( res . statusCode ) . toEqual ( 200 ) ;
2523
+ expect ( res . headers [ 'X-nonsense-1' ] ) . toBeUndefined ( ) ;
2524
+ expect ( res . headers [ 'X-nonsense-2' ] ) . toBeUndefined ( ) ;
2525
+ } ) ;
2434
2526
} ) ;
2435
2527
} ) ;
2436
2528
0 commit comments