@@ -138,7 +138,7 @@ const useFixture = async function (fixtureName) {
138
138
await cpy ( '**' , process . cwd ( ) , { cwd : fixtureDir , parents : true , overwrite : true , dot : true } )
139
139
}
140
140
141
- const netlifyConfig = { build : { command : 'npm run build' } , functions : { } , redirects : [ ] }
141
+ const netlifyConfig = { build : { command : 'npm run build' } , functions : { } , redirects : [ ] , headers : [ ] }
142
142
const defaultArgs = {
143
143
netlifyConfig,
144
144
utils,
@@ -159,6 +159,7 @@ beforeEach(async () => {
159
159
netlifyConfig . build . environment = { }
160
160
161
161
netlifyConfig . redirects = [ ]
162
+ netlifyConfig . headers = [ ]
162
163
netlifyConfig . functions [ HANDLER_FUNCTION_NAME ] && ( netlifyConfig . functions [ HANDLER_FUNCTION_NAME ] . included_files = [ ] )
163
164
netlifyConfig . functions [ ODB_FUNCTION_NAME ] && ( netlifyConfig . functions [ ODB_FUNCTION_NAME ] . included_files = [ ] )
164
165
await useFixture ( 'serverless_next_config' )
@@ -632,6 +633,93 @@ describe('onPostBuild', () => {
632
633
} ,
633
634
] )
634
635
} )
636
+
637
+ test ( 'adds headers to Netlify configuration' , async ( ) => {
638
+ await moveNextDist ( )
639
+
640
+ const show = jest . fn ( )
641
+
642
+ await plugin . onPostBuild ( {
643
+ ...defaultArgs ,
644
+
645
+ utils : { ...defaultArgs . utils , status : { show } , functions : { list : jest . fn ( ) . mockResolvedValue ( [ ] ) } } ,
646
+ } )
647
+
648
+ expect ( netlifyConfig . headers ) . toEqual ( [
649
+ {
650
+ for : '/' ,
651
+ values : {
652
+ 'x-custom-header' : 'my custom header value' ,
653
+ } ,
654
+ } ,
655
+ {
656
+ for : '/en/' ,
657
+ values : {
658
+ 'x-custom-header' : 'my custom header value' ,
659
+ } ,
660
+ } ,
661
+ {
662
+ for : '/es/' ,
663
+ values : {
664
+ 'x-custom-header' : 'my custom header value' ,
665
+ } ,
666
+ } ,
667
+ {
668
+ for : '/fr/' ,
669
+ values : {
670
+ 'x-custom-header' : 'my custom header value' ,
671
+ } ,
672
+ } ,
673
+ {
674
+ for : '/api/*' ,
675
+ values : {
676
+ 'x-custom-api-header' : 'my custom api header value' ,
677
+ } ,
678
+ } ,
679
+ {
680
+ for : '/en/api/*' ,
681
+ values : {
682
+ 'x-custom-api-header' : 'my custom api header value' ,
683
+ } ,
684
+ } ,
685
+ {
686
+ for : '/es/api/*' ,
687
+ values : {
688
+ 'x-custom-api-header' : 'my custom api header value' ,
689
+ } ,
690
+ } ,
691
+ {
692
+ for : '/fr/api/*' ,
693
+ values : {
694
+ 'x-custom-api-header' : 'my custom api header value' ,
695
+ } ,
696
+ } ,
697
+ {
698
+ for : '/*' ,
699
+ values : {
700
+ 'x-custom-header-for-everything' : 'my custom header for everything value' ,
701
+ } ,
702
+ } ,
703
+ {
704
+ for : '/en/*' ,
705
+ values : {
706
+ 'x-custom-header-for-everything' : 'my custom header for everything value' ,
707
+ } ,
708
+ } ,
709
+ {
710
+ for : '/es/*' ,
711
+ values : {
712
+ 'x-custom-header-for-everything' : 'my custom header for everything value' ,
713
+ } ,
714
+ } ,
715
+ {
716
+ for : '/fr/*' ,
717
+ values : {
718
+ 'x-custom-header-for-everything' : 'my custom header for everything value' ,
719
+ } ,
720
+ } ,
721
+ ] )
722
+ } )
635
723
} )
636
724
637
725
describe ( 'utility functions' , ( ) => {
@@ -822,8 +910,6 @@ describe('function helpers', () => {
822
910
// in test data.
823
911
824
912
it ( 'sets custom headers in the Netlify configuration' , ( ) => {
825
- netlifyConfig . headers = [ ]
826
-
827
913
const nextConfig = {
828
914
routesManifest : {
829
915
headers : [
0 commit comments