feat(admin): 改善工作台和账户消耗的等待、异常与移动体验
This commit is contained in:
@@ -0,0 +1,55 @@
|
||||
// Execute the production resolver and route-record factory against the actual Vite glob
|
||||
// inventory. A sentinel importer stands in for each .vue chunk for this Node-only test.
|
||||
const { test } = require('node:test')
|
||||
const assert = require('node:assert/strict')
|
||||
const { readFileSync, readdirSync } = require('node:fs')
|
||||
const path = require('node:path')
|
||||
const ts = require('typescript')
|
||||
const vueRouter = require('vue-router')
|
||||
|
||||
const admin = path.resolve(__dirname, '..')
|
||||
const keys = readdirSync(path.join(admin, 'src/views'), { recursive: true })
|
||||
.filter(name => name.endsWith('.vue')).map(name => '/src/views/' + name).sort()
|
||||
const views = Object.fromEntries(keys.map(key => [key, async () => key]))
|
||||
const source = readFileSync(path.join(admin, 'src/router/index.ts'), 'utf8')
|
||||
.replace("import.meta.glob('/src/views/**/*.vue')", 'views')
|
||||
.replace('import.meta.env.BASE_URL', "'/admin/'")
|
||||
const js = ts.transpileModule(source, { compilerOptions: { module: ts.ModuleKind.CommonJS,
|
||||
target: ts.ScriptTarget.ES2022 } }).outputText
|
||||
const api = {}
|
||||
const deps = {
|
||||
'vue-router': { ...vueRouter, createWebHistory: vueRouter.createMemoryHistory },
|
||||
'@/enums/appEnums': { MenuEnum: { MENU: 'C', CATALOGUE: 'M' } },
|
||||
'@/stores/modules/user': {}, '@/utils/validate': { isExternal: () => false },
|
||||
'./routes': { constantRoutes: [] }
|
||||
}
|
||||
new Function('exports', 'require', 'views', js)(api, id => {
|
||||
assert.ok(Object.hasOwn(deps, id), 'unexpected dependency: ' + id)
|
||||
return deps[id]
|
||||
}, views)
|
||||
|
||||
test('native workbench and assistant workbench resolve to their own SFC via real menu records', async () => {
|
||||
for (const component of ['workbench/index', 'assistant_service/workbench/index']) {
|
||||
const record = api.createRouteRecord({ type: 'C', paths: 'workbench', component, name: '工作台' }, true)
|
||||
assert.equal(await record.component(), '/src/views/' + component + '.vue')
|
||||
}
|
||||
})
|
||||
|
||||
test('every complete component path in the actual glob resolves exactly, including slash normalization', () => {
|
||||
assert.ok(keys.length > 0)
|
||||
for (const key of keys) {
|
||||
const relative = key.slice('/src/views/'.length, -'.vue'.length)
|
||||
assert.equal(api.loadRouteView('/' + relative + '/'), views[key], relative)
|
||||
}
|
||||
})
|
||||
|
||||
test('old abbreviated keys still resolve; empty or missing keys retain RouterView fallback', t => {
|
||||
const oldKey = keys.find(key => key.endsWith('/dept-tongji.vue'))
|
||||
assert.ok(oldKey)
|
||||
assert.equal(api.loadRouteView('dept-tongji'), views[oldKey])
|
||||
const errors = t.mock.method(console, 'error', () => {})
|
||||
for (const bad of ['', 'missing/not-a-view']) {
|
||||
assert.equal(api.loadRouteView(bad), vueRouter.RouterView)
|
||||
}
|
||||
assert.equal(errors.mock.callCount(), 2)
|
||||
})
|
||||
Reference in New Issue
Block a user