1
1
import { basename } from 'pathe'
2
2
import { describe , expect , it } from 'vitest'
3
- import { createPrefixTree , TreeNode } from '../core/tree'
3
+ import { PrefixTree , TreeNode } from '../core/tree'
4
4
import { ResolvedOptions , resolveOptions } from '../options'
5
5
import { generateRouteRecord } from './generateRouteRecords'
6
6
import { ImportsMap } from '../core/utils'
@@ -13,7 +13,7 @@ describe('generateRouteRecord', () => {
13
13
}
14
14
15
15
it ( 'works with an empty tree' , ( ) => {
16
- const tree = createPrefixTree ( DEFAULT_OPTIONS )
16
+ const tree = new PrefixTree ( DEFAULT_OPTIONS )
17
17
18
18
expect ( generateRouteRecordSimple ( tree ) ) . toMatchInlineSnapshot ( `
19
19
"[
@@ -23,29 +23,29 @@ describe('generateRouteRecord', () => {
23
23
} )
24
24
25
25
it ( 'works with some paths at root' , ( ) => {
26
- const tree = createPrefixTree ( DEFAULT_OPTIONS )
26
+ const tree = new PrefixTree ( DEFAULT_OPTIONS )
27
27
tree . insert ( 'a.vue' )
28
28
tree . insert ( 'b.vue' )
29
29
tree . insert ( 'c.vue' )
30
30
expect ( generateRouteRecordSimple ( tree ) ) . toMatchSnapshot ( )
31
31
} )
32
32
33
33
it ( 'handles multiple named views' , ( ) => {
34
- const tree = createPrefixTree ( DEFAULT_OPTIONS )
34
+ const tree = new PrefixTree ( DEFAULT_OPTIONS )
35
35
tree . insert ( 'foo.vue' )
36
36
37
37
38
38
expect ( generateRouteRecordSimple ( tree ) ) . toMatchSnapshot ( )
39
39
} )
40
40
41
41
it ( 'handles single named views' , ( ) => {
42
- const tree = createPrefixTree ( DEFAULT_OPTIONS )
42
+ const tree = new PrefixTree ( DEFAULT_OPTIONS )
43
43
44
44
expect ( generateRouteRecordSimple ( tree ) ) . toMatchSnapshot ( )
45
45
} )
46
46
47
47
it ( 'nested children' , ( ) => {
48
- const tree = createPrefixTree ( DEFAULT_OPTIONS )
48
+ const tree = new PrefixTree ( DEFAULT_OPTIONS )
49
49
tree . insert ( 'a/a.vue' )
50
50
tree . insert ( 'a/b.vue' )
51
51
tree . insert ( 'a/c.vue' )
@@ -59,7 +59,7 @@ describe('generateRouteRecord', () => {
59
59
} )
60
60
61
61
it ( 'adds children and name when folder and component exist' , ( ) => {
62
- const tree = createPrefixTree ( DEFAULT_OPTIONS )
62
+ const tree = new PrefixTree ( DEFAULT_OPTIONS )
63
63
tree . insert ( 'a/c.vue' )
64
64
tree . insert ( 'b/c.vue' )
65
65
tree . insert ( 'a.vue' )
@@ -68,14 +68,14 @@ describe('generateRouteRecord', () => {
68
68
} )
69
69
70
70
it ( 'correctly names index.vue files' , ( ) => {
71
- const tree = createPrefixTree ( DEFAULT_OPTIONS )
71
+ const tree = new PrefixTree ( DEFAULT_OPTIONS )
72
72
tree . insert ( 'index.vue' )
73
73
tree . insert ( 'b/index.vue' )
74
74
expect ( generateRouteRecordSimple ( tree ) ) . toMatchSnapshot ( )
75
75
} )
76
76
77
77
it ( 'handles non nested routes' , ( ) => {
78
- const tree = createPrefixTree ( DEFAULT_OPTIONS )
78
+ const tree = new PrefixTree ( DEFAULT_OPTIONS )
79
79
tree . insert ( 'users.vue' )
80
80
tree . insert ( 'users/index.vue' )
81
81
tree . insert ( 'users/other.vue' )
@@ -89,7 +89,7 @@ describe('generateRouteRecord', () => {
89
89
} )
90
90
91
91
it ( 'removes trailing slashes' , ( ) => {
92
- const tree = createPrefixTree ( DEFAULT_OPTIONS )
92
+ const tree = new PrefixTree ( DEFAULT_OPTIONS )
93
93
tree . insert ( 'users/index.vue' )
94
94
tree . insert ( 'users/other.vue' )
95
95
tree . insert ( 'nested.vue' )
@@ -103,7 +103,7 @@ describe('generateRouteRecord', () => {
103
103
...DEFAULT_OPTIONS ,
104
104
importMode : 'sync' ,
105
105
} as const
106
- const tree = createPrefixTree ( options )
106
+ const tree = new PrefixTree ( options )
107
107
tree . insert ( 'a.vue' )
108
108
tree . insert ( 'b.vue' )
109
109
tree . insert ( 'nested/file/c.vue' )
@@ -120,7 +120,7 @@ describe('generateRouteRecord', () => {
120
120
basename ( filepath ) === 'a.vue' ? 'sync' : 'async' ,
121
121
}
122
122
123
- const tree = createPrefixTree ( options )
123
+ const tree = new PrefixTree ( options )
124
124
tree . insert ( 'a.vue' )
125
125
tree . insert ( 'b.vue' )
126
126
tree . insert ( 'nested/file/c.vue' )
@@ -132,7 +132,7 @@ describe('generateRouteRecord', () => {
132
132
133
133
describe ( 'names' , ( ) => {
134
134
it ( 'creates single word names' , ( ) => {
135
- const tree = createPrefixTree ( DEFAULT_OPTIONS )
135
+ const tree = new PrefixTree ( DEFAULT_OPTIONS )
136
136
tree . insert ( 'index.vue' )
137
137
tree . insert ( 'about.vue' )
138
138
tree . insert ( 'users/index.vue' )
@@ -144,7 +144,7 @@ describe('generateRouteRecord', () => {
144
144
} )
145
145
146
146
it ( 'creates multi word names' , ( ) => {
147
- const tree = createPrefixTree ( DEFAULT_OPTIONS )
147
+ const tree = new PrefixTree ( DEFAULT_OPTIONS )
148
148
tree . insert ( 'index.vue' )
149
149
tree . insert ( 'my-users.vue' )
150
150
tree . insert ( 'MyPascalCaseUsers.vue' )
@@ -154,7 +154,7 @@ describe('generateRouteRecord', () => {
154
154
} )
155
155
156
156
it ( 'works with nested views' , ( ) => {
157
- const tree = createPrefixTree ( DEFAULT_OPTIONS )
157
+ const tree = new PrefixTree ( DEFAULT_OPTIONS )
158
158
tree . insert ( 'index.vue' )
159
159
tree . insert ( 'users.vue' )
160
160
tree . insert ( 'users/index.vue' )
@@ -167,7 +167,7 @@ describe('generateRouteRecord', () => {
167
167
168
168
describe ( 'route block' , ( ) => {
169
169
it ( 'adds meta data' , async ( ) => {
170
- const tree = createPrefixTree ( DEFAULT_OPTIONS )
170
+ const tree = new PrefixTree ( DEFAULT_OPTIONS )
171
171
const node = tree . insert ( 'index.vue' )
172
172
node . setCustomRouteBlock ( 'index.vue' , {
173
173
meta : {
@@ -180,7 +180,7 @@ describe('generateRouteRecord', () => {
180
180
} )
181
181
182
182
it ( 'merges multiple meta properties' , async ( ) => {
183
- const tree = createPrefixTree ( DEFAULT_OPTIONS )
183
+ const tree = new PrefixTree ( DEFAULT_OPTIONS )
184
184
const node = tree . insert ( 'index.vue' )
185
185
node . setCustomRouteBlock ( 'index.vue' , {
186
186
path : '/custom' ,
@@ -199,7 +199,7 @@ describe('generateRouteRecord', () => {
199
199
} )
200
200
201
201
it ( 'merges regardless of order' , async ( ) => {
202
- const tree = createPrefixTree ( DEFAULT_OPTIONS )
202
+ const tree = new PrefixTree ( DEFAULT_OPTIONS )
203
203
const node = tree . insert ( 'index.vue' )
204
204
node . setCustomRouteBlock ( 'index.vue' , {
205
205
name : 'a' ,
@@ -223,7 +223,7 @@ describe('generateRouteRecord', () => {
223
223
} )
224
224
225
225
it ( 'handles named views with empty route blocks' , ( ) => {
226
- const tree = createPrefixTree ( DEFAULT_OPTIONS )
226
+ const tree = new PrefixTree ( DEFAULT_OPTIONS )
227
227
const node = tree . insert ( 'index.vue' )
228
228
const n2 = tree . insert ( '[email protected] ' )
229
229
expect ( node ) . toBe ( n2 )
@@ -242,7 +242,7 @@ describe('generateRouteRecord', () => {
242
242
243
243
// FIXME: allow aliases
244
244
it . todo ( 'merges alias properties' , async ( ) => {
245
- const tree = createPrefixTree ( DEFAULT_OPTIONS )
245
+ const tree = new PrefixTree ( DEFAULT_OPTIONS )
246
246
const node = tree . insert ( 'index.vue' )
247
247
node . setCustomRouteBlock ( 'index.vue' , {
248
248
alias : '/one' ,
@@ -265,7 +265,7 @@ describe('generateRouteRecord', () => {
265
265
} )
266
266
267
267
it ( 'merges deep meta properties' , async ( ) => {
268
- const tree = createPrefixTree ( DEFAULT_OPTIONS )
268
+ const tree = new PrefixTree ( DEFAULT_OPTIONS )
269
269
const node = tree . insert ( 'index.vue' )
270
270
node . setCustomRouteBlock ( 'index.vue' , {
271
271
meta : {
@@ -286,31 +286,31 @@ describe('generateRouteRecord', () => {
286
286
287
287
describe ( 'raw paths insertions' , ( ) => {
288
288
it ( 'works with raw paths' , ( ) => {
289
- const tree = createPrefixTree ( DEFAULT_OPTIONS )
289
+ const tree = new PrefixTree ( DEFAULT_OPTIONS )
290
290
tree . insertParsedPath ( 'a' , 'a.vue' )
291
291
tree . insertParsedPath ( 'b' , 'b.vue' )
292
292
tree . insertParsedPath ( 'c' , 'c.vue' )
293
293
expect ( generateRouteRecordSimple ( tree ) ) . toMatchSnapshot ( )
294
294
} )
295
295
296
296
it ( 'works with mixed nodes' , ( ) => {
297
- const tree = createPrefixTree ( DEFAULT_OPTIONS )
297
+ const tree = new PrefixTree ( DEFAULT_OPTIONS )
298
298
tree . insertParsedPath ( 'a' , 'a.vue' )
299
299
tree . insert ( 'b.vue' )
300
300
tree . insertParsedPath ( 'c' , 'c.vue' )
301
301
expect ( generateRouteRecordSimple ( tree ) ) . toMatchSnapshot ( )
302
302
} )
303
303
304
304
it ( 'works with nested nodes' , ( ) => {
305
- const tree = createPrefixTree ( DEFAULT_OPTIONS )
305
+ const tree = new PrefixTree ( DEFAULT_OPTIONS )
306
306
tree . insertParsedPath ( 'a/b/c' , 'a.vue' )
307
307
tree . insertParsedPath ( 'a/b/d' , 'a.vue' )
308
308
tree . insertParsedPath ( 'a/d/c' , 'a.vue' )
309
309
expect ( generateRouteRecordSimple ( tree ) ) . toMatchSnapshot ( )
310
310
} )
311
311
312
312
it ( 'do not nest raw segments with file based' , ( ) => {
313
- const tree = createPrefixTree ( DEFAULT_OPTIONS )
313
+ const tree = new PrefixTree ( DEFAULT_OPTIONS )
314
314
tree . insert ( 'a/b.vue' )
315
315
// should be separated
316
316
tree . insertParsedPath ( 'a/b/c' , 'a.vue' )
0 commit comments