Skip to content

Commit f0145cc

Browse files
test(fs-routes): Write test files to temp dir (#12446)
1 parent d816819 commit f0145cc

File tree

1 file changed

+20
-11
lines changed

1 file changed

+20
-11
lines changed

packages/react-router-fs-routes/__tests__/flatRoutes-test.ts

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1+
import os from "node:os";
12
import path from "node:path";
2-
import { mkdirSync, rmdirSync, createFileSync, rmSync } from "fs-extra";
3+
import fse from "fs-extra";
34

45
import type { RouteManifestEntry } from "../manifest";
56

@@ -880,27 +881,35 @@ describe("flatRoutes", () => {
880881
});
881882
});
882883

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+
884891
beforeEach(() => {
885-
mkdirSync(APP_DIR, { recursive: true });
892+
fse.mkdirSync(tempDir, { recursive: true });
886893
});
887894
afterEach(() => {
888-
rmdirSync(APP_DIR);
895+
fse.rmSync(tempDir, { recursive: true, force: true });
889896
});
890897

891898
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}`
894901
);
895902
});
896903

897904
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?`
902912
);
903-
rmSync(rootRoute);
904913
});
905914
});
906915
});

0 commit comments

Comments
 (0)