Skip to content

Commit e2ce65a

Browse files
committed
fix: fileRoute unit test
1 parent 324202b commit e2ce65a

1 file changed

Lines changed: 82 additions & 10 deletions

File tree

‎packages/solid-router/tests/fileRoute.test-d.tsx‎

Lines changed: 82 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,53 @@
11
import { expectTypeOf, test } from 'vitest'
2-
import '../../start-client-core/src/serverRoute'
32
import { createFileRoute, createRootRoute } from '../src'
4-
import { createMiddleware } from '../../start-client-core/src/createMiddleware'
3+
import type { Route } from '@tanstack/router-core'
4+
5+
declare module '@tanstack/router-core' {
6+
interface FilebaseRouteOptionsInterface<
7+
TRegister,
8+
TParentRoute,
9+
TId,
10+
TPath,
11+
TSearchValidator,
12+
TParams,
13+
TLoaderDeps,
14+
TLoaderFn,
15+
TRouterContext,
16+
TRouteContextFn,
17+
TBeforeLoadFn,
18+
TRemountDepsFn,
19+
TSSR,
20+
TServerMiddlewares,
21+
THandlers,
22+
> {
23+
server?: {
24+
middleware?: TServerMiddlewares
25+
}
26+
}
27+
28+
interface RouteTypes<
29+
TRegister,
30+
TParentRoute,
31+
TPath,
32+
TFullPath,
33+
TCustomId,
34+
TId,
35+
TSearchValidator,
36+
TParams,
37+
TRouterContext,
38+
TRouteContextFn,
39+
TBeforeLoadFn,
40+
TLoaderDeps,
41+
TLoaderFn,
42+
TChildren,
43+
TFileRouteTypes,
44+
TSSR,
45+
TServerMiddlewares,
46+
THandlers,
47+
> {
48+
middleware: TServerMiddlewares
49+
}
50+
}
551

652
const rootRoute = createRootRoute()
753

@@ -103,23 +149,49 @@ test('when creating a folder group', () => {
103149
expectTypeOf<'/protected'>(protectedRoute.id)
104150
})
105151

152+
<<<<<<< Updated upstream
106153
test('when creating a file route with server middleware', () => {
107154
const middleware = createMiddleware({ type: 'request' }).server(
108155
({ next }) => {
109156
return next({ context: { supportsGzip: true } })
110157
},
111158
)
159+
=======
160+
test('when creating a file route with middleware options', () => {
161+
type Middleware = { readonly middleware: 'middleware' }
162+
const middleware = { middleware: 'middleware' } as const
163+
>>>>>>> Stashed changes
112164

113-
createFileRoute('/invoices')({
165+
const route = createFileRoute('/invoices')({
114166
server: {
115167
middleware: [middleware],
116-
handlers: {
117-
GET: ({ context }) => {
118-
expectTypeOf(context).toEqualTypeOf<{ supportsGzip: boolean }>()
119-
120-
return Response.json(context)
121-
},
122-
},
123168
},
124169
})
170+
171+
type ExtractMiddlewares<TRoute> = TRoute extends Route<
172+
any,
173+
any,
174+
any,
175+
any,
176+
any,
177+
any,
178+
any,
179+
any,
180+
any,
181+
any,
182+
any,
183+
any,
184+
any,
185+
any,
186+
any,
187+
any,
188+
infer TMiddlewares,
189+
any
190+
>
191+
? TMiddlewares
192+
: never
193+
194+
expectTypeOf<ExtractMiddlewares<typeof route>>().toEqualTypeOf<
195+
readonly [Middleware]
196+
>()
125197
})

0 commit comments

Comments
 (0)