Skip to content

Commit 84b96f3

Browse files
committed
test: improve page scanning test stability
1 parent 19a292f commit 84b96f3

File tree

3 files changed

+96
-86
lines changed

3 files changed

+96
-86
lines changed

packages/nuxt/test/__snapshots__/pages-override-meta-disabled.test.ts.snap

Lines changed: 49 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -55,24 +55,33 @@
5555
{
5656
"alias": "mockMeta?.alias || []",
5757
"children": [
58+
{
59+
"alias": "mockMeta?.alias || []",
60+
"component": "() => import("pages/param/sibling.vue")",
61+
"meta": "mockMeta || {}",
62+
"name": "mockMeta?.name ?? "param-sibling"",
63+
"path": "mockMeta?.path ?? "sibling"",
64+
"props": "mockMeta?.props ?? false",
65+
"redirect": "mockMeta?.redirect",
66+
},
5867
{
5968
"alias": "mockMeta?.alias || []",
6069
"children": [
6170
{
6271
"alias": "mockMeta?.alias || []",
63-
"component": "() => import("pages/param/index/index.vue")",
72+
"component": "() => import("layer/pages/param/index/sibling.vue")",
6473
"meta": "mockMeta || {}",
65-
"name": "mockMeta?.name ?? "param-index"",
66-
"path": "mockMeta?.path ?? """,
74+
"name": "mockMeta?.name ?? "param-index-sibling"",
75+
"path": "mockMeta?.path ?? "sibling"",
6776
"props": "mockMeta?.props ?? false",
6877
"redirect": "mockMeta?.redirect",
6978
},
7079
{
7180
"alias": "mockMeta?.alias || []",
72-
"component": "() => import("layer/pages/param/index/sibling.vue")",
81+
"component": "() => import("pages/param/index/index.vue")",
7382
"meta": "mockMeta || {}",
74-
"name": "mockMeta?.name ?? "param-index-sibling"",
75-
"path": "mockMeta?.path ?? "sibling"",
83+
"name": "mockMeta?.name ?? "param-index"",
84+
"path": "mockMeta?.path ?? """,
7685
"props": "mockMeta?.props ?? false",
7786
"redirect": "mockMeta?.redirect",
7887
},
@@ -84,15 +93,6 @@
8493
"props": "mockMeta?.props ?? false",
8594
"redirect": "mockMeta?.redirect",
8695
},
87-
{
88-
"alias": "mockMeta?.alias || []",
89-
"component": "() => import("pages/param/sibling.vue")",
90-
"meta": "mockMeta || {}",
91-
"name": "mockMeta?.name ?? "param-sibling"",
92-
"path": "mockMeta?.path ?? "sibling"",
93-
"props": "mockMeta?.props ?? false",
94-
"redirect": "mockMeta?.redirect",
95-
},
9696
],
9797
"component": "() => import("pages/param.vue")",
9898
"meta": "mockMeta || {}",
@@ -106,19 +106,19 @@
106106
"children": [
107107
{
108108
"alias": "mockMeta?.alias || []",
109-
"component": "() => import("layer/pages/wrapper-expose/other/index.vue")",
109+
"component": "() => import("pages/wrapper-expose/other/sibling.vue")",
110110
"meta": "mockMeta || {}",
111-
"name": "mockMeta?.name ?? "wrapper-expose-other"",
112-
"path": "mockMeta?.path ?? """,
111+
"name": "mockMeta?.name ?? "wrapper-expose-other-sibling"",
112+
"path": "mockMeta?.path ?? "sibling"",
113113
"props": "mockMeta?.props ?? false",
114114
"redirect": "mockMeta?.redirect",
115115
},
116116
{
117117
"alias": "mockMeta?.alias || []",
118-
"component": "() => import("pages/wrapper-expose/other/sibling.vue")",
118+
"component": "() => import("layer/pages/wrapper-expose/other/index.vue")",
119119
"meta": "mockMeta || {}",
120-
"name": "mockMeta?.name ?? "wrapper-expose-other-sibling"",
121-
"path": "mockMeta?.path ?? "sibling"",
120+
"name": "mockMeta?.name ?? "wrapper-expose-other"",
121+
"path": "mockMeta?.path ?? """,
122122
"props": "mockMeta?.props ?? false",
123123
"redirect": "mockMeta?.redirect",
124124
},
@@ -297,19 +297,19 @@
297297
"should generate correct id for catchall (order 2)": [
298298
{
299299
"alias": "mockMeta?.alias || []",
300-
"component": "() => import("pages/stories/[id].vue")",
300+
"component": "() => import("pages/[...stories].vue")",
301301
"meta": "mockMeta || {}",
302-
"name": "mockMeta?.name ?? "stories-id"",
303-
"path": "mockMeta?.path ?? "/stories/:id()"",
302+
"name": "mockMeta?.name ?? "stories"",
303+
"path": "mockMeta?.path ?? "/:stories(.*)*"",
304304
"props": "mockMeta?.props ?? false",
305305
"redirect": "mockMeta?.redirect",
306306
},
307307
{
308308
"alias": "mockMeta?.alias || []",
309-
"component": "() => import("pages/[...stories].vue")",
309+
"component": "() => import("pages/stories/[id].vue")",
310310
"meta": "mockMeta || {}",
311-
"name": "mockMeta?.name ?? "stories"",
312-
"path": "mockMeta?.path ?? "/:stories(.*)*"",
311+
"name": "mockMeta?.name ?? "stories-id"",
312+
"path": "mockMeta?.path ?? "/stories/:id()"",
313313
"props": "mockMeta?.props ?? false",
314314
"redirect": "mockMeta?.redirect",
315315
},
@@ -419,15 +419,6 @@
419419
},
420420
],
421421
"should handle route groups": [
422-
{
423-
"alias": "mockMeta?.alias || []",
424-
"component": "() => import("pages/(foo)/index.vue")",
425-
"meta": "mockMeta || {}",
426-
"name": "mockMeta?.name ?? "index"",
427-
"path": "mockMeta?.path ?? "/"",
428-
"props": "mockMeta?.props ?? false",
429-
"redirect": "mockMeta?.redirect",
430-
},
431422
{
432423
"alias": "mockMeta?.alias || []",
433424
"children": [
@@ -448,6 +439,15 @@
448439
"props": "mockMeta?.props ?? false",
449440
"redirect": "mockMeta?.redirect",
450441
},
442+
{
443+
"alias": "mockMeta?.alias || []",
444+
"component": "() => import("pages/(foo)/index.vue")",
445+
"meta": "mockMeta || {}",
446+
"name": "mockMeta?.name ?? "index"",
447+
"path": "mockMeta?.path ?? "/"",
448+
"props": "mockMeta?.props ?? false",
449+
"redirect": "mockMeta?.redirect",
450+
},
451451
],
452452
"should handle trailing slashes with index routes": [
453453
{
@@ -485,19 +485,19 @@
485485
"should not generate colliding route names when hyphens are in file name": [
486486
{
487487
"alias": "mockMeta?.alias || []",
488-
"component": "() => import("pages/parent/[child].vue")",
488+
"component": "() => import("pages/parent-[child].vue")",
489489
"meta": "mockMeta || {}",
490490
"name": "mockMeta?.name ?? "parent-child"",
491-
"path": "mockMeta?.path ?? "/parent/:child()"",
491+
"path": "mockMeta?.path ?? "/parent-:child()"",
492492
"props": "mockMeta?.props ?? false",
493493
"redirect": "mockMeta?.redirect",
494494
},
495495
{
496496
"alias": "mockMeta?.alias || []",
497-
"component": "() => import("pages/parent-[child].vue")",
497+
"component": "() => import("pages/parent/[child].vue")",
498498
"meta": "mockMeta || {}",
499499
"name": "mockMeta?.name ?? "parent-child"",
500-
"path": "mockMeta?.path ?? "/parent-:child()"",
500+
"path": "mockMeta?.path ?? "/parent/:child()"",
501501
"props": "mockMeta?.props ?? false",
502502
"redirect": "mockMeta?.redirect",
503503
},
@@ -541,15 +541,6 @@
541541
"props": "mockMeta?.props ?? false",
542542
"redirect": "mockMeta?.redirect",
543543
},
544-
{
545-
"alias": "mockMeta?.alias || []",
546-
"component": "() => import("pages/[b2]_[2b].vue")",
547-
"meta": "mockMeta || {}",
548-
"name": "mockMeta?.name ?? "b2_2b"",
549-
"path": "mockMeta?.path ?? "/:b2()_:2b()"",
550-
"props": "mockMeta?.props ?? false",
551-
"redirect": "mockMeta?.redirect",
552-
},
553544
{
554545
"alias": "mockMeta?.alias || []",
555546
"component": "() => import("pages/[[c3@3c]].vue")",
@@ -568,6 +559,15 @@
568559
"props": "mockMeta?.props ?? false",
569560
"redirect": "mockMeta?.redirect",
570561
},
562+
{
563+
"alias": "mockMeta?.alias || []",
564+
"component": "() => import("pages/[b2]_[2b].vue")",
565+
"meta": "mockMeta || {}",
566+
"name": "mockMeta?.name ?? "b2_2b"",
567+
"path": "mockMeta?.path ?? "/:b2()_:2b()"",
568+
"props": "mockMeta?.props ?? false",
569+
"redirect": "mockMeta?.redirect",
570+
},
571571
],
572572
"should properly override route name if definePageMeta name override is defined.": [
573573
{

packages/nuxt/test/__snapshots__/pages-override-meta-enabled.test.ts.snap

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -43,45 +43,45 @@
4343
"should correctly merge nested routes": [
4444
{
4545
"children": [
46+
{
47+
"component": "() => import("pages/param/sibling.vue")",
48+
"name": ""param-sibling"",
49+
"path": ""sibling"",
50+
},
4651
{
4752
"children": [
48-
{
49-
"component": "() => import("pages/param/index/index.vue")",
50-
"name": ""param-index"",
51-
"path": """",
52-
},
5353
{
5454
"component": "() => import("layer/pages/param/index/sibling.vue")",
5555
"name": ""param-index-sibling"",
5656
"path": ""sibling"",
5757
},
58+
{
59+
"component": "() => import("pages/param/index/index.vue")",
60+
"name": ""param-index"",
61+
"path": """",
62+
},
5863
],
5964
"component": "() => import("layer/pages/param/index.vue")",
6065
"name": "mockMeta?.name",
6166
"path": """",
6267
},
63-
{
64-
"component": "() => import("pages/param/sibling.vue")",
65-
"name": ""param-sibling"",
66-
"path": ""sibling"",
67-
},
6868
],
6969
"component": "() => import("pages/param.vue")",
7070
"name": "mockMeta?.name",
7171
"path": ""/param"",
7272
},
7373
{
7474
"children": [
75-
{
76-
"component": "() => import("layer/pages/wrapper-expose/other/index.vue")",
77-
"name": ""wrapper-expose-other"",
78-
"path": """",
79-
},
8075
{
8176
"component": "() => import("pages/wrapper-expose/other/sibling.vue")",
8277
"name": ""wrapper-expose-other-sibling"",
8378
"path": ""sibling"",
8479
},
80+
{
81+
"component": "() => import("layer/pages/wrapper-expose/other/index.vue")",
82+
"name": ""wrapper-expose-other"",
83+
"path": """",
84+
},
8585
],
8686
"component": "() => import("pages/wrapper-expose/other.vue")",
8787
"name": "mockMeta?.name",
@@ -187,16 +187,16 @@
187187
},
188188
],
189189
"should generate correct id for catchall (order 2)": [
190-
{
191-
"component": "() => import("pages/stories/[id].vue")",
192-
"name": ""stories-id"",
193-
"path": ""/stories/:id()"",
194-
},
195190
{
196191
"component": "() => import("pages/[...stories].vue")",
197192
"name": ""stories"",
198193
"path": ""/:stories(.*)*"",
199194
},
195+
{
196+
"component": "() => import("pages/stories/[id].vue")",
197+
"name": ""stories-id"",
198+
"path": ""/stories/:id()"",
199+
},
200200
],
201201
"should generate correct route for kebab-case file": [
202202
{
@@ -263,11 +263,6 @@
263263
},
264264
],
265265
"should handle route groups": [
266-
{
267-
"component": "() => import("pages/(foo)/index.vue")",
268-
"name": ""index"",
269-
"path": ""/"",
270-
},
271266
{
272267
"children": [
273268
{
@@ -280,6 +275,11 @@
280275
"name": "mockMeta?.name",
281276
"path": ""/about"",
282277
},
278+
{
279+
"component": "() => import("pages/(foo)/index.vue")",
280+
"name": ""index"",
281+
"path": ""/"",
282+
},
283283
],
284284
"should handle trailing slashes with index routes": [
285285
{
@@ -305,14 +305,14 @@
305305
],
306306
"should not generate colliding route names when hyphens are in file name": [
307307
{
308-
"component": "() => import("pages/parent/[child].vue")",
308+
"component": "() => import("pages/parent-[child].vue")",
309309
"name": ""parent-child"",
310-
"path": ""/parent/:child()"",
310+
"path": ""/parent-:child()"",
311311
},
312312
{
313-
"component": "() => import("pages/parent-[child].vue")",
313+
"component": "() => import("pages/parent/[child].vue")",
314314
"name": ""parent-child"",
315-
"path": ""/parent-:child()"",
315+
"path": ""/parent/:child()"",
316316
},
317317
],
318318
"should not merge required param as a child of optional param": [
@@ -338,11 +338,6 @@
338338
"name": ""b2.2b"",
339339
"path": ""/:b2.2b()"",
340340
},
341-
{
342-
"component": "() => import("pages/[b2]_[2b].vue")",
343-
"name": ""b2_2b"",
344-
"path": ""/:b2()_:2b()"",
345-
},
346341
{
347342
"component": "() => import("pages/[[c3@3c]].vue")",
348343
"name": ""c33c"",
@@ -353,6 +348,11 @@
353348
"name": ""d44d"",
354349
"path": ""/:d44d?"",
355350
},
351+
{
352+
"component": "() => import("pages/[b2]_[2b].vue")",
353+
"name": ""b2_2b"",
354+
"path": ""/:b2()_:2b()"",
355+
},
356356
],
357357
"should properly override route name if definePageMeta name override is defined.": [
358358
{

packages/nuxt/test/pages.test.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -722,6 +722,14 @@ describe('pages:generateRoutesFromFiles', () => {
722722
const normalizedResults: Record<string, any> = {}
723723
const normalizedOverrideMetaResults: Record<string, any> = {}
724724

725+
const enUSComparator = new Intl.Collator('en-US')
726+
function sortRoutes (routes: NuxtPage[]) {
727+
for (const route of routes) {
728+
route.children &&= sortRoutes([...route.children])
729+
}
730+
return [...routes].sort((a, b) => enUSComparator.compare(b.path, a.path))
731+
}
732+
725733
for (const test of tests) {
726734
const _it = test.it || it
727735
_it(test.description, async () => {
@@ -732,11 +740,13 @@ describe('pages:generateRoutesFromFiles', () => {
732740
) as Record<string, string>
733741

734742
try {
735-
result = generateRoutesFromFiles(test.files.map(file => ({
743+
const files = test.files.map(file => ({
736744
shouldUseServerComponents: true,
737745
absolutePath: file.path,
738746
relativePath: file.path.replace(/^(pages|layer\/pages)\//, ''),
739-
}))).map((route, index) => {
747+
})).sort((a, b) => enUSComparator.compare(a.relativePath, b.relativePath))
748+
749+
result = generateRoutesFromFiles(files).map((route, index) => {
740750
return {
741751
...route,
742752
meta: test.files![index]!.meta,
@@ -752,7 +762,7 @@ describe('pages:generateRoutesFromFiles', () => {
752762
}
753763

754764
if (result) {
755-
expect.soft(result).toEqual(test.output)
765+
expect.soft(sortRoutes(result)).toEqual(test.output ? sortRoutes(test.output) : undefined)
756766

757767
normalizedResults[test.description] = normalizeRoutes(result, new Set(), {
758768
clientComponentRuntime: '<client-component-runtime>',

0 commit comments

Comments
 (0)