diff --git a/packages/remix-dev/__tests__/flat-routes-test.ts b/packages/remix-dev/__tests__/flat-routes-test.ts index f4596acf014..5b9bb523a85 100644 --- a/packages/remix-dev/__tests__/flat-routes-test.ts +++ b/packages/remix-dev/__tests__/flat-routes-test.ts @@ -92,15 +92,46 @@ describe("flatRoutes", () => { }); } - let invalidRoutes = [ + let invalidSlashFiles = [ "($[$dollabills]).([.]lol)[/](what)/([$]).$", "$[$dollabills].[.]lol[/]what/[$].$", ]; - for (let invalid of invalidRoutes) { - expect(() => getRouteSegments(invalid)).toThrow( - "Route segment cannot contain a slash" - ); + for (let invalid of invalidSlashFiles) { + test("should error when using `/` in a route segment", () => { + let regex = new RegExp( + /Route segment (".*?") for (".*?") cannot contain "\/"/ + ); + expect(() => getRouteSegments(invalid)).toThrow(regex); + }); + } + + let invalidSplatFiles: string[] = [ + "routes/about.[*].tsx", + "routes/about.*.tsx", + ]; + + for (let invalid of invalidSplatFiles) { + test("should error when using `*` in a route segment", () => { + let regex = new RegExp( + /Route segment (".*?") for (".*?") cannot contain "\*"/ + ); + expect(() => getRouteSegments(invalid)).toThrow(regex); + }); + } + + let invalidParamFiles: string[] = [ + "routes/about.[:name].tsx", + "routes/about.:name.tsx", + ]; + + for (let invalid of invalidParamFiles) { + test("should error when using `:` in a route segment", () => { + let regex = new RegExp( + /Route segment (".*?") for (".*?") cannot contain ":"/ + ); + expect(() => getRouteSegments(invalid)).toThrow(regex); + }); } }); @@ -582,46 +613,4 @@ describe("flatRoutes", () => { }); } }); - - let invalidSlashFiles: string[] = [ - "routes/($[$dollabills]).([.]lol)[/](what)/([$]).$.tsx", - ]; - - for (let file of invalidSlashFiles) { - test("should error when using `/` in a route segment", () => { - expect(() => - flatRoutesUniversal(APP_DIR, [path.join(APP_DIR, file)]) - ).toThrowError(`Route segment cannot contain a slash`); - }); - } - - let invalidSplatFiles: string[] = [ - "routes/about.[*].tsx", - "routes/about.*.tsx", - ]; - - for (let file of invalidSplatFiles) { - test("should error when using `*` in a route segment", () => { - expect(() => - flatRoutesUniversal(APP_DIR, [path.join(APP_DIR, file)]) - ).toThrowError( - `Route segment for "${path.parse(file).name}" cannot contain "*"` - ); - }); - } - - let invalidParamFiles: string[] = [ - "routes/about.[:name].tsx", - "routes/about.:name.tsx", - ]; - - for (let file of invalidParamFiles) { - test("should error when using `:` in a route segment", () => { - expect(() => - flatRoutesUniversal(APP_DIR, [path.join(APP_DIR, file)]) - ).toThrowError( - `Route segment for "${path.parse(file).name}" cannot contain ":"` - ); - }); - } }); diff --git a/packages/remix-dev/config/flat-routes.ts b/packages/remix-dev/config/flat-routes.ts index 641ab08f3d2..089f62ac91e 100644 --- a/packages/remix-dev/config/flat-routes.ts +++ b/packages/remix-dev/config/flat-routes.ts @@ -127,16 +127,20 @@ export function getRouteSegments(routeId: string) { if (!routeSegment) return; if (rawRouteSegment === "*") { - throw new Error(`Route segment for "${routeId}" cannot contain "*"`); + throw new Error( + `Route segment "${rawRouteSegment}" for "${routeId}" cannot contain "*"` + ); } if (rawRouteSegment.includes(":")) { - throw new Error(`Route segment for "${routeId}" cannot contain ":"`); + throw new Error( + `Route segment "${rawRouteSegment}" for "${routeId}" cannot contain ":"` + ); } if (rawRouteSegment.includes("/")) { throw new Error( - `Route segment cannot contain a slash: ${routeSegment} (in route ${routeId})` + `Route segment "${routeSegment}" for "${routeId}" cannot contain "/"` ); } routeSegments.push(routeSegment);