-
Notifications
You must be signed in to change notification settings - Fork 87
/
Copy pathfunctions.spec.ts
103 lines (101 loc) · 3.77 KB
/
functions.spec.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
import { getApiRouteConfigs, getExtendedApiRouteConfigs } from '../../packages/runtime/src/helpers/functions'
import { describeCwdTmpDir, moveNextDist } from '../test-utils'
describeCwdTmpDir('api route file analysis', () => {
it('extracts correct route configs from source files', async () => {
await moveNextDist()
const configs = await getApiRouteConfigs('.next', process.cwd())
// Using a Set means the order doesn't matter
expect(new Set(configs.map(({ includedFiles, ...rest }) => rest))).toEqual(
new Set([
{
functionName: '_api_og-handler',
functionTitle: 'Next.js API handler /api/og',
compiled: 'pages/api/og.js',
config: {
runtime: 'edge',
},
route: '/api/og',
},
{
functionName: '_api_enterPreview-handler',
functionTitle: 'Next.js API handler /api/enterPreview',
compiled: 'pages/api/enterPreview.js',
config: {},
route: '/api/enterPreview',
},
{
functionName: '_api_exitPreview-handler',
functionTitle: 'Next.js API handler /api/exitPreview',
compiled: 'pages/api/exitPreview.js',
config: {},
route: '/api/exitPreview',
},
{
functionName: '_api_hello-handler',
functionTitle: 'Next.js API handler /api/hello',
compiled: 'pages/api/hello.js',
config: {},
route: '/api/hello',
},
{
functionName: '_api_shows_params-SPLAT-handler',
functionTitle: 'Next.js API handler /api/shows/[...params]',
compiled: 'pages/api/shows/[...params].js',
config: {},
route: '/api/shows/[...params]',
},
{
functionName: '_api_shows_id-PARAM-handler',
functionTitle: 'Next.js API handler /api/shows/[id]',
compiled: 'pages/api/shows/[id].js',
config: {},
route: '/api/shows/[id]',
},
{
functionName: '_api_hello-background-background',
functionTitle: 'Next.js API handler /api/hello-background',
compiled: 'pages/api/hello-background.js',
config: { type: 'experimental-background' },
route: '/api/hello-background',
},
{
functionName: '_api_hello-scheduled-handler',
functionTitle: 'Next.js API handler /api/hello-scheduled',
compiled: 'pages/api/hello-scheduled.js',
config: { schedule: '@hourly', type: 'experimental-scheduled' },
route: '/api/hello-scheduled',
},
{
functionName: '_api_revalidate-handler',
functionTitle: 'Next.js API handler /api/revalidate',
compiled: 'pages/api/revalidate.js',
config: {},
route: '/api/revalidate',
},
]),
)
})
it('only shows scheduled/background functions as extended funcs', async () => {
await moveNextDist()
const configs = await getExtendedApiRouteConfigs('.next', process.cwd())
// Using a Set means the order doesn't matter
expect(new Set(configs.map(({ includedFiles, ...rest }) => rest))).toEqual(
new Set([
{
functionName: '_api_hello-background-background',
functionTitle: 'Next.js API handler /api/hello-background',
compiled: 'pages/api/hello-background.js',
config: { type: 'experimental-background' },
route: '/api/hello-background',
},
{
functionName: '_api_hello-scheduled-handler',
functionTitle: 'Next.js API handler /api/hello-scheduled',
compiled: 'pages/api/hello-scheduled.js',
config: { schedule: '@hourly', type: 'experimental-scheduled' },
route: '/api/hello-scheduled',
},
]),
)
})
})