diff --git a/packages/edge-bundler/node/config.test.ts b/packages/edge-bundler/node/config.test.ts index 8f5b02da97..3d92ab326d 100644 --- a/packages/edge-bundler/node/config.test.ts +++ b/packages/edge-bundler/node/config.test.ts @@ -240,7 +240,7 @@ test('Loads function paths from the in-source `config` function', async () => { }) const generatedFiles = await fs.readdir(distPath) - expect(result.functions.length).toBe(7) + expect(result.functions.length).toBe(11) expect(generatedFiles.length).toBe(2) const manifestFile = await fs.readFile(resolve(distPath, 'manifest.json'), 'utf8') @@ -251,7 +251,7 @@ test('Loads function paths from the in-source `config` function', async () => { expect(bundles[0].format).toBe('eszip2') expect(generatedFiles.includes(bundles[0].asset)).toBe(true) - expect(routes.length).toBe(6) + expect(routes.length).toBe(12) expect(routes[0]).toEqual({ function: 'framework-func2', pattern: '^/framework-func2/?$', @@ -272,24 +272,54 @@ test('Loads function paths from the in-source `config` function', async () => { path: '/framework-func1', }) expect(routes[3]).toEqual({ + function: 'framework-func3', + pattern: '^/framework-func3(/.*)?$', + excluded_patterns: ['^/framework-func3/excluded$'], + }) + expect(routes[4]).toEqual({ + function: 'framework-func4', + pattern: '^/framework-func4(/.*)?$', + excluded_patterns: ['^/framework-func4/excluded$', '^/framework-func4-alt/excluded$'], + }) + expect(routes[5]).toEqual({ + function: 'framework-func4', + pattern: '^/framework-func4-alt(/.*)?$', + excluded_patterns: ['^/framework-func4/excluded$', '^/framework-func4-alt/excluded$'], + }) + expect(routes[6]).toEqual({ function: 'user-func1', pattern: '^/user-func1/?$', excluded_patterns: [], path: '/user-func1', }) - expect(routes[4]).toEqual({ + expect(routes[7]).toEqual({ function: 'user-func3', pattern: '^/user-func3/?$', excluded_patterns: [], path: '/user-func3', }) - expect(routes[5]).toEqual({ + expect(routes[8]).toEqual({ function: 'user-func5', pattern: '^/user-func5(?:/(.*))/?$', excluded_patterns: ['^/user-func5/excluded/?$'], path: '/user-func5/*', methods: ['GET'], }) + expect(routes[9]).toEqual({ + function: 'user-func6', + pattern: '^/user-func6(/.*)?$', + excluded_patterns: ['^/user-func6/excluded$'], + }) + expect(routes[10]).toEqual({ + function: 'user-func7', + pattern: '^/user-func7(/.*)?$', + excluded_patterns: ['^/user-func7/excluded$', '^/user-func7-alt/excluded$'], + }) + expect(routes[11]).toEqual({ + function: 'user-func7', + pattern: '^/user-func7-alt(/.*)?$', + excluded_patterns: ['^/user-func7/excluded$', '^/user-func7-alt/excluded$'], + }) expect(postCacheRoutes.length).toBe(1) expect(postCacheRoutes[0]).toEqual({ @@ -300,10 +330,22 @@ test('Loads function paths from the in-source `config` function', async () => { methods: ['POST', 'PUT'], }) - expect(Object.keys(functionConfig)).toHaveLength(1) + expect(Object.keys(functionConfig)).toHaveLength(5) expect(functionConfig['user-func5']).toEqual({ excluded_patterns: ['^/user-func5/excluded/?$'], }) + expect(functionConfig['user-func6']).toEqual({ + excluded_patterns: ['^/user-func6/excluded$'], + }) + expect(functionConfig['user-func7']).toEqual({ + excluded_patterns: ['^/user-func7/excluded$', '^/user-func7-alt/excluded$'], + }) + expect(functionConfig['framework-func3']).toEqual({ + excluded_patterns: ['^/framework-func3/excluded$'], + }) + expect(functionConfig['framework-func4']).toEqual({ + excluded_patterns: ['^/framework-func4/excluded$', '^/framework-func4-alt/excluded$'], + }) await cleanup() }) diff --git a/packages/edge-bundler/test/fixtures/with_config/.netlify/edge-functions/framework-func3.ts b/packages/edge-bundler/test/fixtures/with_config/.netlify/edge-functions/framework-func3.ts new file mode 100644 index 0000000000..5e3ddb5aad --- /dev/null +++ b/packages/edge-bundler/test/fixtures/with_config/.netlify/edge-functions/framework-func3.ts @@ -0,0 +1,13 @@ +import { IntegrationsConfig } from 'https://edge.netlify.com' +import { greet } from 'alias:helper' + +export default async () => { + const greeting = greet('framework function 3') + + return new Response(greeting) +} + +export const config: IntegrationsConfig = { + pattern: '/framework-func3(/.*)?', + excludedPattern: '/framework-func3/excluded', +} diff --git a/packages/edge-bundler/test/fixtures/with_config/.netlify/edge-functions/framework-func4.ts b/packages/edge-bundler/test/fixtures/with_config/.netlify/edge-functions/framework-func4.ts new file mode 100644 index 0000000000..3ad0f1ff11 --- /dev/null +++ b/packages/edge-bundler/test/fixtures/with_config/.netlify/edge-functions/framework-func4.ts @@ -0,0 +1,13 @@ +import { IntegrationsConfig } from 'https://edge.netlify.com' +import { greet } from 'alias:helper' + +export default async () => { + const greeting = greet('framework function 4') + + return new Response(greeting) +} + +export const config: IntegrationsConfig = { + pattern: ['/framework-func4(/.*)?', '/framework-func4-alt(/.*)?'], + excludedPattern: ['/framework-func4/excluded', '/framework-func4-alt/excluded'], +} diff --git a/packages/edge-bundler/test/fixtures/with_config/netlify/edge-functions/user-func6.ts b/packages/edge-bundler/test/fixtures/with_config/netlify/edge-functions/user-func6.ts new file mode 100644 index 0000000000..f9ef8ab2b5 --- /dev/null +++ b/packages/edge-bundler/test/fixtures/with_config/netlify/edge-functions/user-func6.ts @@ -0,0 +1,6 @@ +export default async () => new Response('Hello from user function 6.') + +export const config = { + pattern: '/user-func6(/.*)?', + excludedPattern: '/user-func6/excluded', +} diff --git a/packages/edge-bundler/test/fixtures/with_config/netlify/edge-functions/user-func7.ts b/packages/edge-bundler/test/fixtures/with_config/netlify/edge-functions/user-func7.ts new file mode 100644 index 0000000000..826a920ef3 --- /dev/null +++ b/packages/edge-bundler/test/fixtures/with_config/netlify/edge-functions/user-func7.ts @@ -0,0 +1,6 @@ +export default async () => new Response('Hello from user function 7.') + +export const config = { + pattern: ['/user-func7(/.*)?', '/user-func7-alt(/.*)?'], + excludedPattern: ['/user-func7/excluded', '/user-func7-alt/excluded'] +}