-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move
/dev/routes
API to route-config
package
- Loading branch information
1 parent
3a48dfe
commit c54c443
Showing
20 changed files
with
533 additions
and
330 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
141 changes: 141 additions & 0 deletions
141
packages/remix-dev/__tests__/validateRouteConfig-test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,141 @@ | ||
import { validateRouteConfig } from "../config/routes"; | ||
|
||
describe("validateRouteConfig", () => { | ||
it("validates a route config", () => { | ||
expect( | ||
validateRouteConfig({ | ||
routeConfigFile: "routes.ts", | ||
routeConfig: [ | ||
{ | ||
path: "parent", | ||
file: "parent.tsx", | ||
children: [ | ||
{ | ||
path: "child", | ||
file: "child.tsx", | ||
}, | ||
], | ||
}, | ||
], | ||
}).valid | ||
).toBe(true); | ||
}); | ||
|
||
it("is invalid when not an array", () => { | ||
let result = validateRouteConfig({ | ||
routeConfigFile: "routes.ts", | ||
routeConfig: { path: "path", file: "file.tsx" }, | ||
}); | ||
|
||
expect(result.valid).toBe(false); | ||
expect(!result.valid && result.message).toMatchInlineSnapshot( | ||
`"Route config in "routes.ts" must be an array."` | ||
); | ||
}); | ||
|
||
it("is invalid when route is a promise", () => { | ||
let result = validateRouteConfig({ | ||
routeConfigFile: "routes.ts", | ||
routeConfig: [ | ||
{ | ||
path: "parent", | ||
file: "parent.tsx", | ||
children: [Promise.resolve({})], | ||
}, | ||
], | ||
}); | ||
|
||
expect(result.valid).toBe(false); | ||
expect(!result.valid && result.message).toMatchInlineSnapshot(` | ||
"Route config in "routes.ts" is invalid. | ||
Path: routes.0.children.0 | ||
Invalid type: Expected object but received a promise. Did you forget to await?" | ||
`); | ||
}); | ||
|
||
it("is invalid when file is missing", () => { | ||
let result = validateRouteConfig({ | ||
routeConfigFile: "routes.ts", | ||
routeConfig: [ | ||
{ | ||
path: "parent", | ||
file: "parent.tsx", | ||
children: [ | ||
{ | ||
id: "child", | ||
}, | ||
], | ||
}, | ||
], | ||
}); | ||
|
||
expect(result.valid).toBe(false); | ||
expect(!result.valid && result.message).toMatchInlineSnapshot(` | ||
"Route config in "routes.ts" is invalid. | ||
Path: routes.0.children.0.file | ||
Invalid type: Expected string but received undefined" | ||
`); | ||
}); | ||
|
||
it("is invalid when property is wrong type", () => { | ||
let result = validateRouteConfig({ | ||
routeConfigFile: "routes.ts", | ||
routeConfig: [ | ||
{ | ||
path: "parent", | ||
file: "parent.tsx", | ||
children: [ | ||
{ | ||
file: 123, | ||
}, | ||
], | ||
}, | ||
], | ||
}); | ||
|
||
expect(result.valid).toBe(false); | ||
expect(!result.valid && result.message).toMatchInlineSnapshot(` | ||
"Route config in "routes.ts" is invalid. | ||
Path: routes.0.children.0.file | ||
Invalid type: Expected string but received 123" | ||
`); | ||
}); | ||
|
||
it("shows multiple error messages", () => { | ||
let result = validateRouteConfig({ | ||
routeConfigFile: "routes.ts", | ||
routeConfig: [ | ||
{ | ||
path: "parent", | ||
file: "parent.tsx", | ||
children: [ | ||
{ | ||
id: "child", | ||
}, | ||
{ | ||
file: 123, | ||
}, | ||
Promise.resolve(), | ||
], | ||
}, | ||
], | ||
}); | ||
|
||
expect(result.valid).toBe(false); | ||
expect(!result.valid && result.message).toMatchInlineSnapshot(` | ||
"Route config in "routes.ts" is invalid. | ||
Path: routes.0.children.0.file | ||
Invalid type: Expected string but received undefined | ||
Path: routes.0.children.1.file | ||
Invalid type: Expected string but received 123 | ||
Path: routes.0.children.2 | ||
Invalid type: Expected object but received a promise. Did you forget to await?" | ||
`); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.