@@ -1012,6 +1012,7 @@ describe.each([
1012
1012
instance = middleware ( compiler ) ;
1013
1013
1014
1014
app = framework ( ) ;
1015
+ // eslint-disable-next-line no-shadow
1015
1016
app . use ( ( req , res , next ) => {
1016
1017
// Express API
1017
1018
if ( res . set ) {
@@ -2133,6 +2134,7 @@ describe.each([
2133
2134
app = framework ( ) ;
2134
2135
app . use ( instance ) ;
2135
2136
2137
+ // eslint-disable-next-line no-shadow
2136
2138
app . use ( "/file.jpg" , ( req , res ) => {
2137
2139
// Express API
2138
2140
if ( res . send ) {
@@ -2762,6 +2764,7 @@ describe.each([
2762
2764
} ) ;
2763
2765
2764
2766
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
2765
2768
app . use ( "/file.jpg" , ( req , res ) => {
2766
2769
// Express API
2767
2770
if ( res . send ) {
@@ -2779,6 +2782,62 @@ describe.each([
2779
2782
expect ( res . headers [ "X-nonsense-2" ] ) . toBeUndefined ( ) ;
2780
2783
} ) ;
2781
2784
} ) ;
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
+
2782
2841
describe ( "works with function" , ( ) => {
2783
2842
beforeEach ( ( done ) => {
2784
2843
const compiler = getCompiler ( webpackConfig ) ;
@@ -2808,6 +2867,7 @@ describe.each([
2808
2867
} ) ;
2809
2868
2810
2869
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
2811
2871
app . use ( "/file.jpg" , ( req , res ) => {
2812
2872
// Express API
2813
2873
if ( res . send ) {
@@ -2826,12 +2886,67 @@ describe.each([
2826
2886
} ) ;
2827
2887
} ) ;
2828
2888
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
+
2829
2944
describe ( "works with headers function with params" , ( ) => {
2830
2945
beforeEach ( ( done ) => {
2831
2946
const compiler = getCompiler ( webpackConfig ) ;
2832
2947
2833
2948
instance = middleware ( compiler , {
2834
- // eslint-disable-next-line no-unused-vars
2949
+ // eslint-disable-next-line no-unused-vars, no-shadow
2835
2950
headers : ( req , res , context ) => {
2836
2951
res . setHeader ( "X-nonsense-1" , "yes" ) ;
2837
2952
res . setHeader ( "X-nonsense-2" , "no" ) ;
@@ -2857,6 +2972,7 @@ describe.each([
2857
2972
} ) ;
2858
2973
2859
2974
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
2860
2976
app . use ( "/file.jpg" , ( req , res ) => {
2861
2977
// Express API
2862
2978
if ( res . send ) {
@@ -2934,6 +3050,7 @@ describe.each([
2934
3050
2935
3051
app = framework ( ) ;
2936
3052
app . use ( instance ) ;
3053
+ // eslint-disable-next-line no-shadow
2937
3054
app . use ( ( req , res ) => {
2938
3055
// eslint-disable-next-line prefer-destructuring
2939
3056
locals = res . locals ;
0 commit comments