Skip to content

Commit c69ff0e

Browse files
committed
href typegen tests
1 parent 67b2728 commit c69ff0e

File tree

4 files changed

+52
-13
lines changed

4 files changed

+52
-13
lines changed

integration/helpers/vite-5-template/tsconfig.json

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
11
{
2-
"include": [
3-
"env.d.ts",
4-
"**/*.ts",
5-
"**/*.tsx",
6-
".react-router/types/**/*.d.ts"
7-
],
2+
"include": ["env.d.ts", "**/*.ts", "**/*.tsx", ".react-router/types/**/*"],
83
"compilerOptions": {
94
"lib": ["DOM", "DOM.Iterable", "ES2022"],
105
"verbatimModuleSyntax": true,

integration/helpers/vite-6-template/tsconfig.json

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
11
{
2-
"include": [
3-
"env.d.ts",
4-
"**/*.ts",
5-
"**/*.tsx",
6-
".react-router/types/**/*.d.ts"
7-
],
2+
"include": ["env.d.ts", "**/*.ts", "**/*.tsx", ".react-router/types/**/*"],
83
"compilerOptions": {
94
"lib": ["DOM", "DOM.Iterable", "ES2022"],
105
"verbatimModuleSyntax": true,

integration/helpers/vite-cloudflare-template/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"include": ["env.d.ts", "**/*.ts", "**/*.tsx"],
2+
"include": ["env.d.ts", "**/*.ts", "**/*.tsx", ".react-router/types/**/*"],
33
"compilerOptions": {
44
"lib": ["DOM", "DOM.Iterable", "ES2022"],
55
"types": ["vite/client"],

integration/typegen-test.ts

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -388,4 +388,53 @@ test.describe("typegen", () => {
388388
expect(proc.stderr.toString()).toBe("");
389389
expect(proc.status).toBe(0);
390390
});
391+
392+
test("href", async () => {
393+
const cwd = await createProject({
394+
"vite.config.ts": viteConfig,
395+
"app/expect-type.ts": expectType,
396+
"app/routes.ts": tsx`
397+
import path from "node:path";
398+
import { type RouteConfig, route } from "@react-router/dev/routes";
399+
400+
export default [
401+
route("no-params", "routes/no-params.tsx"),
402+
route("required-param/:req", "routes/required-param.tsx"),
403+
route("optional-param/:opt?", "routes/optional-param.tsx"),
404+
route("some-other-route", "routes/some-other-route.tsx"),
405+
] satisfies RouteConfig;
406+
`,
407+
"app/routes/no-params.tsx": tsx`
408+
export default function Component() {}
409+
`,
410+
"app/routes/required-param.tsx": tsx`
411+
export default function Component() {}
412+
`,
413+
"app/routes/optional-param.tsx": tsx`
414+
export default function Component() {}
415+
`,
416+
"app/routes/some-other-route.tsx": tsx`
417+
import { href } from "react-router"
418+
419+
// @ts-expect-error
420+
href("/does-not-exist")
421+
422+
href("/no-params")
423+
424+
// @ts-expect-error
425+
href("/required-param/:req")
426+
href("/required-param/:req", { req: "hello" })
427+
428+
href("/optional-param/:opt?")
429+
href("/optional-param/:opt?", { opt: "hello" })
430+
431+
export default function Component() {}
432+
`,
433+
});
434+
console.log({ cwd });
435+
const proc = typecheck(cwd);
436+
expect(proc.stdout.toString()).toBe("");
437+
expect(proc.stderr.toString()).toBe("");
438+
expect(proc.status).toBe(0);
439+
});
391440
});

0 commit comments

Comments
 (0)