|
| 1 | +import os from "node:os"; |
1 | 2 | import path from "node:path";
|
2 |
| -import { mkdirSync, rmdirSync, createFileSync, rmSync } from "fs-extra"; |
| 3 | +import fse from "fs-extra"; |
3 | 4 |
|
4 | 5 | import type { RouteManifestEntry } from "../manifest";
|
5 | 6 |
|
@@ -880,27 +881,35 @@ describe("flatRoutes", () => {
|
880 | 881 | });
|
881 | 882 | });
|
882 | 883 |
|
883 |
| - describe("throw correct error", () => { |
| 884 | + describe("throws expected errors", () => { |
| 885 | + let tempDir = path.join( |
| 886 | + os.tmpdir(), |
| 887 | + "react-router-fs-routes-test", |
| 888 | + Math.random().toString(36).substring(2, 15) |
| 889 | + ); |
| 890 | + |
884 | 891 | beforeEach(() => {
|
885 |
| - mkdirSync(APP_DIR, { recursive: true }); |
| 892 | + fse.mkdirSync(tempDir, { recursive: true }); |
886 | 893 | });
|
887 | 894 | afterEach(() => {
|
888 |
| - rmdirSync(APP_DIR); |
| 895 | + fse.rmSync(tempDir, { recursive: true, force: true }); |
889 | 896 | });
|
890 | 897 |
|
891 | 898 | test("root route is not found", () => {
|
892 |
| - expect(() => flatRoutes(APP_DIR)).toThrow( |
893 |
| - `Could not find a root route module in the app directory: test/root/app` |
| 899 | + expect(() => flatRoutes(tempDir)).toThrow( |
| 900 | + `Could not find a root route module in the app directory: ${tempDir}` |
894 | 901 | );
|
895 | 902 | });
|
896 | 903 |
|
897 | 904 | test("routes dir is not found", () => {
|
898 |
| - const rootRoute = path.join(APP_DIR, "root.tsx"); |
899 |
| - createFileSync(rootRoute); |
900 |
| - expect(() => flatRoutes(APP_DIR)).toThrow( |
901 |
| - `Could not find the routes directory: test/root/app/routes. Did you forget to create it?` |
| 905 | + const rootRoute = path.join(tempDir, "root.tsx"); |
| 906 | + fse.createFileSync(rootRoute); |
| 907 | + expect(() => flatRoutes(tempDir)).toThrow( |
| 908 | + `Could not find the routes directory: ${path.join( |
| 909 | + tempDir, |
| 910 | + "routes" |
| 911 | + )}. Did you forget to create it?` |
902 | 912 | );
|
903 |
| - rmSync(rootRoute); |
904 | 913 | });
|
905 | 914 | });
|
906 | 915 | });
|
0 commit comments