11import { createRouterMatcher , normalizeRouteRecord } from '../matcher'
22import { RouteComponent , RouteRecordRaw , MatcherLocation } from '../types'
3- import { MatcherLocationNormalizedLoose } from '../../__tests__/utils'
43import { defineComponent } from 'vue'
54import { START_LOCATION_NORMALIZED } from '../location'
65import { describe , expect , it } from 'vitest'
@@ -10,7 +9,8 @@ import {
109 MatcherLocationRaw ,
1110 NEW_MatcherRecordRaw ,
1211 NEW_LocationResolved ,
13- } from './matcher'
12+ NEW_MatcherRecord ,
13+ } from './resolver'
1414import { PathParams , tokensToParser } from '../matcher/pathParserRanker'
1515import { tokenizePath } from '../matcher/pathTokenizer'
1616import { miss } from './matchers/errors'
@@ -63,22 +63,23 @@ function compileRouteRecord(
6363
6464describe ( 'RouterMatcher.resolve' , ( ) => {
6565 mockWarn ( )
66- type Matcher = ReturnType < typeof createRouterMatcher >
66+ type Matcher = ReturnType < typeof createCompiledMatcher >
6767 type MatcherResolvedLocation = ReturnType < Matcher [ 'resolve' ] >
6868
69- const START_LOCATION : NEW_LocationResolved = {
69+ const START_LOCATION : MatcherResolvedLocation = {
7070 name : Symbol ( 'START' ) ,
71- fullPath : '/' ,
72- path : '/' ,
7371 params : { } ,
72+ path : '/' ,
73+ fullPath : '/' ,
7474 query : { } ,
7575 hash : '' ,
7676 matched : [ ] ,
77+ // meta: {},
7778 }
7879
7980 function isMatcherLocationResolved (
8081 location : unknown
81- ) : location is NEW_LocationResolved {
82+ ) : location is NEW_LocationResolved < NEW_MatcherRecord > {
8283 return ! ! (
8384 location &&
8485 typeof location === 'object' &&
@@ -95,16 +96,16 @@ describe('RouterMatcher.resolve', () => {
9596 toLocation : MatcherLocationRaw ,
9697 expectedLocation : Partial < MatcherResolvedLocation > ,
9798 fromLocation :
98- | NEW_LocationResolved
99+ | NEW_LocationResolved < NEW_MatcherRecord >
99100 | Exclude < MatcherLocationRaw , string >
100101 | `/${string } ` = START_LOCATION
101102 ) {
102103 const records = ( Array . isArray ( record ) ? record : [ record ] ) . map (
103104 ( record ) : NEW_MatcherRecordRaw => compileRouteRecord ( record )
104105 )
105- const matcher = createCompiledMatcher ( )
106+ const matcher = createCompiledMatcher < NEW_MatcherRecord > ( )
106107 for ( const record of records ) {
107- matcher . addRoute ( record )
108+ matcher . addMatcher ( record )
108109 }
109110
110111 const resolved : MatcherResolvedLocation = {
@@ -137,60 +138,6 @@ describe('RouterMatcher.resolve', () => {
137138 } )
138139 }
139140
140- function _assertRecordMatch (
141- record : RouteRecordRaw | RouteRecordRaw [ ] ,
142- location : MatcherLocationRaw ,
143- resolved : Partial < MatcherLocationNormalizedLoose > ,
144- start : MatcherLocation = START_LOCATION_NORMALIZED
145- ) {
146- record = Array . isArray ( record ) ? record : [ record ]
147- const matcher = createRouterMatcher ( record , { } )
148-
149- if ( ! ( 'meta' in resolved ) ) {
150- resolved . meta = record [ 0 ] . meta || { }
151- }
152-
153- if ( ! ( 'name' in resolved ) ) {
154- resolved . name = undefined
155- }
156-
157- // add location if provided as it should be the same value
158- if ( 'path' in location && ! ( 'path' in resolved ) ) {
159- resolved . path = location . path
160- }
161-
162- if ( 'redirect' in record ) {
163- throw new Error ( 'not handled' )
164- } else {
165- // use one single record
166- if ( ! resolved . matched ) resolved . matched = record . map ( normalizeRouteRecord )
167- // allow passing an expect.any(Array)
168- else if ( Array . isArray ( resolved . matched ) )
169- resolved . matched = resolved . matched . map ( m => ( {
170- ...normalizeRouteRecord ( m as any ) ,
171- aliasOf : m . aliasOf ,
172- } ) )
173- }
174-
175- // allows not passing params
176- resolved . params =
177- resolved . params || ( 'params' in location ? location . params : { } )
178-
179- const startCopy : MatcherLocation = {
180- ...start ,
181- matched : start . matched . map ( m => ( {
182- ...normalizeRouteRecord ( m ) ,
183- aliasOf : m . aliasOf ,
184- } ) ) as MatcherLocation [ 'matched' ] ,
185- }
186-
187- // make matched non enumerable
188- Object . defineProperty ( startCopy , 'matched' , { enumerable : false } )
189-
190- const result = matcher . resolve ( location , startCopy )
191- expect ( result ) . toEqual ( resolved )
192- }
193-
194141 /**
195142 *
196143 * @param record - Record or records we are testing the matcher against
0 commit comments