Skip to content

Commit 9fb98fe

Browse files
authored
typegen: custom app dir test (#12236)
* refactor tests * typegen: simplify vite.config.ts for tests * typegen: add test for custom app dir
1 parent 72220e2 commit 9fb98fe

File tree

1 file changed

+60
-27
lines changed

1 file changed

+60
-27
lines changed

integration/typegen-test.ts

Lines changed: 60 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import { spawnSync } from "node:child_process";
2+
import * as path from "node:path";
23

34
import { expect, test } from "@playwright/test";
45
import dedent from "dedent";
6+
import fse from "fs-extra";
57

68
import { createProject } from "./helpers/vite";
79

@@ -22,13 +24,9 @@ function typecheck(cwd: string) {
2224

2325
const viteConfig = tsx`
2426
import { reactRouter } from "@react-router/dev/vite";
25-
import tsconfigPaths from "vite-tsconfig-paths";
2627
2728
export default {
28-
plugins: [
29-
reactRouter(),
30-
tsconfigPaths()
31-
],
29+
plugins: [reactRouter()],
3230
};
3331
`;
3432

@@ -59,24 +57,46 @@ test.describe("typegen", () => {
5957
expect(proc.status).toBe(0);
6058
});
6159

62-
test("repeated param", async () => {
63-
const cwd = await createProject({
64-
"vite.config.ts": viteConfig,
65-
"app/routes/repeated.$id.($id).$id.tsx": tsx`
66-
import type { Route } from "./+types.repeated.$id.($id).$id"
67-
68-
function assertType<T>(t: T) {}
60+
test.describe("params", () => {
61+
test("repeated", async () => {
62+
const cwd = await createProject({
63+
"vite.config.ts": viteConfig,
64+
"app/routes/repeated.$id.($id).$id.tsx": tsx`
65+
import type { Route } from "./+types.repeated.$id.($id).$id"
66+
67+
function assertType<T>(t: T) {}
68+
69+
export function loader({ params }: Route.LoaderArgs) {
70+
assertType<[string, string | undefined, string]>(params.id)
71+
return null
72+
}
73+
`,
74+
});
75+
const proc = typecheck(cwd);
76+
expect(proc.stdout.toString()).toBe("");
77+
expect(proc.stderr.toString()).toBe("");
78+
expect(proc.status).toBe(0);
79+
});
6980

70-
export function loader({ params }: Route.LoaderArgs) {
71-
assertType<[string, string | undefined, string]>(params.id)
72-
return null
73-
}
74-
`,
81+
test("splat", async () => {
82+
const cwd = await createProject({
83+
"vite.config.ts": viteConfig,
84+
"app/routes/splat.$.tsx": tsx`
85+
import type { Route } from "./+types.splat.$"
86+
87+
function assertType<T>(t: T) {}
88+
89+
export function loader({ params }: Route.LoaderArgs) {
90+
assertType<string>(params["*"])
91+
return null
92+
}
93+
`,
94+
});
95+
const proc = typecheck(cwd);
96+
expect(proc.stdout.toString()).toBe("");
97+
expect(proc.stderr.toString()).toBe("");
98+
expect(proc.status).toBe(0);
7599
});
76-
const proc = typecheck(cwd);
77-
expect(proc.stdout.toString()).toBe("");
78-
expect(proc.stderr.toString()).toBe("");
79-
expect(proc.status).toBe(0);
80100
});
81101

82102
test("clientLoader.hydrate = true", async () => {
@@ -112,20 +132,33 @@ test.describe("typegen", () => {
112132
expect(proc.status).toBe(0);
113133
});
114134

115-
test("splat", async () => {
135+
test("custom app dir", async () => {
116136
const cwd = await createProject({
117-
"vite.config.ts": viteConfig,
118-
"app/routes/splat.$.tsx": tsx`
119-
import type { Route } from "./+types.splat.$"
137+
"vite.config.ts": tsx`
138+
import { reactRouter } from "@react-router/dev/vite";
139+
140+
export default {
141+
plugins: [reactRouter({ appDirectory: "src/myapp" })],
142+
};
143+
`,
144+
"app/routes/products.$id.tsx": tsx`
145+
import type { Route } from "./+types.products.$id"
120146
121147
function assertType<T>(t: T) {}
122148
123149
export function loader({ params }: Route.LoaderArgs) {
124-
assertType<string>(params["*"])
125-
return null
150+
assertType<string>(params.id)
151+
return { planet: "world" }
152+
}
153+
154+
export default function Component({ loaderData }: Route.ComponentProps) {
155+
assertType<string>(loaderData.planet)
156+
return <h1>Hello, {loaderData.planet}!</h1>
126157
}
127158
`,
128159
});
160+
fse.moveSync(path.join(cwd, "app"), path.join(cwd, "src/myapp"));
161+
129162
const proc = typecheck(cwd);
130163
expect(proc.stdout.toString()).toBe("");
131164
expect(proc.stderr.toString()).toBe("");

0 commit comments

Comments
 (0)