Repository: dai-shi/waku
Pull request #1099 (2024-12-28 07:36:11)

feat(define-router): handleApi

vercel[bot]: [vc]: #uCCryeLs2ht3HBBuz7hqI1jLkj0xUmk4cJhrY2hXAFc=:eyJpc01vbm9yZXBvIjp0cnVlLCJ0eXBlIjoiZ2l0aHViIiwicHJvamVjdHMiOlt7Im5hbWUiOiJ3YWt1IiwiaW5zcGVjdG9yVXJsIjoiaHR0cHM6Ly92ZXJjZWwuY29tL2RhaXNoaXMtcHJvamVjdHMvd2FrdS80SjRWTll6cUdQRVljckZ6S3Y5TXZCVURVUjRWIiwicHJldmlld1VybCI6Indha3UtZ2l0LWZlYXQtZGVmaW5lLXJvdXRlcmhhbmRsZS1hcGktZGFpc2hpcy1wcm9qZWN0cy52ZXJjZWwuYXBwIiwibmV4dENvbW1pdFN0YXR1cyI6IkRFUExPWUVEIn1dfQ==
**The latest updates on your projects**. Learn more about [Vercel for Git ↗︎](https://vercel.link/github-learn-more)

| Name | Status | Preview | Updated (UTC) |
| :--- | :----- | :------ | :------ |
| **waku** | ✅ Ready ([Inspect](https://vercel.com/daishis-projects/waku/4J4VNYzqGPEYcrFzKv9MvBUDUR4V)) | [Visit Preview](https://waku-git-feat-define-routerhandle-api-daishis-projects.vercel.app) | Dec 28, 2024 7:36am |


codesandbox-ci[bot]: This pull request is automatically built and testable in [CodeSandbox](https://codesandbox.io).

  To see build info of the built libraries, click [here](https://ci.codesandbox.io/status/dai-shi/waku/pr/1099/builds/574120) or the icon next to each commit SHA.

Patch:
diff --git a/examples/22_define-router/src/entries.tsx b/examples/22_define-router/src/entries.tsx
index 0e4c4e23..35d7049e 100644
--- a/examples/22_define-router/src/entries.tsx
+++ b/examples/22_define-router/src/entries.tsx
@@ -9,7 +9,7 @@ import BarPage from './components/BarPage';
 import NestedBazPage from './components/NestedBazPage';
 
 export default defineRouter({
-  getPathConfig: async () => {
+  getRouteConfig: async () => {
     return [
       {
         pattern: '/',
@@ -70,7 +70,7 @@ export default defineRouter({
       },
     ];
   },
-  renderRoute: async (path) => {
+  handleRoute: async (path) => {
     if (path === '/') {
       return {
         routeElement: (
diff --git a/packages/waku/src/router/create-pages.ts b/packages/waku/src/router/create-pages.ts
index 2b4eb542..a1467ec4 100644
--- a/packages/waku/src/router/create-pages.ts
+++ b/packages/waku/src/router/create-pages.ts
@@ -394,7 +394,7 @@ export const createPages = <
   };
 
   const definedRouter = unstable_defineRouter({
-    getPathConfig: async () => {
+    getRouteConfig: async () => {
       await configure();
       const paths: {
         path: PathSpec;
@@ -482,7 +482,7 @@ export const createPages = <
       }
       return paths;
     },
-    renderRoute: async (path, { query }) => {
+    handleRoute: async (path, { query }) => {
       await configure();
 
       // path without slugs
diff --git a/packages/waku/src/router/define-router.ts b/packages/waku/src/router/define-router.ts
index e2c3f2be..83af74d6 100644
--- a/packages/waku/src/router/define-router.ts
+++ b/packages/waku/src/router/define-router.ts
@@ -18,6 +18,7 @@ import { getPathMapping, path2regexp } from '../lib/utils/path.js';
 import type { PathSpec } from '../lib/utils/path.js';
 import { ServerRouter } from './client.js';
 import { getContext } from '../middleware/context.js';
+import { stringToStream } from '../lib/utils/stream.js';
 
 const isStringArray = (x: unknown): x is string[] =>
   Array.isArray(x) && x.every((y) => typeof y === 'string');
@@ -72,7 +73,7 @@ type SlotId = string;
 const ROUTE_SLOT_ID_PREFIX = 'route:';
 
 export function unstable_defineRouter(fns: {
-  getPathConfig: () => Promise<
+  getRouteConfig: () => Promise<
     Iterable<{
       path: PathSpec;
       pathPattern?: PathSpec;
@@ -81,7 +82,7 @@ export function unstable_defineRouter(fns: {
       noSsr?: boolean;
     }>
   >;
-  renderRoute: (
+  handleRoute: (
     path: string,
     options: {
       query?: string;
@@ -91,15 +92,37 @@ export function unstable_defineRouter(fns: {
     elements: Record<SlotId, ReactNode>;
     fallbackElement?: ReactNode;
   }>;
+  getApiConfig?: () => Promise<
+    Iterable<{
+      path: PathSpec;
+      isStatic?: boolean;
+    }>
+  >;
+  handleApi?: (
+    path: string,
+    options: {
+      body: ReadableStream | null;
+      headers: Readonly<Record<string, string>>;
+      method: string;
+    },
+  ) => Promise<{
+    body?: ReadableStream;
+    headers?: Record<string, string | string[]>;
+    status?: number;
+  }>;
 }) {
   const platformObject = unstable_getPlatformObject();
   type MyPathConfig = {
     pathSpec: PathSpec;
     pathname: string | undefined;
     pattern: string;
-    staticElementIds: SlotId[];
-    isStatic?: boolean | undefined;
-    specs: { noSsr?: boolean; is404: boolean };
+    specs: {
+      isStatic?: true;
+      staticElementIds?: SlotId[];
+      noSsr?: true;
+      is404?: true;
+      isApi?: true;
+    };
   }[];
   let cachedPathConfig: MyPathConfig | undefined;
   const getMyPathConfig = async (): Promise<MyPathConfig> => {
@@ -108,59 +131,54 @@ export function unstable_defineRouter(fns: {
       return pathConfig as MyPathConfig;
     }
     if (!cachedPathConfig) {
-      cachedPathConfig = Array.from(await fns.getPathConfig()).map((item) => {
-        const is404 =
-          item.path.length === 1 &&
-          item.path[0]!.type === 'literal' &&
-          item.path[0]!.name === '404';
-        return {
-          pathSpec: item.path,
-          pathname: pathSpec2pathname(item.path),
-          pattern: path2regexp(item.pathPattern || item.path),
-          staticElementIds: Object.entries(item.elements).flatMap(
-            ([id, { isStatic }]) => (isStatic ? [id] : []),
-          ),
-          isStatic:
+      cachedPathConfig = [
+        ...Array.from(await fns.getRouteConfig()).map((item) => {
+          const is404 =
+            item.path.length === 1 &&
+            item.path[0]!.type === 'literal' &&
+            item.path[0]!.name === '404';
+          const isStatic =
             !!item.routeElement.isStatic &&
-            Object.values(item.elements).every((x) => x.isStatic),
-          specs: { is404, noSsr: !!item.noSsr },
-        };
-      });
+            Object.values(item.elements).every((x) => x.isStatic);
+          return {
+            pathSpec: item.path,
+            pathname: pathSpec2pathname(item.path),
+            pattern: path2regexp(item.pathPattern || item.path),
+            specs: {
+              staticElementIds: Object.entries(item.elements).flatMap(
+                ([id, { isStatic }]) => (isStatic ? [id] : []),
+              ),
+              ...(isStatic ? { isStatic: true as const } : {}),
+              ...(is404 ? { is404: true as const } : {}),
+              ...(item.noSsr ? { noSsr: true as const } : {}),
+            },
+          };
+        }),
+        ...Array.from((await fns.getApiConfig?.()) || []).map((item) => {
+          return {
+            pathSpec: item.path,
+            pathname: pathSpec2pathname(item.path),
+            pattern: path2regexp(item.path),
+            specs: {
+              ...(item.isStatic ? { isStatic: true as const } : {}),
+              isApi: true as const,
+            },
+          };
+        }),
+      ];
     }
     return cachedPathConfig;
   };
-  const existsPath = async (
-    pathname: string,
-  ): Promise<
-    (
-      | {
-          found: true;
-          isStatic: boolean;
-          noSsr: boolean;
-        }
-      | {
-          found: false;
-        }
-    ) & {
-      has404: boolean;
-    }
-  > => {
+  const getPathConfigItem = async (pathname: string) => {
     const pathConfig = await getMyPathConfig();
     const found = pathConfig.find(({ pathSpec }) =>
       getPathMapping(pathSpec, pathname),
     );
-    const has404 = pathConfig.some(({ specs: { is404 } }) => is404);
-    return found
-      ? {
-          found: true,
-          has404,
-          isStatic: !!found.isStatic,
-          noSsr: !!found.specs.noSsr,
-        }
-      : {
-          found: false,
-          has404,
-        };
+    return found;
+  };
+  const has404 = async () => {
+    const pathConfig = await getMyPathConfig();
+    return pathConfig.some(({ specs: { is404 } }) => is404);
   };
   const filterEffectiveSkip = async (
     pathname: string,
@@ -171,7 +189,7 @@ export function unstable_defineRouter(fns: {
       const found = pathConfig.find(({ pathSpec }) =>
         getPathMapping(pathSpec, pathname),
       );
-      return !!found && found.staticElementIds.includes(slotId);
+      return found?.specs.staticElementIds?.includes(slotId);
     });
   };
   const getEntries = async (
@@ -180,8 +198,8 @@ export function unstable_defineRouter(fns: {
     headers: Readonly<Record<string, string>>,
   ) => {
     const pathname = decodeRoutePath(rscPath);
-    const pathStatus = await existsPath(pathname);
-    if (!pathStatus.found) {
+    const pathConfigItem = await getPathConfigItem(pathname);
+    if (!pathConfigItem) {
       return null;
     }
     let skipParam: unknown;
@@ -192,9 +210,9 @@ export function unstable_defineRouter(fns: {
     }
     const skip = isStringArray(skipParam) ? skipParam : [];
     const { query } = parseRscParams(rscParams);
-    const { routeElement, elements, fallbackElement } = await fns.renderRoute(
+    const { routeElement, elements, fallbackElement } = await fns.handleRoute(
       pathname,
-      pathStatus.isStatic ? {} : { query },
+      pathConfigItem.specs.isStatic ? {} : { query },
     );
     if (
       Object.keys(elements).some((id) => id.startsWith(ROUTE_SLOT_ID_PREFIX))
@@ -213,8 +231,8 @@ export function unstable_defineRouter(fns: {
       delete entries[skipId];
     }
     entries[ROUTE_ID] = [pathname, query];
-    entries[IS_STATIC_ID] = pathStatus.isStatic;
-    if (pathStatus.has404) {
+    entries[IS_STATIC_ID] = !!pathConfigItem.specs.isStatic;
+    if (await has404()) {
       entries[HAS404_ID] = true;
     }
     return entries;
@@ -269,15 +287,22 @@ export function unstable_defineRouter(fns: {
       rendered = true;
       return renderRsc({ ...(await elementsPromise), _value: value });
     }
+    const pathConfigItem = await getPathConfigItem(input.pathname);
+    if (pathConfigItem?.specs?.isApi && fns.handleApi) {
+      return fns.handleApi(input.pathname, {
+        body: input.req.body,
+        headers: input.req.headers,
+        method: input.req.method,
+      });
+    }
     if (input.type === 'action' || input.type === 'custom') {
       let pathname = input.pathname;
       const query = input.req.url.searchParams.toString();
-      const pathStatus = await existsPath(pathname);
-      if (pathStatus.found && pathStatus.noSsr) {
+      if (pathConfigItem?.specs?.noSsr) {
         return null;
       }
-      if (!pathStatus.found) {
-        if (pathStatus.has404) {
+      if (!pathConfigItem) {
+        if (await has404()) {
           pathname = '/404';
         } else {
           return null;
@@ -309,13 +334,28 @@ export function unstable_defineRouter(fns: {
     createAsyncIterable(async (): Promise<Tasks> => {
       const tasks: Tasks = [];
       const pathConfig = await getMyPathConfig();
+
+      for (const { pathname, specs } of pathConfig) {
+        const { handleApi } = fns;
+        if (pathname && specs.isStatic && specs.isApi && handleApi) {
+          tasks.push(async () => ({
+            type: 'file',
+            pathname,
+            body: handleApi(pathname, {
+              body: null,
+              headers: {},
+              method: 'GET',
+            }).then(({ body }) => body || stringToStream('')),
+          }));
+        }
+      }
+
       const path2moduleIds: Record<string, string[]> = {};
       const moduleIdsForPrefetch = new WeakMap<PathSpec, Set<string>>();
       // FIXME this approach keeps all entries in memory during the loop
       const entriesCache = new Map<string, Record<string, ReactNode>>();
-
       await Promise.all(
-        pathConfig.map(async ({ pathSpec, pathname, pattern, isStatic }) => {
+        pathConfig.map(async ({ pathSpec, pathname, pattern, specs }) => {
           const moduleIds = new Set<string>();
           moduleIdsForPrefetch.set(pathSpec, moduleIds);
           if (!pathname) {
@@ -327,7 +367,7 @@ export function unstable_defineRouter(fns: {
             entriesCache.set(pathname, entries);
             path2moduleIds[pattern] =
               await unstable_collectClientModules(entries);
-            if (isStatic) {
+            if (specs.isStatic) {
               tasks.push(async () => ({
                 type: 'file',
                 pathname: rscPath2pathname(rscPath),
@@ -351,7 +391,7 @@ globalThis.__WAKU_ROUTER_PREFETCH__ = (path) => {
   }
 };`;
 
-      for (const { pathSpec, pathname, isStatic, specs } of pathConfig) {
+      for (const { pathSpec, pathname, specs } of pathConfig) {
         tasks.push(async () => {
           const moduleIds = moduleIdsForPrefetch.get(pathSpec)!;
           if (pathname) {
@@ -361,7 +401,7 @@ globalThis.__WAKU_ROUTER_PREFETCH__ = (path) => {
               getRouterPrefetchCode() +
               (specs.is404 ? 'globalThis.__WAKU_ROUTER_404__ = true;' : '');
             const entries = entriesCache.get(pathname);
-            if (isStatic && entries) {
+            if (specs.isStatic && entries) {
               const html = createElement(ServerRouter, {
                 route: { path: pathname, query: '', hash: '' },
               });


Test patch:
diff --git a/e2e/fixtures/define-router/src/entries.tsx b/e2e/fixtures/define-router/src/entries.tsx
index 67f0d764..6f89ba00 100644
--- a/e2e/fixtures/define-router/src/entries.tsx
+++ b/e2e/fixtures/define-router/src/entries.tsx
@@ -14,7 +14,7 @@ const PATH_PAGE: Record<string, ReactNode> = {
 };
 
 const router: ReturnType<typeof defineRouter> = defineRouter({
-  getPathConfig: async () =>
+  getRouteConfig: async () =>
     STATIC_PATHS.map((path) => ({
       pattern: `^${path}$`,
       path: path
@@ -28,7 +28,7 @@ const router: ReturnType<typeof defineRouter> = defineRouter({
         [`page:${path}`]: { isStatic: true },
       },
     })),
-  renderRoute: async (path) => {
+  handleRoute: async (path) => {
     if (!STATIC_PATHS.includes(path)) {
       throw new Error('renderRoute: No such path:' + path);
     }
diff --git a/packages/waku/tests/create-pages.test.ts b/packages/waku/tests/create-pages.test.ts
index b1f52978..aa46a7b7 100644
--- a/packages/waku/tests/create-pages.test.ts
+++ b/packages/waku/tests/create-pages.test.ts
@@ -412,11 +412,11 @@ beforeEach(() => {
 
 function injectedFunctions() {
   expect(defineRouterMock).toHaveBeenCalledTimes(1);
-  assert(defineRouterMock.mock.calls[0]?.[0].getPathConfig);
-  assert(defineRouterMock.mock.calls[0]?.[0].renderRoute);
+  assert(defineRouterMock.mock.calls[0]?.[0].getRouteConfig);
+  assert(defineRouterMock.mock.calls[0]?.[0].handleRoute);
   return {
-    getPathConfig: defineRouterMock.mock.calls[0][0].getPathConfig,
-    renderRoute: defineRouterMock.mock.calls[0][0].renderRoute,
+    getRouteConfig: defineRouterMock.mock.calls[0][0].getRouteConfig,
+    handleRoute: defineRouterMock.mock.calls[0][0].handleRoute,
   };
 }
 
@@ -430,9 +430,9 @@ describe('createPages', () => {
         component: TestPage,
       }),
     ]);
-    const { getPathConfig, renderRoute } = injectedFunctions();
+    const { getRouteConfig, handleRoute } = injectedFunctions();
 
-    expect(await getPathConfig()).toEqual([
+    expect(await getRouteConfig()).toEqual([
       {
         elements: {
           root: { isStatic: true },
@@ -444,7 +444,7 @@ describe('createPages', () => {
       },
     ]);
 
-    const route = await renderRoute('/test', {
+    const route = await handleRoute('/test', {
       query: '?skip=[]',
     });
     expect(route).toBeDefined();
@@ -461,8 +461,8 @@ describe('createPages', () => {
         component: TestPage,
       }),
     ]);
-    const { getPathConfig, renderRoute } = injectedFunctions();
-    expect(await getPathConfig()).toEqual([
+    const { getRouteConfig, handleRoute } = injectedFunctions();
+    expect(await getRouteConfig()).toEqual([
       {
         elements: {
           root: { isStatic: true },
@@ -473,7 +473,7 @@ describe('createPages', () => {
         path: [{ name: 'test', type: 'literal' }],
       },
     ]);
-    const route = await renderRoute('/test', {
+    const route = await handleRoute('/test', {
       query: '?skip=[]',
     });
     expect(route).toBeDefined();
@@ -497,8 +497,8 @@ describe('createPages', () => {
       }),
     ]);
 
-    const { getPathConfig, renderRoute } = injectedFunctions();
-    expect(await getPathConfig()).toEqual([
+    const { getRouteConfig, handleRoute } = injectedFunctions();
+    expect(await getRouteConfig()).toEqual([
       {
         elements: {
           'layout:/': { isStatic: true },
@@ -510,7 +510,7 @@ describe('createPages', () => {
         path: [{ name: 'test', type: 'literal' }],
       },
     ]);
-    const route = await renderRoute('/test', {
+    const route = await handleRoute('/test', {
       query: '?skip=[]',
     });
     expect(route).toBeDefined();
@@ -538,8 +538,8 @@ describe('createPages', () => {
       }),
     ]);
 
-    const { getPathConfig, renderRoute } = injectedFunctions();
-    expect(await getPathConfig()).toEqual([
+    const { getRouteConfig, handleRoute } = injectedFunctions();
+    expect(await getRouteConfig()).toEqual([
       {
         elements: {
           'layout:/': { isStatic: false },
@@ -552,7 +552,7 @@ describe('createPages', () => {
       },
     ]);
 
-    const route = await renderRoute('/test', {
+    const route = await handleRoute('/test', {
       query: '?skip=[]',
     });
     expect(route).toBeDefined();
@@ -573,8 +573,8 @@ describe('createPages', () => {
         component: TestPage,
       }),
     ]);
-    const { getPathConfig, renderRoute } = injectedFunctions();
-    expect(await getPathConfig()).toEqual([
+    const { getRouteConfig, handleRoute } = injectedFunctions();
+    expect(await getRouteConfig()).toEqual([
       {
         elements: {
           root: { isStatic: true },
@@ -588,7 +588,7 @@ describe('createPages', () => {
         ],
       },
     ]);
-    const route = await renderRoute('/test/nested', {
+    const route = await handleRoute('/test/nested', {
       query: '?skip=[]',
     });
     expect(route).toBeDefined();
@@ -610,8 +610,8 @@ describe('createPages', () => {
         component: () => null,
       }),
     ]);
-    const { getPathConfig, renderRoute } = injectedFunctions();
-    expect(await getPathConfig()).toEqual([
+    const { getRouteConfig, handleRoute } = injectedFunctions();
+    expect(await getRouteConfig()).toEqual([
       {
         elements: {
           root: { isStatic: true },
@@ -626,7 +626,7 @@ describe('createPages', () => {
         ],
       },
     ]);
-    const route = await renderRoute('/test/nested', {
+    const route = await handleRoute('/test/nested', {
       query: '?skip=[]',
     });
     expect(route).toBeDefined();
@@ -647,8 +647,8 @@ describe('createPages', () => {
         component: TestPage,
       }),
     ]);
-    const { getPathConfig, renderRoute } = injectedFunctions();
-    expect(await getPathConfig()).toEqual([
+    const { getRouteConfig, handleRoute } = injectedFunctions();
+    expect(await getRouteConfig()).toEqual([
       {
         elements: {
           root: { isStatic: true },
@@ -663,7 +663,7 @@ describe('createPages', () => {
       },
     ]);
 
-    const route = await renderRoute('/test/nested', {
+    const route = await handleRoute('/test/nested', {
       query: '?skip=[]',
     });
     expect(route).toBeDefined();
@@ -684,8 +684,8 @@ describe('createPages', () => {
         component: TestPage,
       }),
     ]);
-    const { getPathConfig, renderRoute } = injectedFunctions();
-    expect(await getPathConfig()).toEqual([
+    const { getRouteConfig, handleRoute } = injectedFunctions();
+    expect(await getRouteConfig()).toEqual([
       {
         elements: {
           root: { isStatic: true },
@@ -723,7 +723,7 @@ describe('createPages', () => {
         ],
       },
     ]);
-    const route = await renderRoute('/test/y/z', {
+    const route = await handleRoute('/test/y/z', {
       query: '?skip=[]',
     });
     expect(route).toBeDefined();
@@ -740,8 +740,8 @@ describe('createPages', () => {
         component: TestPage,
       }),
     ]);
-    const { getPathConfig, renderRoute } = injectedFunctions();
-    expect(await getPathConfig()).toEqual([
+    const { getRouteConfig, handleRoute } = injectedFunctions();
+    expect(await getRouteConfig()).toEqual([
       {
         elements: {
           root: { isStatic: true },
@@ -756,7 +756,7 @@ describe('createPages', () => {
         ],
       },
     ]);
-    const route = await renderRoute('/test/w/x', {
+    const route = await handleRoute('/test/w/x', {
       query: '?skip=[]',
     });
     expect(route).toBeDefined();
@@ -774,8 +774,8 @@ describe('createPages', () => {
         component: TestPage,
       }),
     ]);
-    const { getPathConfig, renderRoute } = injectedFunctions();
-    expect(await getPathConfig()).toEqual([
+    const { getRouteConfig, handleRoute } = injectedFunctions();
+    expect(await getRouteConfig()).toEqual([
       {
         elements: {
           root: { isStatic: true },
@@ -794,7 +794,7 @@ describe('createPages', () => {
         ],
       },
     ]);
-    const route = await renderRoute('/test/a/b', {
+    const route = await handleRoute('/test/a/b', {
       query: '?skip=[]',
     });
     expect(route).toBeDefined();
@@ -811,8 +811,8 @@ describe('createPages', () => {
         component: TestPage,
       }),
     ]);
-    const { getPathConfig, renderRoute } = injectedFunctions();
-    expect(await getPathConfig()).toEqual([
+    const { getRouteConfig, handleRoute } = injectedFunctions();
+    expect(await getRouteConfig()).toEqual([
       {
         elements: {
           root: { isStatic: true },
@@ -826,7 +826,7 @@ describe('createPages', () => {
         ],
       },
     ]);
-    const route = await renderRoute('/test/a/b', {
+    const route = await handleRoute('/test/a/b', {
       query: '?skip=[]',
     });
     expect(route).toBeDefined();
@@ -847,8 +847,8 @@ describe('createPages', () => {
         component: () => null,
       }),
     ]);
-    const { getPathConfig } = injectedFunctions();
-    await expect(getPathConfig).rejects.toThrowError(
+    const { getRouteConfig } = injectedFunctions();
+    await expect(getRouteConfig).rejects.toThrowError(
       'staticPaths does not match with slug pattern',
     );
   });
@@ -868,8 +868,8 @@ describe('createPages', () => {
         unstable_disableSSR: true,
       }),
     ]);
-    const { getPathConfig } = injectedFunctions();
-    expect(await getPathConfig()).toEqual([
+    const { getRouteConfig } = injectedFunctions();
+    expect(await getRouteConfig()).toEqual([
       {
         elements: {
           root: { isStatic: true },
@@ -904,8 +904,8 @@ describe('createPages', () => {
         component: () => null,
       }),
     ]);
-    const { getPathConfig } = injectedFunctions();
-    await expect(getPathConfig).rejects.toThrowError(
+    const { getRouteConfig } = injectedFunctions();
+    await expect(getRouteConfig).rejects.toThrowError(
       'Duplicated dynamic path: /test',
     );
   });
@@ -923,8 +923,8 @@ describe('createPages', () => {
         component: () => null,
       }),
     ]);
-    const { getPathConfig } = injectedFunctions();
-    await expect(getPathConfig).rejects.toThrowError(
+    const { getRouteConfig } = injectedFunctions();
+    await expect(getRouteConfig).rejects.toThrowError(
       'Duplicated component for: test/page',
     );
   });
@@ -944,8 +944,8 @@ describe('createPages', () => {
           component: () => null,
         }),
       ]);
-      const { getPathConfig } = injectedFunctions();
-      await expect(getPathConfig).rejects.toThrowError(
+      const { getRouteConfig } = injectedFunctions();
+      await expect(getRouteConfig).rejects.toThrowError(
         'Duplicated component for: test/page',
       );
     },
@@ -955,9 +955,9 @@ describe('createPages', () => {
     const TestPage = vi.fn();
     complexTestRouter(createPages, TestPage);
 
-    const { getPathConfig, renderRoute } = injectedFunctions();
+    const { getRouteConfig, handleRoute } = injectedFunctions();
 
-    expect(await getPathConfig()).toEqual([
+    expect(await getRouteConfig()).toEqual([
       {
         elements: {
           root: { isStatic: true },
@@ -1170,7 +1170,7 @@ describe('createPages', () => {
         ],
       },
     ]);
-    const route = await renderRoute('/server/two/a/b', {
+    const route = await handleRoute('/server/two/a/b', {
       query: '?skip=[]',
     });
     assert(route);