Skip to content

Commit 37a6e3a

Browse files
committed
fix: functions test
1 parent cbcdc0c commit 37a6e3a

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

packages/runtime/src/helpers/functions.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,7 @@ export const getAPILambdas = async (
401401
export const getApiRouteConfigs = async (
402402
publish: string,
403403
appDir: string,
404-
pageExtensions: string[],
404+
pageExtensions?: string[],
405405
): Promise<Array<ApiRouteConfig>> => {
406406
const pages = await readJSON(join(publish, 'server', 'pages-manifest.json'))
407407
const apiRoutes = Object.keys(pages).filter((page) => page.startsWith('/api/'))
@@ -442,7 +442,7 @@ export const getApiRouteConfigs = async (
442442
export const getExtendedApiRouteConfigs = async (
443443
publish: string,
444444
appDir: string,
445-
pageExtensions: string[],
445+
pageExtensions?: string[],
446446
): Promise<Array<ApiRouteConfig>> => {
447447
const settledApiRoutes = await getApiRouteConfigs(publish, appDir, pageExtensions)
448448

test/helpers/functions.spec.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@ import { describeCwdTmpDir, moveNextDist } from '../test-utils'
44
describeCwdTmpDir('api route file analysis', () => {
55
it('extracts correct route configs from source files', async () => {
66
await moveNextDist()
7-
const configs = await getApiRouteConfigs('.next', process.cwd(), ['js', 'jsx', 'ts', 'tsx'])
7+
const configs = await getApiRouteConfigs('.next', process.cwd())
88
// Using a Set means the order doesn't matter
99
expect(new Set(configs.map(({ includedFiles, ...rest }) => rest))).toEqual(
1010
new Set([
1111
{
1212
functionName: '_api_og-handler',
13+
functionTitle: 'Next.js API handler /api/og',
1314
compiled: 'pages/api/og.js',
1415
config: {
1516
runtime: 'edge',
@@ -18,48 +19,56 @@ describeCwdTmpDir('api route file analysis', () => {
1819
},
1920
{
2021
functionName: '_api_enterPreview-handler',
22+
functionTitle: 'Next.js API handler /api/enterPreview',
2123
compiled: 'pages/api/enterPreview.js',
2224
config: {},
2325
route: '/api/enterPreview',
2426
},
2527
{
2628
functionName: '_api_exitPreview-handler',
29+
functionTitle: 'Next.js API handler /api/exitPreview',
2730
compiled: 'pages/api/exitPreview.js',
2831
config: {},
2932
route: '/api/exitPreview',
3033
},
3134
{
3235
functionName: '_api_hello-handler',
36+
functionTitle: 'Next.js API handler /api/hello',
3337
compiled: 'pages/api/hello.js',
3438
config: {},
3539
route: '/api/hello',
3640
},
3741
{
3842
functionName: '_api_shows_params-SPLAT-handler',
43+
functionTitle: 'Next.js API handler /api/shows/[...params]',
3944
compiled: 'pages/api/shows/[...params].js',
4045
config: {},
4146
route: '/api/shows/[...params]',
4247
},
4348
{
4449
functionName: '_api_shows_id-PARAM-handler',
50+
functionTitle: 'Next.js API handler /api/shows/[id]',
4551
compiled: 'pages/api/shows/[id].js',
4652
config: {},
4753
route: '/api/shows/[id]',
4854
},
4955
{
5056
functionName: '_api_hello-background-background',
57+
functionTitle: 'Next.js API handler /api/hello-background',
5158
compiled: 'pages/api/hello-background.js',
5259
config: { type: 'experimental-background' },
5360
route: '/api/hello-background',
5461
},
5562
{
5663
functionName: '_api_hello-scheduled-handler',
64+
functionTitle: 'Next.js API handler /api/hello-scheduled',
5765
compiled: 'pages/api/hello-scheduled.js',
5866
config: { schedule: '@hourly', type: 'experimental-scheduled' },
5967
route: '/api/hello-scheduled',
6068
},
6169
{
6270
functionName: '_api_revalidate-handler',
71+
functionTitle: 'Next.js API handler /api/revalidate',
6372
compiled: 'pages/api/revalidate.js',
6473
config: {},
6574
route: '/api/revalidate',
@@ -70,18 +79,20 @@ describeCwdTmpDir('api route file analysis', () => {
7079

7180
it('only shows scheduled/background functions as extended funcs', async () => {
7281
await moveNextDist()
73-
const configs = await getExtendedApiRouteConfigs('.next', process.cwd(), [])
82+
const configs = await getExtendedApiRouteConfigs('.next', process.cwd())
7483
// Using a Set means the order doesn't matter
7584
expect(new Set(configs.map(({ includedFiles, ...rest }) => rest))).toEqual(
7685
new Set([
7786
{
7887
functionName: '_api_hello-background-background',
88+
functionTitle: 'Next.js API handler /api/hello-background',
7989
compiled: 'pages/api/hello-background.js',
8090
config: { type: 'experimental-background' },
8191
route: '/api/hello-background',
8292
},
8393
{
8494
functionName: '_api_hello-scheduled-handler',
95+
functionTitle: 'Next.js API handler /api/hello-scheduled',
8596
compiled: 'pages/api/hello-scheduled.js',
8697
config: { schedule: '@hourly', type: 'experimental-scheduled' },
8798
route: '/api/hello-scheduled',

0 commit comments

Comments
 (0)