Skip to content

Commit 8eb92e6

Browse files
committed
test: improve page scanning test stability
1 parent 478a732 commit 8eb92e6

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
},
@@ -308,19 +308,19 @@
308308
"should generate correct id for catchall (order 2)": [
309309
{
310310
"alias": "mockMeta?.alias || []",
311-
"component": "() => import("pages/stories/[id].vue")",
311+
"component": "() => import("pages/[...stories].vue")",
312312
"meta": "mockMeta || {}",
313-
"name": "mockMeta?.name ?? "stories-id"",
314-
"path": "mockMeta?.path ?? "/stories/:id()"",
313+
"name": "mockMeta?.name ?? "stories"",
314+
"path": "mockMeta?.path ?? "/:stories(.*)*"",
315315
"props": "mockMeta?.props ?? false",
316316
"redirect": "mockMeta?.redirect",
317317
},
318318
{
319319
"alias": "mockMeta?.alias || []",
320-
"component": "() => import("pages/[...stories].vue")",
320+
"component": "() => import("pages/stories/[id].vue")",
321321
"meta": "mockMeta || {}",
322-
"name": "mockMeta?.name ?? "stories"",
323-
"path": "mockMeta?.path ?? "/:stories(.*)*"",
322+
"name": "mockMeta?.name ?? "stories-id"",
323+
"path": "mockMeta?.path ?? "/stories/:id()"",
324324
"props": "mockMeta?.props ?? false",
325325
"redirect": "mockMeta?.redirect",
326326
},
@@ -430,15 +430,6 @@
430430
},
431431
],
432432
"should handle route groups": [
433-
{
434-
"alias": "mockMeta?.alias || []",
435-
"component": "() => import("pages/(foo)/index.vue")",
436-
"meta": "mockMeta || {}",
437-
"name": "mockMeta?.name ?? "index"",
438-
"path": "mockMeta?.path ?? "/"",
439-
"props": "mockMeta?.props ?? false",
440-
"redirect": "mockMeta?.redirect",
441-
},
442433
{
443434
"alias": "mockMeta?.alias || []",
444435
"children": [
@@ -459,6 +450,15 @@
459450
"props": "mockMeta?.props ?? false",
460451
"redirect": "mockMeta?.redirect",
461452
},
453+
{
454+
"alias": "mockMeta?.alias || []",
455+
"component": "() => import("pages/(foo)/index.vue")",
456+
"meta": "mockMeta || {}",
457+
"name": "mockMeta?.name ?? "index"",
458+
"path": "mockMeta?.path ?? "/"",
459+
"props": "mockMeta?.props ?? false",
460+
"redirect": "mockMeta?.redirect",
461+
},
462462
],
463463
"should handle trailing slashes with index routes": [
464464
{
@@ -496,19 +496,19 @@
496496
"should not generate colliding route names when hyphens are in file name": [
497497
{
498498
"alias": "mockMeta?.alias || []",
499-
"component": "() => import("pages/parent/[child].vue")",
499+
"component": "() => import("pages/parent-[child].vue")",
500500
"meta": "mockMeta || {}",
501501
"name": "mockMeta?.name ?? "parent-child"",
502-
"path": "mockMeta?.path ?? "/parent/:child()"",
502+
"path": "mockMeta?.path ?? "/parent-:child()"",
503503
"props": "mockMeta?.props ?? false",
504504
"redirect": "mockMeta?.redirect",
505505
},
506506
{
507507
"alias": "mockMeta?.alias || []",
508-
"component": "() => import("pages/parent-[child].vue")",
508+
"component": "() => import("pages/parent/[child].vue")",
509509
"meta": "mockMeta || {}",
510510
"name": "mockMeta?.name ?? "parent-child"",
511-
"path": "mockMeta?.path ?? "/parent-:child()"",
511+
"path": "mockMeta?.path ?? "/parent/:child()"",
512512
"props": "mockMeta?.props ?? false",
513513
"redirect": "mockMeta?.redirect",
514514
},
@@ -552,15 +552,6 @@
552552
"props": "mockMeta?.props ?? false",
553553
"redirect": "mockMeta?.redirect",
554554
},
555-
{
556-
"alias": "mockMeta?.alias || []",
557-
"component": "() => import("pages/[b2]_[2b].vue")",
558-
"meta": "mockMeta || {}",
559-
"name": "mockMeta?.name ?? "b2_2b"",
560-
"path": "mockMeta?.path ?? "/:b2()_:2b()"",
561-
"props": "mockMeta?.props ?? false",
562-
"redirect": "mockMeta?.redirect",
563-
},
564555
{
565556
"alias": "mockMeta?.alias || []",
566557
"component": "() => import("pages/[[c3@3c]].vue")",
@@ -579,6 +570,15 @@
579570
"props": "mockMeta?.props ?? false",
580571
"redirect": "mockMeta?.redirect",
581572
},
573+
{
574+
"alias": "mockMeta?.alias || []",
575+
"component": "() => import("pages/[b2]_[2b].vue")",
576+
"meta": "mockMeta || {}",
577+
"name": "mockMeta?.name ?? "b2_2b"",
578+
"path": "mockMeta?.path ?? "/:b2()_:2b()"",
579+
"props": "mockMeta?.props ?? false",
580+
"redirect": "mockMeta?.redirect",
581+
},
582582
],
583583
"should properly override route name if definePageMeta name override is defined.": [
584584
{

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
@@ -42,45 +42,45 @@
4242
"should correctly merge nested routes": [
4343
{
4444
"children": [
45+
{
46+
"component": "() => import("pages/param/sibling.vue")",
47+
"name": ""param-sibling"",
48+
"path": ""sibling"",
49+
},
4550
{
4651
"children": [
47-
{
48-
"component": "() => import("pages/param/index/index.vue")",
49-
"name": ""param-index"",
50-
"path": """",
51-
},
5252
{
5353
"component": "() => import("layer/pages/param/index/sibling.vue")",
5454
"name": ""param-index-sibling"",
5555
"path": ""sibling"",
5656
},
57+
{
58+
"component": "() => import("pages/param/index/index.vue")",
59+
"name": ""param-index"",
60+
"path": """",
61+
},
5762
],
5863
"component": "() => import("layer/pages/param/index.vue")",
5964
"name": "mockMeta?.name",
6065
"path": """",
6166
},
62-
{
63-
"component": "() => import("pages/param/sibling.vue")",
64-
"name": ""param-sibling"",
65-
"path": ""sibling"",
66-
},
6767
],
6868
"component": "() => import("pages/param.vue")",
6969
"name": "mockMeta?.name",
7070
"path": ""/param"",
7171
},
7272
{
7373
"children": [
74-
{
75-
"component": "() => import("layer/pages/wrapper-expose/other/index.vue")",
76-
"name": ""wrapper-expose-other"",
77-
"path": """",
78-
},
7974
{
8075
"component": "() => import("pages/wrapper-expose/other/sibling.vue")",
8176
"name": ""wrapper-expose-other-sibling"",
8277
"path": ""sibling"",
8378
},
79+
{
80+
"component": "() => import("layer/pages/wrapper-expose/other/index.vue")",
81+
"name": ""wrapper-expose-other"",
82+
"path": """",
83+
},
8484
],
8585
"component": "() => import("pages/wrapper-expose/other.vue")",
8686
"name": "mockMeta?.name",
@@ -193,16 +193,16 @@
193193
},
194194
],
195195
"should generate correct id for catchall (order 2)": [
196-
{
197-
"component": "() => import("pages/stories/[id].vue")",
198-
"name": ""stories-id"",
199-
"path": ""/stories/:id()"",
200-
},
201196
{
202197
"component": "() => import("pages/[...stories].vue")",
203198
"name": ""stories"",
204199
"path": ""/:stories(.*)*"",
205200
},
201+
{
202+
"component": "() => import("pages/stories/[id].vue")",
203+
"name": ""stories-id"",
204+
"path": ""/stories/:id()"",
205+
},
206206
],
207207
"should generate correct route for kebab-case file": [
208208
{
@@ -269,11 +269,6 @@
269269
},
270270
],
271271
"should handle route groups": [
272-
{
273-
"component": "() => import("pages/(foo)/index.vue")",
274-
"name": ""index"",
275-
"path": ""/"",
276-
},
277272
{
278273
"children": [
279274
{
@@ -286,6 +281,11 @@
286281
"name": "mockMeta?.name",
287282
"path": ""/about"",
288283
},
284+
{
285+
"component": "() => import("pages/(foo)/index.vue")",
286+
"name": ""index"",
287+
"path": ""/"",
288+
},
289289
],
290290
"should handle trailing slashes with index routes": [
291291
{
@@ -311,14 +311,14 @@
311311
],
312312
"should not generate colliding route names when hyphens are in file name": [
313313
{
314-
"component": "() => import("pages/parent/[child].vue")",
314+
"component": "() => import("pages/parent-[child].vue")",
315315
"name": ""parent-child"",
316-
"path": ""/parent/:child()"",
316+
"path": ""/parent-:child()"",
317317
},
318318
{
319-
"component": "() => import("pages/parent-[child].vue")",
319+
"component": "() => import("pages/parent/[child].vue")",
320320
"name": ""parent-child"",
321-
"path": ""/parent-:child()"",
321+
"path": ""/parent/:child()"",
322322
},
323323
],
324324
"should not merge required param as a child of optional param": [
@@ -344,11 +344,6 @@
344344
"name": ""b2.2b"",
345345
"path": ""/:b2.2b()"",
346346
},
347-
{
348-
"component": "() => import("pages/[b2]_[2b].vue")",
349-
"name": ""b2_2b"",
350-
"path": ""/:b2()_:2b()"",
351-
},
352347
{
353348
"component": "() => import("pages/[[c3@3c]].vue")",
354349
"name": ""c33c"",
@@ -359,6 +354,11 @@
359354
"name": ""d44d"",
360355
"path": ""/:d44d?"",
361356
},
357+
{
358+
"component": "() => import("pages/[b2]_[2b].vue")",
359+
"name": ""b2_2b"",
360+
"path": ""/:b2()_:2b()"",
361+
},
362362
],
363363
"should properly override route name if definePageMeta name override is defined.": [
364364
{

packages/nuxt/test/pages.test.ts

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

729+
const enUSComparator = new Intl.Collator('en-US')
730+
function sortRoutes (routes: NuxtPage[]) {
731+
for (const route of routes) {
732+
route.children &&= sortRoutes([...route.children])
733+
}
734+
return [...routes].sort((a, b) => enUSComparator.compare(b.path, a.path))
735+
}
736+
729737
for (const test of tests) {
730738
const _it = test.it || it
731739
_it(test.description, async () => {
@@ -736,11 +744,13 @@ describe('pages:generateRoutesFromFiles', () => {
736744
) as Record<string, string>
737745

738746
try {
739-
result = generateRoutesFromFiles(test.files.map(file => ({
747+
const files = test.files.map(file => ({
740748
shouldUseServerComponents: true,
741749
absolutePath: file.path,
742750
relativePath: file.path.replace(/^(pages|layer\/pages)\//, ''),
743-
}))).map((route, index) => {
751+
})).sort((a, b) => enUSComparator.compare(a.relativePath, b.relativePath))
752+
753+
result = generateRoutesFromFiles(files).map((route, index) => {
744754
return {
745755
...route,
746756
meta: test.files![index]!.meta,
@@ -756,7 +766,7 @@ describe('pages:generateRoutesFromFiles', () => {
756766
}
757767

758768
if (result) {
759-
expect.soft(result).toEqual(test.output)
769+
expect.soft(sortRoutes(result)).toEqual(test.output ? sortRoutes(test.output) : undefined)
760770

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

0 commit comments

Comments
 (0)