1- import { getExtendedApiRouteConfigs } from " ../../packages/runtime/src/helpers/functions"
2- import { describeCwdTmpDir , moveNextDist } from " ../test-utils"
1+ import { getApiRouteConfigs , getExtendedApiRouteConfigs } from ' ../../packages/runtime/src/helpers/functions'
2+ import { describeCwdTmpDir , moveNextDist } from ' ../test-utils'
33
44describeCwdTmpDir ( 'api route file analysis' , ( ) => {
55 it ( 'extracts correct route configs from source files' , async ( ) => {
6+ await moveNextDist ( )
7+ const configs = await getApiRouteConfigs ( '.next' , process . cwd ( ) )
8+ // Using a Set means the order doesn't matter
9+ expect ( new Set ( configs ) ) . toEqual (
10+ new Set ( [
11+ {
12+ compiled : 'pages/api/og.js' ,
13+ config : {
14+ runtime : 'edge' ,
15+ } ,
16+ route : '/api/og' ,
17+ } ,
18+ {
19+ compiled : 'pages/api/enterPreview.js' ,
20+ config : { } ,
21+ route : '/api/enterPreview' ,
22+ } ,
23+ {
24+ compiled : 'pages/api/exitPreview.js' ,
25+ config : { } ,
26+ route : '/api/exitPreview' ,
27+ } ,
28+ {
29+ compiled : 'pages/api/hello.js' ,
30+ config : { } ,
31+ route : '/api/hello' ,
32+ } ,
33+ {
34+ compiled : 'pages/api/shows/[...params].js' ,
35+ config : { } ,
36+ route : '/api/shows/[...params]' ,
37+ } ,
38+ {
39+ compiled : 'pages/api/shows/[id].js' ,
40+ config : { } ,
41+ route : '/api/shows/[id]' ,
42+ } ,
43+ {
44+ compiled : 'pages/api/hello-background.js' ,
45+ config : { type : 'experimental-background' } ,
46+ route : '/api/hello-background' ,
47+ } ,
48+ {
49+ compiled : 'pages/api/hello-scheduled.js' ,
50+ config : { schedule : '@hourly' , type : 'experimental-scheduled' } ,
51+ route : '/api/hello-scheduled' ,
52+ } ,
53+ {
54+ compiled : 'pages/api/revalidate.js' ,
55+ config : { } ,
56+ route : '/api/revalidate' ,
57+ } ,
58+ ] ) ,
59+ )
60+ } )
61+
62+ it ( 'only shows scheduled/background functions as extended funcs' , async ( ) => {
663 await moveNextDist ( )
764 const configs = await getExtendedApiRouteConfigs ( '.next' , process . cwd ( ) )
865 // Using a Set means the order doesn't matter
@@ -21,4 +78,4 @@ describeCwdTmpDir('api route file analysis', () => {
2178 ] ) ,
2279 )
2380 } )
24- } )
81+ } )
0 commit comments