@@ -9,19 +9,20 @@ const deployConfig = {
9
9
layers : [ ] ,
10
10
}
11
11
12
- test ( 'In source config takes precedence over netlify.toml config' , ( ) => {
12
+ test ( 'In- source config takes precedence over netlify.toml config' , ( ) => {
13
13
const tomlConfig = [
14
14
{ function : 'geolocation' , path : '/geo' , cache : 'off' } ,
15
15
{ function : 'json' , path : '/json' , cache : 'manual' } ,
16
16
]
17
17
18
18
const funcConfig = {
19
- geolocation : { path : '/geo-isc' , cache : 'manual' } ,
19
+ geolocation : { path : [ '/geo-isc' , '/*' ] , cache : 'manual' } ,
20
20
json : { path : '/json' , cache : 'off' } ,
21
21
} as Record < string , FunctionConfig >
22
22
23
23
const expectedDeclarations = [
24
24
{ function : 'geolocation' , path : '/geo-isc' , cache : 'manual' } ,
25
+ { function : 'geolocation' , path : '/*' , cache : 'manual' } ,
25
26
{ function : 'json' , path : '/json' , cache : 'off' } ,
26
27
]
27
28
@@ -30,14 +31,14 @@ test('In source config takes precedence over netlify.toml config', () => {
30
31
expect ( declarations ) . toEqual ( expectedDeclarations )
31
32
} )
32
33
33
- test ( "Declarations don't break if no in source config is provided" , ( ) => {
34
+ test ( "Declarations don't break if no in- source config is provided" , ( ) => {
34
35
const tomlConfig = [
35
36
{ function : 'geolocation' , path : '/geo' , cache : 'off' } ,
36
37
{ function : 'json' , path : '/json' , cache : 'manual' } ,
37
38
]
38
39
39
40
const funcConfig = {
40
- geolocation : { path : '/geo-isc' , cache : 'manual' } ,
41
+ geolocation : { path : [ '/geo-isc' ] , cache : 'manual' } ,
41
42
json : { } ,
42
43
} as Record < string , FunctionConfig >
43
44
@@ -51,11 +52,11 @@ test("Declarations don't break if no in source config is provided", () => {
51
52
expect ( declarations ) . toEqual ( expectedDeclarations )
52
53
} )
53
54
54
- test ( 'In source config works independent of the netlify.toml file if a path is defined and otherwise if no path is set' , ( ) => {
55
+ test ( 'In- source config works independent of the netlify.toml file if a path is defined and otherwise if no path is set' , ( ) => {
55
56
const tomlConfig = [ { function : 'geolocation' , path : '/geo' , cache : 'off' } ]
56
57
57
58
const funcConfigWithPath = {
58
- json : { path : '/json' , cache : 'off' } ,
59
+ json : { path : [ '/json' , '/json-isc' ] , cache : 'off' } ,
59
60
} as Record < string , FunctionConfig >
60
61
61
62
const funcConfigWithoutPath = {
@@ -65,6 +66,7 @@ test('In source config works independent of the netlify.toml file if a path is d
65
66
const expectedDeclarationsWithISCPath = [
66
67
{ function : 'geolocation' , path : '/geo' , cache : 'off' } ,
67
68
{ function : 'json' , path : '/json' , cache : 'off' } ,
69
+ { function : 'json' , path : '/json-isc' , cache : 'off' } ,
68
70
]
69
71
70
72
const expectedDeclarationsWithoutISCPath = [ { function : 'geolocation' , path : '/geo' , cache : 'off' } ]
@@ -75,3 +77,53 @@ test('In source config works independent of the netlify.toml file if a path is d
75
77
const declarationsWithoutISCPath = getDeclarationsFromConfig ( tomlConfig , funcConfigWithoutPath , deployConfig )
76
78
expect ( declarationsWithoutISCPath ) . toEqual ( expectedDeclarationsWithoutISCPath )
77
79
} )
80
+
81
+ test ( 'In-source config works if only the cache config property is set' , ( ) => {
82
+ const tomlConfig = [ { function : 'geolocation' , path : '/geo' , cache : 'off' } ]
83
+
84
+ const funcConfig = {
85
+ geolocation : { cache : 'manual' } ,
86
+ } as Record < string , FunctionConfig >
87
+
88
+ const expectedDeclarations = [ { function : 'geolocation' , path : '/geo' , cache : 'manual' } ]
89
+
90
+ expect ( getDeclarationsFromConfig ( tomlConfig , funcConfig , deployConfig ) ) . toEqual ( expectedDeclarations )
91
+ } )
92
+
93
+ test ( "In-source config path property works if it's not an array" , ( ) => {
94
+ const tomlConfig = [ { function : 'json' , path : '/json-toml' , cache : 'off' } ]
95
+
96
+ const funcConfig = {
97
+ json : { path : '/json' , cache : 'manual' } ,
98
+ } as Record < string , FunctionConfig >
99
+
100
+ const expectedDeclarations = [ { function : 'json' , path : '/json' , cache : 'manual' } ]
101
+
102
+ expect ( getDeclarationsFromConfig ( tomlConfig , funcConfig , deployConfig ) ) . toEqual ( expectedDeclarations )
103
+ } )
104
+
105
+ test ( "In-source config path property works if it's not an array and it's not present in toml or deploy config" , ( ) => {
106
+ const tomlConfig = [ { function : 'geolocation' , path : '/geo' , cache : 'off' } ]
107
+ const funcConfig = {
108
+ json : { path : '/json-isc' , cache : 'manual' } ,
109
+ } as Record < string , FunctionConfig >
110
+
111
+ const expectedDeclarations = [
112
+ { function : 'geolocation' , path : '/geo' , cache : 'off' } ,
113
+ { function : 'json' , path : '/json-isc' , cache : 'manual' } ,
114
+ ]
115
+
116
+ expect ( getDeclarationsFromConfig ( tomlConfig , funcConfig , deployConfig ) ) . toEqual ( expectedDeclarations )
117
+ } )
118
+
119
+ test ( 'In-source config works if path property is an empty array with cache value specified' , ( ) => {
120
+ const tomlConfig = [ { function : 'json' , path : '/json-toml' , cache : 'off' } ]
121
+
122
+ const funcConfig = {
123
+ json : { path : [ ] , cache : 'manual' } ,
124
+ } as Record < string , FunctionConfig >
125
+
126
+ const expectedDeclarations = [ { function : 'json' , path : '/json-toml' , cache : 'manual' } ]
127
+
128
+ expect ( getDeclarationsFromConfig ( tomlConfig , funcConfig , deployConfig ) ) . toEqual ( expectedDeclarations )
129
+ } )
0 commit comments