@@ -1012,6 +1012,7 @@ describe.each([
10121012 instance = middleware ( compiler ) ;
10131013
10141014 app = framework ( ) ;
1015+ // eslint-disable-next-line no-shadow
10151016 app . use ( ( req , res , next ) => {
10161017 // Express API
10171018 if ( res . set ) {
@@ -2133,6 +2134,7 @@ describe.each([
21332134 app = framework ( ) ;
21342135 app . use ( instance ) ;
21352136
2137+ // eslint-disable-next-line no-shadow
21362138 app . use ( "/file.jpg" , ( req , res ) => {
21372139 // Express API
21382140 if ( res . send ) {
@@ -2762,6 +2764,7 @@ describe.each([
27622764 } ) ;
27632765
27642766 it ( 'should return the "200" code for the "GET" request to path not in outputFileSystem but not return headers' , async ( ) => {
2767+ // eslint-disable-next-line no-shadow
27652768 app . use ( "/file.jpg" , ( req , res ) => {
27662769 // Express API
27672770 if ( res . send ) {
@@ -2779,6 +2782,62 @@ describe.each([
27792782 expect ( res . headers [ "X-nonsense-2" ] ) . toBeUndefined ( ) ;
27802783 } ) ;
27812784 } ) ;
2785+
2786+ describe ( "works with array of objects" , ( ) => {
2787+ beforeEach ( ( done ) => {
2788+ const compiler = getCompiler ( webpackConfig ) ;
2789+
2790+ instance = middleware ( compiler , {
2791+ headers : [
2792+ {
2793+ key : "X-Foo" ,
2794+ value : "value1" ,
2795+ } ,
2796+ {
2797+ key : "X-Bar" ,
2798+ value : "value2" ,
2799+ } ,
2800+ ] ,
2801+ } ) ;
2802+
2803+ app = framework ( ) ;
2804+ app . use ( instance ) ;
2805+
2806+ listen = listenShorthand ( done ) ;
2807+
2808+ req = request ( app ) ;
2809+ } ) ;
2810+
2811+ afterEach ( close ) ;
2812+
2813+ it ( 'should return the "200" code for the "GET" request to the bundle file and return headers' , async ( ) => {
2814+ const response = await req . get ( `/bundle.js` ) ;
2815+
2816+ expect ( response . statusCode ) . toEqual ( 200 ) ;
2817+ expect ( response . headers [ "x-foo" ] ) . toEqual ( "value1" ) ;
2818+ expect ( response . headers [ "x-bar" ] ) . toEqual ( "value2" ) ;
2819+ } ) ;
2820+
2821+ it ( 'should return the "200" code for the "GET" request to path not in outputFileSystem but not return headers' , async ( ) => {
2822+ // eslint-disable-next-line no-shadow
2823+ app . use ( "/file.jpg" , ( req , res ) => {
2824+ // Express API
2825+ if ( res . send ) {
2826+ res . send ( "welcome" ) ;
2827+ }
2828+ // Connect API
2829+ else {
2830+ res . end ( "welcome" ) ;
2831+ }
2832+ } ) ;
2833+
2834+ const res = await request ( app ) . get ( "/file.jpg" ) ;
2835+ expect ( res . statusCode ) . toEqual ( 200 ) ;
2836+ expect ( res . headers [ "x-foo" ] ) . toBeUndefined ( ) ;
2837+ expect ( res . headers [ "x-bar" ] ) . toBeUndefined ( ) ;
2838+ } ) ;
2839+ } ) ;
2840+
27822841 describe ( "works with function" , ( ) => {
27832842 beforeEach ( ( done ) => {
27842843 const compiler = getCompiler ( webpackConfig ) ;
@@ -2808,6 +2867,7 @@ describe.each([
28082867 } ) ;
28092868
28102869 it ( 'should return the "200" code for the "GET" request to path not in outputFileSystem but not return headers' , async ( ) => {
2870+ // eslint-disable-next-line no-shadow
28112871 app . use ( "/file.jpg" , ( req , res ) => {
28122872 // Express API
28132873 if ( res . send ) {
@@ -2826,12 +2886,67 @@ describe.each([
28262886 } ) ;
28272887 } ) ;
28282888
2889+ describe ( "works with function returning an array" , ( ) => {
2890+ beforeEach ( ( done ) => {
2891+ const compiler = getCompiler ( webpackConfig ) ;
2892+
2893+ instance = middleware ( compiler , {
2894+ headers : ( ) => [
2895+ {
2896+ key : "X-Foo" ,
2897+ value : "value1" ,
2898+ } ,
2899+ {
2900+ key : "X-Bar" ,
2901+ value : "value2" ,
2902+ } ,
2903+ ] ,
2904+ } ) ;
2905+
2906+ app = framework ( ) ;
2907+ app . use ( instance ) ;
2908+
2909+ listen = listenShorthand ( done ) ;
2910+
2911+ req = request ( app ) ;
2912+ } ) ;
2913+
2914+ afterEach ( close ) ;
2915+
2916+ it ( 'should return the "200" code for the "GET" request to the bundle file and return headers' , async ( ) => {
2917+ const response = await req . get ( `/bundle.js` ) ;
2918+
2919+ expect ( response . statusCode ) . toEqual ( 200 ) ;
2920+ expect ( response . headers [ "x-foo" ] ) . toEqual ( "value1" ) ;
2921+ expect ( response . headers [ "x-bar" ] ) . toEqual ( "value2" ) ;
2922+ } ) ;
2923+
2924+ it ( 'should return the "200" code for the "GET" request to path not in outputFileSystem but not return headers' , async ( ) => {
2925+ // eslint-disable-next-line no-shadow
2926+ app . use ( "/file.jpg" , ( req , res ) => {
2927+ // Express API
2928+ if ( res . send ) {
2929+ res . send ( "welcome" ) ;
2930+ }
2931+ // Connect API
2932+ else {
2933+ res . end ( "welcome" ) ;
2934+ }
2935+ } ) ;
2936+
2937+ const res = await req . get ( "/file.jpg" ) ;
2938+ expect ( res . statusCode ) . toEqual ( 200 ) ;
2939+ expect ( res . headers [ "x-foo" ] ) . toBeUndefined ( ) ;
2940+ expect ( res . headers [ "x-bar" ] ) . toBeUndefined ( ) ;
2941+ } ) ;
2942+ } ) ;
2943+
28292944 describe ( "works with headers function with params" , ( ) => {
28302945 beforeEach ( ( done ) => {
28312946 const compiler = getCompiler ( webpackConfig ) ;
28322947
28332948 instance = middleware ( compiler , {
2834- // eslint-disable-next-line no-unused-vars
2949+ // eslint-disable-next-line no-unused-vars, no-shadow
28352950 headers : ( req , res , context ) => {
28362951 res . setHeader ( "X-nonsense-1" , "yes" ) ;
28372952 res . setHeader ( "X-nonsense-2" , "no" ) ;
@@ -2857,6 +2972,7 @@ describe.each([
28572972 } ) ;
28582973
28592974 it ( 'should return the "200" code for the "GET" request to path not in outputFileSystem but not return headers' , async ( ) => {
2975+ // eslint-disable-next-line no-shadow
28602976 app . use ( "/file.jpg" , ( req , res ) => {
28612977 // Express API
28622978 if ( res . send ) {
@@ -2934,6 +3050,7 @@ describe.each([
29343050
29353051 app = framework ( ) ;
29363052 app . use ( instance ) ;
3053+ // eslint-disable-next-line no-shadow
29373054 app . use ( ( req , res ) => {
29383055 // eslint-disable-next-line prefer-destructuring
29393056 locals = res . locals ;
0 commit comments