11import { describe , it , expect } from "vitest" ;
22import { matchRoutes } from "../core/matchRoutes.js" ;
3- import type { RouteDefinition } from "../types.js" ;
3+ import { internalRoutes , type InternalRouteDefinition } from "../types.js" ;
44
55describe ( "matchRoutes" , ( ) => {
66 describe ( "basic matching" , ( ) => {
77 it ( "matches exact paths" , ( ) => {
8- const routes : RouteDefinition [ ] = [
8+ const routes = internalRoutes ( [
99 { path : "/" , component : ( ) => null } ,
1010 { path : "/about" , component : ( ) => null } ,
11- ] ;
11+ ] ) ;
1212
1313 const result = matchRoutes ( routes , "/about" ) ;
1414 expect ( result ) . toHaveLength ( 1 ) ;
1515 expect ( result ! [ 0 ] . route . path ) . toBe ( "/about" ) ;
1616 } ) ;
1717
1818 it ( "returns null for non-matching paths" , ( ) => {
19- const routes : RouteDefinition [ ] = [
19+ const routes = internalRoutes ( [
2020 { path : "/" , component : ( ) => null } ,
2121 { path : "/about" , component : ( ) => null } ,
22- ] ;
22+ ] ) ;
2323
2424 const result = matchRoutes ( routes , "/contact" ) ;
2525 expect ( result ) . toBeNull ( ) ;
2626 } ) ;
2727
2828 it ( "matches root path" , ( ) => {
29- const routes : RouteDefinition [ ] = [ { path : "/" , component : ( ) => null } ] ;
29+ const routes = internalRoutes ( [ { path : "/" , component : ( ) => null } ] ) ;
3030
3131 const result = matchRoutes ( routes , "/" ) ;
3232 expect ( result ) . toHaveLength ( 1 ) ;
@@ -36,19 +36,19 @@ describe("matchRoutes", () => {
3636
3737 describe ( "path parameters" , ( ) => {
3838 it ( "extracts single parameter" , ( ) => {
39- const routes : RouteDefinition [ ] = [
39+ const routes = internalRoutes ( [
4040 { path : "/users/:id" , component : ( ) => null } ,
41- ] ;
41+ ] ) ;
4242
4343 const result = matchRoutes ( routes , "/users/123" ) ;
4444 expect ( result ) . toHaveLength ( 1 ) ;
4545 expect ( result ! [ 0 ] . params ) . toEqual ( { id : "123" } ) ;
4646 } ) ;
4747
4848 it ( "extracts multiple parameters" , ( ) => {
49- const routes : RouteDefinition [ ] = [
49+ const routes = internalRoutes ( [
5050 { path : "/users/:userId/posts/:postId" , component : ( ) => null } ,
51- ] ;
51+ ] ) ;
5252
5353 const result = matchRoutes ( routes , "/users/42/posts/99" ) ;
5454 expect ( result ) . toHaveLength ( 1 ) ;
@@ -58,7 +58,7 @@ describe("matchRoutes", () => {
5858
5959 describe ( "nested routes" , ( ) => {
6060 it ( "matches nested routes" , ( ) => {
61- const routes : RouteDefinition [ ] = [
61+ const routes = internalRoutes ( [
6262 {
6363 path : "/" ,
6464 component : ( ) => null ,
@@ -67,7 +67,7 @@ describe("matchRoutes", () => {
6767 { path : "about" , component : ( ) => null } ,
6868 ] ,
6969 } ,
70- ] ;
70+ ] ) ;
7171
7272 const result = matchRoutes ( routes , "/about" ) ;
7373 expect ( result ) . toHaveLength ( 2 ) ;
@@ -76,7 +76,7 @@ describe("matchRoutes", () => {
7676 } ) ;
7777
7878 it ( "matches deeply nested routes" , ( ) => {
79- const routes : RouteDefinition [ ] = [
79+ const routes = internalRoutes ( [
8080 {
8181 path : "/" ,
8282 component : ( ) => null ,
@@ -88,7 +88,7 @@ describe("matchRoutes", () => {
8888 } ,
8989 ] ,
9090 } ,
91- ] ;
91+ ] ) ;
9292
9393 const result = matchRoutes ( routes , "/users/123" ) ;
9494 expect ( result ) . toHaveLength ( 3 ) ;
@@ -99,27 +99,27 @@ describe("matchRoutes", () => {
9999 } ) ;
100100
101101 it ( "merges params from parent routes" , ( ) => {
102- const routes : RouteDefinition [ ] = [
102+ const routes = internalRoutes ( [
103103 {
104104 path : "/org/:orgId" ,
105105 component : ( ) => null ,
106106 children : [ { path : "users/:userId" , component : ( ) => null } ] ,
107107 } ,
108- ] ;
108+ ] ) ;
109109
110110 const result = matchRoutes ( routes , "/org/acme/users/123" ) ;
111111 expect ( result ) . toHaveLength ( 2 ) ;
112112 expect ( result ! [ 1 ] . params ) . toEqual ( { orgId : "acme" , userId : "123" } ) ;
113113 } ) ;
114114
115115 it ( "matches index route (empty path)" , ( ) => {
116- const routes : RouteDefinition [ ] = [
116+ const routes = internalRoutes ( [
117117 {
118118 path : "/" ,
119119 component : ( ) => null ,
120120 children : [ { path : "" , component : ( ) => null } ] ,
121121 } ,
122- ] ;
122+ ] ) ;
123123
124124 const result = matchRoutes ( routes , "/" ) ;
125125 expect ( result ) . toHaveLength ( 2 ) ;
@@ -130,10 +130,10 @@ describe("matchRoutes", () => {
130130
131131 describe ( "route priority" , ( ) => {
132132 it ( "matches first matching route" , ( ) => {
133- const routes : RouteDefinition [ ] = [
133+ const routes = internalRoutes ( [
134134 { path : "/users/new" , component : ( ) => null } ,
135135 { path : "/users/:id" , component : ( ) => null } ,
136- ] ;
136+ ] ) ;
137137
138138 const result = matchRoutes ( routes , "/users/new" ) ;
139139 expect ( result ) . toHaveLength ( 1 ) ;
0 commit comments