|
| 1 | +import { describe, it, expect } from "bun:test"; |
| 2 | +import { join } from "path"; |
| 3 | +import { cwd } from "process"; |
| 4 | +import ScanPaths from "src/utils/ScanPaths"; |
| 5 | + |
| 6 | +const root = join(cwd(), "__tests__", "routes"); |
| 7 | + |
| 8 | +describe("Route mapper tests", () => { |
| 9 | + it("will recursively fetch the paths of files inside the 'routes' folder", async () => { |
| 10 | + const paths: Array<RoutePath> = [ |
| 11 | + { AbsolutePath: "messages.ts", FullPath: root + "/messages.ts", EffectiveRoute: "messages", }, |
| 12 | + { AbsolutePath: "messages/[id].ts", FullPath: root + "/messages/[id].ts", EffectiveRoute: "messages/[id]" }, |
| 13 | + { AbsolutePath: "messages/new_message.ts", FullPath: root + "/messages/new_message.ts", EffectiveRoute: "messages/new_message" }, |
| 14 | + { AbsolutePath: "user/[user]/[likes].ts", FullPath: root + "/user/[user]/[likes].ts", EffectiveRoute: "user/[user]/[likes]" }, |
| 15 | + { AbsolutePath: "user/[user].ts", FullPath: root + "/user/[user].ts", EffectiveRoute: "user/[user]" } |
| 16 | + ]; |
| 17 | + |
| 18 | + const routePaths = await ScanPaths(root, ""); |
| 19 | + |
| 20 | + expect(JSON.stringify(routePaths)).toBe(JSON.stringify(paths)); |
| 21 | + |
| 22 | + expect(routePaths.length).toBe(5); |
| 23 | + |
| 24 | + for (let x = 0; x < paths.length; x++) { |
| 25 | + expect(routePaths[x].FullPath).toBe(paths[x].FullPath); |
| 26 | + } |
| 27 | + |
| 28 | + for (let x = 0; x < paths.length; x++) { |
| 29 | + expect(routePaths[x].AbsolutePath).toBe(paths[x].AbsolutePath); |
| 30 | + } |
| 31 | + }); |
| 32 | +}); |
0 commit comments