Open History to see the last commit
1import { expect, test } from 'vitest'
2β
3// keeping this dummy test in since in the future
4// we may want to grab the commented out tests from here
5β
6test('index true=true', () => {
7 expect(true).toBe(true)
8})
9// import { render } from '@solidjs/testing-library'
10β
11// import * as Solid from 'solid-js'
12β
13// import {
14// Outlet,
15// RouterProvider,
16// cleanPath,
17// createMemoryHistory,
18// createRootRoute,
19// createRoute,
20// createRouter,
21// // Location,
22// matchPathname,
23// // ParsedLocation,
24// parsePathname,
25// redirect,
26// // Route,
27// // createMemoryHistory,
28// resolvePath,
29// // Segment,
30// trimPath,
31// trimPathLeft,
32// } from '../src'
33β
34// import { createTimer, sleep } from './utils'
35β
36// function RouterInstance(opts?: { initialEntries?: string[] }) {
37// return new RouterInstance({
38// routes: [],
39// history: createMemoryHistory({
40// initialEntries: opts?.initialEntries ?? ['/'],
41// }),
42// })
43// }
44β
45// function createLocation(location: Partial<Location>): ParsedLocation {
46// return {
47// pathname: '',
48// href: '',
49// search: {},
50// searchStr: '',
51// state: {},
52// hash: '',
53// ...location,
54// }
55// }
56β
57// describe('Router', () => {
58// test('mounts to /', async () => {
59// const router = RouterInstance()
60β
61// const routes = [
62// {
63// path: '/',
64// },
65// ]
66β
67// router.update({
68// routes,
69// })
70β
71// const promise = router.mount()
72// expect(router.store.pendingMatches[0].id).toBe('/')
73β
74// await promise
75// expect(router.state.matches[0].id).toBe('/')
76// })
77β
78// test('mounts to /a', async () => {
79// const router = RouterInstance({ initialEntries: ['/a'] })
80// const routes: Route[] = [
81// {
82// path: '/',
83// },
84// {
85// path: '/a',
86// },
87// ]
88β
89// router.update({
90// routes,
91// })
92β
93// let promise = router.mount()
94β
95// expect(router.store.pendingMatches[0].id).toBe('/a')
96// await promise
97// expect(router.state.matches[0].id).toBe('/a')
98// })
99β
100// test('mounts to /a/b', async () => {
101// const router = RouterInstance({
102// initialEntries: ['/a/b'],
103// })
104β
105// const routes: Route[] = [
106// {
107// path: '/',
108// },
109// {
110// path: '/a',
111// children: [
112// {
113// path: '/b',
114// },
115// ],
116// },
117// ]
118β
119// router.update({
120// routes,
121// })
122β
123// let promise = router.mount()
124β
125// expect(router.store.pendingMatches[1].id).toBe('/a/b')
126// await promise
127// expect(router.state.matches[1].id).toBe('/a/b')
128// })
129β
130// test('navigates to /a', async () => {
131// const router = RouterInstance()
132// const routes: Route[] = [
133// {
134// path: '/',
135// },
136// {
137// path: 'a',
138// },
139// ]
140β
141// router.update({
142// routes,
143// })
144β
145// let promise = router.mount()
146β
147// expect(router.store.pendingMatches[0].id).toBe('/')
148β
149// await promise
150// expect(router.state.matches[0].id).toBe('/')
151β
152// promise = router.navigate({ to: 'a' })
153// expect(router.state.matches[0].id).toBe('/')
154// expect(router.store.pendingMatches[0].id).toBe('a')
155β
156// await promise
157// expect(router.state.matches[0].id).toBe('a')
158// expect(router.store.pending).toBe(undefined)
159// })
160β
161// test('navigates to /a to /a/b', async () => {
162// const router = RouterInstance()
163// const routes: Route[] = [
164// {
165// path: '/',
166// },
167// {
168// path: 'a',
169// children: [
170// {
171// path: 'b',
172// },
173// ],
174// },
175// ]
176β
177// router.update({
178// routes,
179// })
180β
181// await router.mount()
182// expect(router.state.location.href).toBe('/')
183β
184// let promise = router.navigate({ to: 'a' })
185// expect(router.store.pendingLocation.href).toBe('/a')
186// await promise
187// expect(router.state.location.href).toBe('/a')
188β
189// promise = router.navigate({ to: './b' })
190// expect(router.store.pendingLocation.href).toBe('/a/b')
191// await promise
192// expect(router.state.location.href).toBe('/a/b')
193β
194// expect(router.store.pending).toBe(undefined)
195// })
196β
197// test('async navigates to /a/b', async () => {
198// const router = RouterInstance()
199// const routes: Route[] = [
200// {
201// path: '/',
202// },
203// {
204// path: 'a',
205// loader: () => sleep(10).then((d) => ({ a: true })),
206// children: [
207// {
208// path: 'b',
209// loader: () => sleep(10).then((d) => ({ b: true })),
210// },
211// ],
212// },
213// ]
214β
215// const timer = createTimer()
216β
217// router.update({
218// routes,
219// })
220β
221// router.mount()
222β
223// timer.start()
224// await router.navigate({ to: 'a/b' })
225// expect(router.store.loaderData).toEqual({
226// a: true,
227// b: true,
228// })
229// expect(timer.getTime()).toBeLessThan(30)
230// })
231β
232// test('async navigates with import + loader', async () => {
233// const router = RouterInstance()
234// const routes: Route[] = [
235// {
236// path: '/',
237// },
238// {
239// path: 'a',
240// import: async () => {
241// await sleep(10)
242// return {
243// loader: () => sleep(10).then((d) => ({ a: true })),
244// }
245// },
246// children: [
247// {
248// path: 'b',
249// import: async () => {
250// await sleep(10)
251// return {
252// loader: () =>
253// sleep(10).then((d) => ({
254// b: true,
255// })),
256// }
257// },
258// },
259// ],
260// },
261// ]
262β
263// const timer = createTimer()
264β
265// router.update({
266// routes,
267// })
268β
269// router.mount()
270β
271// timer.start()
272// await router.navigate({ to: 'a/b' })
273// expect(router.store.loaderData).toEqual({
274// a: true,
275// b: true,
276// })
277// expect(timer.getTime()).toBeLessThan(28)
278// })
279β
280// test('async navigates with import + elements + loader', async () => {
281// const router = RouterInstance()
282// const routes: Route[] = [
283// {
284// path: '/',
285// },
286// {
287// path: 'a',
288// import: async () => {
289// await sleep(10)
290// return {
291// element: async () => {
292// await sleep(20)
293// return 'element'
294// },
295// loader: () => sleep(30).then((d) => ({ a: true })),
296// }
297// },
298// children: [
299// {
300// path: 'b',
301// import: async () => {
302// await sleep(10)
303// return {
304// element: async () => {
305// await sleep(20)
306// return 'element'
307// },
308// loader: () =>
309// sleep(30).then((d) => ({
310// b: true,
311// })),
312// }
313// },
314// },
315// ],
316// },
317// ]
318β
319// const timer = createTimer()
320β
321// router.update({
322// routes,
323// })
324β
325// router.mount()
326β
327// await router.navigate({ to: 'a/b' })
328// expect(router.store.loaderData).toEqual({
329// a: true,
330// b: true,
331// })
332// expect(timer.getTime()).toBeLessThan(55)
333// })
334β
335// test('async navigates with pending state', async () => {
336// const router = RouterInstance()
337// const routes: Route[] = [
338// {
339// path: '/',
340// },
341// {
342// path: 'a',
343// pendingMs: 10,
344// loader: () => sleep(20),
345// children: [
346// {
347// path: 'b',
348// pendingMs: 30,
349// loader: () => sleep(40),
350// },
351// ],
352// },
353// ]
354β
355// router.update({
356// routes,
357// })
358β
359// await router.mount()
360β
361// const timer = createTimer()
362// await router.navigate({ to: 'a/b' })
363// expect(timer.getTime()).toBeLessThan(46)
364// })
365// })
366β
367// describe('matchRoute', () => {
368// describe('fuzzy', () => {
369// ;(
370// [
371// [
372// '/',
373// {
374// to: '/',
375// fuzzy: true,
376// },
377// {},
378// ],
379// [
380// '/a',
381// {
382// to: '/',
383// fuzzy: true,
384// },
385// {},
386// ],
387// [
388// '/a',
389// {
390// to: '/$',
391// fuzzy: true,
392// },
393// { '*': 'a' },
394// ],
395// [
396// '/a/b',
397// {
398// to: '/$',
399// fuzzy: true,
400// },
401// { '*': 'a/b' },
402// ],
403// [
404// '/a/b/c',
405// {
406// to: '/$',
407// fuzzy: true,
408// },
409// { '*': 'a/b/c' },
410// ],
411// [
412// '/a/b/c',
413// {
414// to: '/',
415// fuzzy: true,
416// },
417// {},
418// ],
419// [
420// '/a/b',
421// {
422// to: '/a/b/',
423// fuzzy: true,
424// },
425// {},
426// ],
427// ] as const
428// ).forEach(([a, b, eq]) => {
429// test(`${a} == ${b.to}`, () => {
430// expect(matchPathname('', a, b)).toEqual(eq)
431// })
432// })
433// })
434β
435// describe('exact', () => {
436// ;(
437// [
438// [
439// '/a/b/c',
440// {
441// to: '/',
442// },
443// undefined,
444// ],
445// [
446// '/a/b/c',
447// {
448// to: '/a/b',
449// },
450// undefined,
451// ],
452// [
453// '/a/b/c',
454// {
455// to: '/a/b/c',
456// },
457// {},
458// ],
459// ] as const
460// ).forEach(([a, b, eq]) => {
461// test(`${a} == ${b.to}`, () => {
462// expect(matchPathname('', a, b)).toEqual(eq)
463// })
464// })
465// })
466β
467// describe('basepath', () => {
468// ;(
469// [
470// [
471// '/base',
472// '/base',
473// {
474// to: '/',
475// },
476// {},
477// ],
478// [
479// '/base',
480// '/base/a',
481// {
482// to: '/a',
483// },
484// {},
485// ],
486// [
487// '/base',
488// '/base/a/b/c',
489// {
490// to: '/a/b/c',
491// },
492// {},
493// ],
494// [
495// '/base',
496// '/base/posts',
497// {
498// fuzzy: true,
499// to: '/',
500// },
501// {},
502// ],
503// [
504// '/base',
505// '/base/a',
506// {
507// to: '/b',
508// },
509// undefined,
510// ],
511// ] as const
512// ).forEach(([a, b, c, eq]) => {
513// test(`${b} == ${a} + ${c.to}`, () => {
514// expect(matchPathname(a, b, c)).toEqual(eq)
515// })
516// })
517// })
518β
519// describe('params', () => {
520// ;(
521// [
522// [
523// '/a/b',
524// {
525// to: '/a/$b',
526// },
527// { b: 'b' },
528// ],
529// [
530// '/a/b/c',
531// {
532// to: '/a/$b/$c',
533// },
534// { b: 'b', c: 'c' },
535// ],
536// [
537// '/a/b/c',
538// {
539// to: '/$a/$b/$c',
540// },
541// { a: 'a', b: 'b', c: 'c' },
542// ],
543// [
544// '/a/b/c',
545// {
546// to: '/$a/$',
547// },
548// { a: 'a', '*': 'b/c' },
549// ],
550// [
551// '/a/b/c',
552// {
553// to: '/a/$b/c',
554// },
555// { b: 'b' },
556// ],
557// ] as const
558// ).forEach(([a, b, eq]) => {
559// test(`${a} == ${b.to}`, () => {
560// expect(matchPathname('', a, b)).toEqual(eq)
561// })
562// })
563// })
564// })