import test from 'node:test' import assert from 'node:assert/strict' import { existsSync } from 'node:fs' import { join } from 'node:path' import { readSource, occurrences } from './helpers.ts' import { adminPages } from '../src/router/routes.ts' const ROUTER = 'src/router/index.ts' const NOT_FOUND = 'src/pages/error/NotFoundPage.vue' test('test_task_012_route_error_page_normal_primary_path', () => { // 正常主路径:未知路径注册到路由级错误页兜底。 const router = readSource(ROUTER) assert.match(router, /path:\s*':pathMatch\(\.\*\)\*'/) assert.match(router, /NotFoundPage/) assert.match(router, /页面不存在/) }) test('test_task_012_route_error_page_normal_variant_input', () => { // 正常变体:错误页在 AdminLayout children 内,保留壳层 chrome。 const router = readSource(ROUTER) const catchAllIndex = router.indexOf(':pathMatch(.*)*') const registryIndex = router.indexOf('adminRouteRecords.map') assert.ok(catchAllIndex > registryIndex, 'catch-all 应在业务路由之后注册') assert.match(router, /path: '\/',/) }) test('test_task_012_route_error_page_normal_repeated_operation_is_idempotent', () => { // 正常重复:错误页注册不重复追加。 const first = readSource(ROUTER) assert.equal(occurrences(first, ':pathMatch(.*)*'), 1) }) test('test_task_012_route_error_page_boundary_empty_input', () => { // 边界空值:错误页文件存在,且不进入业务路由注册表。 assert.equal(existsSync(join(process.cwd(), NOT_FOUND)), true) // 业务路由条目与页面定义一一对应;错误页不占用其中任何一条。 const router = readSource(ROUTER) assert.equal(occurrences(router, '...adminRouteRecords'), 1, '错误页不应计入业务路由') assert.ok(adminPages.length >= 18, '业务页至少 18(随版本递增,不设上限断言)') }) test('test_task_012_route_error_page_boundary_single_item', () => { // 边界单元素:错误页是单一 Vue 页面组件。 const source = readSource(NOT_FOUND) assert.equal(occurrences(source, '