11import { promises as fs } from 'fs'
22import { join } from 'path'
3- import { platform , version as nodeVersion } from 'process'
3+ import { platform } from 'process'
44import { fileURLToPath } from 'url'
55
66import { Fixture , normalizeOutput } from '@netlify/testing'
77import test from 'ava'
88import { pathExists } from 'path-exists'
9- import semver from 'semver'
109import tmp from 'tmp-promise'
1110
1211import { importJsonFile } from '../../lib/utils/json.js'
@@ -215,10 +214,31 @@ test.serial('cleans up the edge functions dist directory before bundling', async
215214 t . false ( await pathExists ( oldBundlePath ) )
216215} )
217216
218- // Targeting Node 16.7.0+ because these fixtures rely on `fs.cp()`.
219- if ( semver . gte ( nodeVersion , '16.7.0' ) ) {
220- test . serial ( 'builds edge functions generated with the Frameworks API' , async ( t ) => {
221- const output = await new Fixture ( './fixtures/functions_user_framework' )
217+ test . serial ( 'builds edge functions generated with the Frameworks API' , async ( t ) => {
218+ const output = await new Fixture ( './fixtures/functions_user_framework' )
219+ . withFlags ( {
220+ debug : false ,
221+ mode : 'buildbot' ,
222+ } )
223+ . runWithBuild ( )
224+
225+ t . snapshot ( normalizeOutput ( output ) )
226+
227+ const { routes } = await assertManifest ( t , 'functions_user_framework' )
228+
229+ t . is ( routes . length , 1 )
230+ t . deepEqual ( routes [ 0 ] , {
231+ function : 'function-2' ,
232+ pattern : '^/framework(?:/(.*))/?$' ,
233+ excluded_patterns : [ '^/framework/skip_(.*)/?$' ] ,
234+ path : '/framework/*' ,
235+ } )
236+ } )
237+
238+ test . serial (
239+ 'builds both edge functions generated with the Frameworks API and the ones in the internal directory' ,
240+ async ( t ) => {
241+ const output = await new Fixture ( './fixtures/functions_user_internal_framework' )
222242 . withFlags ( {
223243 debug : false ,
224244 mode : 'buildbot' ,
@@ -227,69 +247,45 @@ if (semver.gte(nodeVersion, '16.7.0')) {
227247
228248 t . snapshot ( normalizeOutput ( output ) )
229249
230- const { routes } = await assertManifest ( t , 'functions_user_framework' )
231-
232- t . is ( routes . length , 1 )
233- t . deepEqual ( routes [ 0 ] , {
234- function : 'function-2' ,
235- pattern : '^/framework(?:/(.*))/?$' ,
236- excluded_patterns : [ '^/framework/skip_(.*)/?$' ] ,
237- path : '/framework/*' ,
238- } )
239- } )
240-
241- test . serial (
242- 'builds both edge functions generated with the Frameworks API and the ones in the internal directory' ,
243- async ( t ) => {
244- const output = await new Fixture ( './fixtures/functions_user_internal_framework' )
245- . withFlags ( {
246- debug : false ,
247- mode : 'buildbot' ,
248- } )
249- . runWithBuild ( )
250-
251- t . snapshot ( normalizeOutput ( output ) )
252-
253- const { routes } = await assertManifest ( t , 'functions_user_internal_framework' )
254-
255- t . deepEqual ( routes , [
256- {
257- function : 'frameworks-internal-conflict' ,
258- pattern : '^/frameworks-internal-conflict/frameworks/?$' ,
259- excluded_patterns : [ ] ,
260- path : '/frameworks-internal-conflict/frameworks' ,
261- } ,
262- {
263- function : 'function-3' ,
264- pattern : '^/internal(?:/(.*))/?$' ,
265- excluded_patterns : [ '^/internal/skip_(.*)/?$' ] ,
266- path : '/internal/*' ,
267- } ,
268- {
269- function : 'frameworks-user-conflict' ,
270- pattern : '^/frameworks-user-conflict/frameworks/?$' ,
271- excluded_patterns : [ ] ,
272- path : '/frameworks-user-conflict/frameworks' ,
273- } ,
274- {
275- function : 'function-2' ,
276- pattern : '^/framework(?:/(.*))/?$' ,
277- excluded_patterns : [ '^/framework/skip_(.*)/?$' ] ,
278- path : '/framework/*' ,
279- } ,
280- {
281- function : 'frameworks-user-conflict' ,
282- pattern : '^/frameworks-user-conflict/user/?$' ,
283- excluded_patterns : [ ] ,
284- path : '/frameworks-user-conflict/user' ,
285- } ,
286- {
287- function : 'function-1' ,
288- pattern : '^/user/?$' ,
289- excluded_patterns : [ ] ,
290- path : '/user' ,
291- } ,
292- ] )
293- } ,
294- )
295- }
250+ const { routes } = await assertManifest ( t , 'functions_user_internal_framework' )
251+
252+ t . deepEqual ( routes , [
253+ {
254+ function : 'frameworks-internal-conflict' ,
255+ pattern : '^/frameworks-internal-conflict/frameworks/?$' ,
256+ excluded_patterns : [ ] ,
257+ path : '/frameworks-internal-conflict/frameworks' ,
258+ } ,
259+ {
260+ function : 'function-3' ,
261+ pattern : '^/internal(?:/(.*))/?$' ,
262+ excluded_patterns : [ '^/internal/skip_(.*)/?$' ] ,
263+ path : '/internal/*' ,
264+ } ,
265+ {
266+ function : 'frameworks-user-conflict' ,
267+ pattern : '^/frameworks-user-conflict/frameworks/?$' ,
268+ excluded_patterns : [ ] ,
269+ path : '/frameworks-user-conflict/frameworks' ,
270+ } ,
271+ {
272+ function : 'function-2' ,
273+ pattern : '^/framework(?:/(.*))/?$' ,
274+ excluded_patterns : [ '^/framework/skip_(.*)/?$' ] ,
275+ path : '/framework/*' ,
276+ } ,
277+ {
278+ function : 'frameworks-user-conflict' ,
279+ pattern : '^/frameworks-user-conflict/user/?$' ,
280+ excluded_patterns : [ ] ,
281+ path : '/frameworks-user-conflict/user' ,
282+ } ,
283+ {
284+ function : 'function-1' ,
285+ pattern : '^/user/?$' ,
286+ excluded_patterns : [ ] ,
287+ path : '/user' ,
288+ } ,
289+ ] )
290+ } ,
291+ )
0 commit comments