@@ -720,6 +720,245 @@ describe('onPostBuild', () => {
720
720
} ,
721
721
] )
722
722
} )
723
+
724
+ test ( 'appends headers to existing headers in the Netlify configuration' , async ( ) => {
725
+ await moveNextDist ( )
726
+
727
+ netlifyConfig . headers = [
728
+ {
729
+ for : '/' ,
730
+ values : {
731
+ 'x-existing-header-in-configuration' : 'existing header in configuration value' ,
732
+ } ,
733
+ } ,
734
+ ]
735
+
736
+ const show = jest . fn ( )
737
+
738
+ await plugin . onPostBuild ( {
739
+ ...defaultArgs ,
740
+
741
+ utils : { ...defaultArgs . utils , status : { show } , functions : { list : jest . fn ( ) . mockResolvedValue ( [ ] ) } } ,
742
+ } )
743
+
744
+ expect ( netlifyConfig . headers ) . toEqual ( [
745
+ {
746
+ for : '/' ,
747
+ values : {
748
+ 'x-existing-header-in-configuration' : 'existing header in configuration value' ,
749
+ } ,
750
+ } ,
751
+ {
752
+ for : '/' ,
753
+ values : {
754
+ 'x-custom-header' : 'my custom header value' ,
755
+ } ,
756
+ } ,
757
+ {
758
+ for : '/en/' ,
759
+ values : {
760
+ 'x-custom-header' : 'my custom header value' ,
761
+ } ,
762
+ } ,
763
+ {
764
+ for : '/es/' ,
765
+ values : {
766
+ 'x-custom-header' : 'my custom header value' ,
767
+ } ,
768
+ } ,
769
+ {
770
+ for : '/fr/' ,
771
+ values : {
772
+ 'x-custom-header' : 'my custom header value' ,
773
+ } ,
774
+ } ,
775
+ {
776
+ for : '/api/*' ,
777
+ values : {
778
+ 'x-custom-api-header' : 'my custom api header value' ,
779
+ } ,
780
+ } ,
781
+ {
782
+ for : '/en/api/*' ,
783
+ values : {
784
+ 'x-custom-api-header' : 'my custom api header value' ,
785
+ } ,
786
+ } ,
787
+ {
788
+ for : '/es/api/*' ,
789
+ values : {
790
+ 'x-custom-api-header' : 'my custom api header value' ,
791
+ } ,
792
+ } ,
793
+ {
794
+ for : '/fr/api/*' ,
795
+ values : {
796
+ 'x-custom-api-header' : 'my custom api header value' ,
797
+ } ,
798
+ } ,
799
+ {
800
+ for : '/*' ,
801
+ values : {
802
+ 'x-custom-header-for-everything' : 'my custom header for everything value' ,
803
+ } ,
804
+ } ,
805
+ {
806
+ for : '/en/*' ,
807
+ values : {
808
+ 'x-custom-header-for-everything' : 'my custom header for everything value' ,
809
+ } ,
810
+ } ,
811
+ {
812
+ for : '/es/*' ,
813
+ values : {
814
+ 'x-custom-header-for-everything' : 'my custom header for everything value' ,
815
+ } ,
816
+ } ,
817
+ {
818
+ for : '/fr/*' ,
819
+ values : {
820
+ 'x-custom-header-for-everything' : 'my custom header for everything value' ,
821
+ } ,
822
+ } ,
823
+ ] )
824
+ } )
825
+
826
+ test ( 'appends headers to existing headers in the Netlify configuration' , async ( ) => {
827
+ await moveNextDist ( )
828
+
829
+ netlifyConfig . headers = [
830
+ {
831
+ for : '/' ,
832
+ values : {
833
+ 'x-existing-header-in-configuration' : 'existing header in configuration value' ,
834
+ } ,
835
+ } ,
836
+ ]
837
+
838
+ const show = jest . fn ( )
839
+
840
+ await plugin . onPostBuild ( {
841
+ ...defaultArgs ,
842
+
843
+ utils : { ...defaultArgs . utils , status : { show } , functions : { list : jest . fn ( ) . mockResolvedValue ( [ ] ) } } ,
844
+ } )
845
+
846
+ expect ( netlifyConfig . headers ) . toEqual ( [
847
+ {
848
+ for : '/' ,
849
+ values : {
850
+ 'x-existing-header-in-configuration' : 'existing header in configuration value' ,
851
+ } ,
852
+ } ,
853
+ {
854
+ for : '/' ,
855
+ values : {
856
+ 'x-custom-header' : 'my custom header value' ,
857
+ } ,
858
+ } ,
859
+ {
860
+ for : '/en/' ,
861
+ values : {
862
+ 'x-custom-header' : 'my custom header value' ,
863
+ } ,
864
+ } ,
865
+ {
866
+ for : '/es/' ,
867
+ values : {
868
+ 'x-custom-header' : 'my custom header value' ,
869
+ } ,
870
+ } ,
871
+ {
872
+ for : '/fr/' ,
873
+ values : {
874
+ 'x-custom-header' : 'my custom header value' ,
875
+ } ,
876
+ } ,
877
+ {
878
+ for : '/api/*' ,
879
+ values : {
880
+ 'x-custom-api-header' : 'my custom api header value' ,
881
+ } ,
882
+ } ,
883
+ {
884
+ for : '/en/api/*' ,
885
+ values : {
886
+ 'x-custom-api-header' : 'my custom api header value' ,
887
+ } ,
888
+ } ,
889
+ {
890
+ for : '/es/api/*' ,
891
+ values : {
892
+ 'x-custom-api-header' : 'my custom api header value' ,
893
+ } ,
894
+ } ,
895
+ {
896
+ for : '/fr/api/*' ,
897
+ values : {
898
+ 'x-custom-api-header' : 'my custom api header value' ,
899
+ } ,
900
+ } ,
901
+ {
902
+ for : '/*' ,
903
+ values : {
904
+ 'x-custom-header-for-everything' : 'my custom header for everything value' ,
905
+ } ,
906
+ } ,
907
+ {
908
+ for : '/en/*' ,
909
+ values : {
910
+ 'x-custom-header-for-everything' : 'my custom header for everything value' ,
911
+ } ,
912
+ } ,
913
+ {
914
+ for : '/es/*' ,
915
+ values : {
916
+ 'x-custom-header-for-everything' : 'my custom header for everything value' ,
917
+ } ,
918
+ } ,
919
+ {
920
+ for : '/fr/*' ,
921
+ values : {
922
+ 'x-custom-header-for-everything' : 'my custom header for everything value' ,
923
+ } ,
924
+ } ,
925
+ ] )
926
+ } )
927
+
928
+ test ( 'appends no additional headers in the Netlify configuration when none are in the routes manifest' , async ( ) => {
929
+ await moveNextDist ( )
930
+
931
+ netlifyConfig . headers = [
932
+ {
933
+ for : '/' ,
934
+ values : {
935
+ 'x-existing-header-in-configuration' : 'existing header in configuration value' ,
936
+ } ,
937
+ } ,
938
+ ]
939
+
940
+ const show = jest . fn ( )
941
+
942
+ const manifestPath = path . resolve ( '.next/routes-manifest.json' )
943
+ const routesManifest = await readJson ( manifestPath )
944
+ delete routesManifest . headers
945
+ await writeJSON ( manifestPath , routesManifest )
946
+
947
+ await plugin . onPostBuild ( {
948
+ ...defaultArgs ,
949
+
950
+ utils : { ...defaultArgs . utils , status : { show } , functions : { list : jest . fn ( ) . mockResolvedValue ( [ ] ) } } ,
951
+ } )
952
+
953
+ expect ( netlifyConfig . headers ) . toEqual ( [
954
+ {
955
+ for : '/' ,
956
+ values : {
957
+ 'x-existing-header-in-configuration' : 'existing header in configuration value' ,
958
+ } ,
959
+ } ,
960
+ ] )
961
+ } )
723
962
} )
724
963
725
964
describe ( 'utility functions' , ( ) => {
0 commit comments