@@ -44,9 +44,15 @@ test('Generates a manifest with display names', () => {
44
44
name : 'Display Name' ,
45
45
} ,
46
46
}
47
- const manifest = generateManifest ( { bundles : [ ] , declarations, functions, internalFunctionConfig } )
47
+ const manifest = generateManifest ( {
48
+ bundles : [ ] ,
49
+ declarations,
50
+ functions,
51
+ internalFunctionConfig,
52
+ featureFlags : { edge_functions_path_urlpattern : true } ,
53
+ } )
48
54
49
- const expectedRoutes = [ { function : 'func-1' , pattern : '^/f1/.* /?$' , excluded_patterns : [ ] } ]
55
+ const expectedRoutes = [ { function : 'func-1' , pattern : '^/f1(?:/(.*)) /?$' , excluded_patterns : [ ] } ]
50
56
expect ( manifest . function_config ) . toEqual ( {
51
57
'func-1' : { name : 'Display Name' } ,
52
58
} )
@@ -63,9 +69,15 @@ test('Generates a manifest with a generator field', () => {
63
69
generator :
'@netlify/[email protected] ' ,
64
70
} ,
65
71
}
66
- const manifest = generateManifest ( { bundles : [ ] , declarations, functions, internalFunctionConfig } )
72
+ const manifest = generateManifest ( {
73
+ bundles : [ ] ,
74
+ declarations,
75
+ functions,
76
+ internalFunctionConfig,
77
+ featureFlags : { edge_functions_path_urlpattern : true } ,
78
+ } )
67
79
68
- const expectedRoutes = [ { function : 'func-1' , pattern : '^/f1/.* /?$' , excluded_patterns : [ ] } ]
80
+ const expectedRoutes = [ { function : 'func-1' , pattern : '^/f1(?:/(.*)) /?$' , excluded_patterns : [ ] } ]
69
81
const expectedFunctionConfig = { 'func-1' :
{ generator :
'@netlify/[email protected] ' } }
70
82
expect ( manifest . routes ) . toEqual ( expectedRoutes )
71
83
expect ( manifest . function_config ) . toEqual ( expectedFunctionConfig )
@@ -79,14 +91,23 @@ test('Generates a manifest with excluded paths and patterns', () => {
79
91
]
80
92
const declarations : Declaration [ ] = [
81
93
{ function : 'func-1' , path : '/f1/*' , excludedPath : '/f1/exclude' } ,
82
- { function : 'func-2' , pattern : '^/f2/.* /?$' , excludedPattern : [ '^/f2/exclude$' , '^/f2/exclude-as-well$' ] } ,
94
+ { function : 'func-2' , pattern : '^/f2(?:/(.*)) /?$' , excludedPattern : [ '^/f2/exclude$' , '^/f2/exclude-as-well$' ] } ,
83
95
{ function : 'func-3' , path : '/*' , excludedPath : '/**/*.html' } ,
84
96
]
85
- const manifest = generateManifest ( { bundles : [ ] , declarations, functions } )
97
+ const manifest = generateManifest ( {
98
+ bundles : [ ] ,
99
+ declarations,
100
+ functions,
101
+ featureFlags : { edge_functions_path_urlpattern : true } ,
102
+ } )
86
103
const expectedRoutes = [
87
- { function : 'func-1' , pattern : '^/f1/.*/?$' , excluded_patterns : [ '^/f1/exclude/?$' ] } ,
88
- { function : 'func-2' , pattern : '^/f2/.*/?$' , excluded_patterns : [ '^/f2/exclude$' , '^/f2/exclude-as-well$' ] } ,
89
- { function : 'func-3' , pattern : '^/.*/?$' , excluded_patterns : [ '^/.*/.*\\.html/?$' ] } ,
104
+ { function : 'func-1' , pattern : '^/f1(?:/(.*))/?$' , excluded_patterns : [ '^/f1/exclude/?$' ] } ,
105
+ { function : 'func-2' , pattern : '^/f2(?:/(.*))/?$' , excluded_patterns : [ '^/f2/exclude$' , '^/f2/exclude-as-well$' ] } ,
106
+ {
107
+ function : 'func-3' ,
108
+ pattern : '^(?:/(.*))/?$' ,
109
+ excluded_patterns : [ '^(?:/((?:.*)(?:/(?:.*))*))?(?:/(.*))\\.html/?$' ] ,
110
+ } ,
90
111
]
91
112
92
113
expect ( manifest . routes ) . toEqual ( expectedRoutes )
@@ -105,9 +126,14 @@ test('TOML-defined paths can be combined with ISC-defined excluded paths', () =>
105
126
const userFunctionConfig : Record < string , FunctionConfig > = {
106
127
'func-1' : { excludedPath : '/f1/exclude' } ,
107
128
}
108
- const manifest = generateManifest ( { bundles : [ ] , declarations, functions, userFunctionConfig } )
109
-
110
- const expectedRoutes = [ { function : 'func-1' , pattern : '^/f1/.*/?$' , excluded_patterns : [ ] } ]
129
+ const manifest = generateManifest ( {
130
+ bundles : [ ] ,
131
+ declarations,
132
+ functions,
133
+ userFunctionConfig,
134
+ featureFlags : { edge_functions_path_urlpattern : true } ,
135
+ } )
136
+ const expectedRoutes = [ { function : 'func-1' , pattern : '^/f1(?:/(.*))/?$' , excluded_patterns : [ ] } ]
111
137
112
138
expect ( manifest . routes ) . toEqual ( expectedRoutes )
113
139
expect ( manifest . function_config ) . toEqual ( {
@@ -123,7 +149,7 @@ test('Filters out internal in-source configurations in user created functions',
123
149
]
124
150
const declarations : Declaration [ ] = [
125
151
{ function : 'func-1' , path : '/f1/*' } ,
126
- { function : 'func-2' , pattern : '^/f2/.* /?$' } ,
152
+ { function : 'func-2' , pattern : '^/f2(?:/(.*)) /?$' } ,
127
153
]
128
154
const userFunctionConfig : Record < string , FunctionConfig > = {
129
155
'func-1' : {
@@ -185,22 +211,23 @@ test('excludedPath from ISC goes into function_config, TOML goes into routes', (
185
211
functions,
186
212
userFunctionConfig,
187
213
internalFunctionConfig,
214
+ featureFlags : { edge_functions_path_urlpattern : true } ,
188
215
} )
189
216
expect ( manifest . routes ) . toEqual ( [
190
217
{
191
218
function : 'customisation' ,
192
- pattern : '^/showcases/.* /?$' ,
219
+ pattern : '^/showcases(?:/(.*)) /?$' ,
193
220
excluded_patterns : [ ] ,
194
221
} ,
195
222
{
196
223
function : 'customisation' ,
197
- pattern : '^/checkout/.* /?$' ,
198
- excluded_patterns : [ '^/.* /terms-and-conditions/?$' ] ,
224
+ pattern : '^/checkout(?:/(.*)) /?$' ,
225
+ excluded_patterns : [ '^(?:/(.*)) /terms-and-conditions/?$' ] ,
199
226
} ,
200
227
] )
201
228
expect ( manifest . function_config ) . toEqual ( {
202
229
customisation : {
203
- excluded_patterns : [ '^/.* \\.css/?$' , '^/.* \\.jpg/?$' ] ,
230
+ excluded_patterns : [ '^(?:/(.*)) \\.css/?$' , '^(?:/(.*)) \\.jpg/?$' ] ,
204
231
} ,
205
232
} )
206
233
@@ -220,7 +247,7 @@ test('Includes failure modes in manifest', () => {
220
247
]
221
248
const declarations : Declaration [ ] = [
222
249
{ function : 'func-1' , path : '/f1/*' } ,
223
- { function : 'func-2' , pattern : '^/f2/.* /?$' } ,
250
+ { function : 'func-2' , pattern : '^/f2(?:/(.*)) /?$' } ,
224
251
]
225
252
const userFunctionConfig : Record < string , FunctionConfig > = {
226
253
'func-1' : {
@@ -330,17 +357,28 @@ test('Generates a manifest with layers', () => {
330
357
{ function : 'func-2' , path : '/f2/*' } ,
331
358
]
332
359
const expectedRoutes = [
333
- { function : 'func-1' , pattern : '^/f1/.* /?$' , excluded_patterns : [ ] } ,
334
- { function : 'func-2' , pattern : '^/f2/.* /?$' , excluded_patterns : [ ] } ,
360
+ { function : 'func-1' , pattern : '^/f1(?:/(.*)) /?$' , excluded_patterns : [ ] } ,
361
+ { function : 'func-2' , pattern : '^/f2(?:/(.*)) /?$' , excluded_patterns : [ ] } ,
335
362
]
336
363
const layers = [
337
364
{
338
365
name : 'onion' ,
339
366
flag : 'edge_functions_onion_layer' ,
340
367
} ,
341
368
]
342
- const manifest1 = generateManifest ( { bundles : [ ] , declarations, functions } )
343
- const manifest2 = generateManifest ( { bundles : [ ] , declarations, functions, layers } )
369
+ const manifest1 = generateManifest ( {
370
+ bundles : [ ] ,
371
+ declarations,
372
+ functions,
373
+ featureFlags : { edge_functions_path_urlpattern : true } ,
374
+ } )
375
+ const manifest2 = generateManifest ( {
376
+ bundles : [ ] ,
377
+ declarations,
378
+ functions,
379
+ layers,
380
+ featureFlags : { edge_functions_path_urlpattern : true } ,
381
+ } )
344
382
345
383
expect ( manifest1 . routes ) . toEqual ( expectedRoutes )
346
384
expect ( manifest1 . layers ) . toEqual ( [ ] )
0 commit comments