feat: warn on _parent conflict · vuejs/router@182fe03 (original) (raw)
1
1
`import { describe, expect, it } from 'vitest'
`
2
2
`import { DEFAULT_OPTIONS, Options, resolveOptions } from '../options'
`
3
``
`-
import { PrefixTree, TreeNodeValueMatcherPart } from './tree'
`
``
3
`+
import {
`
``
4
`+
collectParentConflicts,
`
``
5
`+
PrefixTree,
`
``
6
`+
TreeNodeValueMatcherPart,
`
``
7
`+
} from './tree'
`
4
8
`import { TreeNodeType, type TreePathParam } from './treeNodeValue'
`
5
9
`import { resolve } from 'pathe'
`
6
10
`import { mockWarn } from '../../tests/vitest-mock-warn'
`
`@@ -1185,6 +1189,36 @@ describe('Tree', () => {
`
1185
1189
`expect(c.value.components.get('default')).toBe('a/b/c/_parent.vue')
`
1186
1190
`expect(c.children.has('_parent')).toBe(false)
`
1187
1191
`})
`
``
1192
+
``
1193
`+
it('collects _parent conflicts', () => {
`
``
1194
`+
const tree = new PrefixTree(RESOLVED_OPTIONS)
`
``
1195
`+
tree.insert('nested/_parent', 'nested/_parent.vue')
`
``
1196
`+
tree.insert('nested', 'nested.vue')
`
``
1197
+
``
1198
`+
expect(collectParentConflicts(tree)).toEqual([
`
``
1199
`+
{
`
``
1200
`+
routePath: '/nested',
`
``
1201
`+
parentFilePath: 'nested/_parent.vue',
`
``
1202
`+
filePath: 'nested.vue',
`
``
1203
`+
},
`
``
1204
`+
])
`
``
1205
`+
})
`
``
1206
+
``
1207
`+
it('keeps nested children when removing same-name file', () => {
`
``
1208
`+
const tree = new PrefixTree(RESOLVED_OPTIONS)
`
``
1209
`+
tree.insert('nested', 'nested.vue')
`
``
1210
`+
tree.insert('nested/_parent', 'nested/_parent.vue')
`
``
1211
`+
tree.insert('nested/index', 'nested/index.vue')
`
``
1212
`+
tree.insert('nested/other', 'nested/other.vue')
`
``
1213
+
``
1214
`+
tree.removeChild('nested.vue')
`
``
1215
+
``
1216
`+
const nested = tree.children.get('nested')!
`
``
1217
`+
expect(nested).toBeDefined()
`
``
1218
`+
expect(nested.value.components.get('default')).toBe('nested/_parent.vue')
`
``
1219
`+
expect(nested.children.has('index')).toBe(true)
`
``
1220
`+
expect(nested.children.has('other')).toBe(true)
`
``
1221
`+
})
`
1188
1222
`})
`
1189
1223
``
1190
1224
`describe('Empty parameter names', () => {
`