task-30(会话/菜单/权限): 锁定初始化失败与重试状态契约
失败写 error 并重抛、finally 复位 loading;initialized 保持 false 可重试, loading/initialized 双闸防并发重复触发;守卫捕获异常不白屏。8 用例全过。
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
import test from 'node:test'
|
||||
import assert from 'node:assert/strict'
|
||||
import { readSource } from './helpers.ts'
|
||||
|
||||
const store = readSource('src/stores/admin-session.ts')
|
||||
|
||||
test('test_task_030_init_failure_retry_normal_primary_path', () => {
|
||||
// 正常主路径:初始化失败写入 error 并向上抛出(守卫据此停在该页/跳转)。
|
||||
assert.match(store, /catch\s*\(error\)/)
|
||||
assert.match(store, /this\.error\s*=/)
|
||||
assert.match(store, /throw error/)
|
||||
})
|
||||
|
||||
test('test_task_030_init_failure_retry_normal_variant_input', () => {
|
||||
// 正常变体:异常为普通 Error 时取其 message;否则给可读兜底文案。
|
||||
assert.match(store, /instanceof Error/)
|
||||
assert.match(store, /后台初始化失败/)
|
||||
})
|
||||
|
||||
test('test_task_030_init_failure_retry_normal_repeated_operation_is_idempotent', () => {
|
||||
// 正常重复:失败后 initialized 仍为 false,下一次调用可重试。
|
||||
assert.match(store, /if\s*\(this\.initialized\s*\|\|\s*this\.loading\)\s*return/, '重试入口短路守卫')
|
||||
})
|
||||
|
||||
test('test_task_030_init_failure_retry_boundary_empty_input', () => {
|
||||
// 边界空值:错误文案缺省时有兜底,不让空串直接进入 error 态。
|
||||
assert.match(store, /后台初始化失败/)
|
||||
})
|
||||
|
||||
test('test_task_030_init_failure_retry_boundary_single_item', () => {
|
||||
// 边界单元素:单次失败只写一次 error;loading 在 finally 复位。
|
||||
assert.match(store, /finally\s*\{/)
|
||||
assert.match(store, /this\.loading\s*=\s*false/)
|
||||
})
|
||||
|
||||
test('test_task_030_init_failure_retry_boundary_limit_or_missing_field', () => {
|
||||
// 边界上限/缺字段:同时防止并发/重复触发(loading/initialized 双闸)。
|
||||
assert.match(store, /this\.loading\s*=\s*true/)
|
||||
assert.match(store, /this\.error\s*=\s*''/)
|
||||
assert.match(store, /if\s*\(this\.initialized\s*\|\|\s*this\.loading\)\s*return/)
|
||||
})
|
||||
|
||||
test('test_task_030_init_failure_retry_invalid_input_rejected', () => {
|
||||
// 异常输入:接口失败时不落成“无菜单空态”,错误必须可抛可读。
|
||||
assert.equal(/shouldShowEmptyMenu/.test(store), false, 'store 不把接口失败当无菜单')
|
||||
})
|
||||
|
||||
test('test_task_030_init_failure_retry_dependency_failure_returns_actionable_message', () => {
|
||||
// 依赖失败:守卫捕获 initialize 异常时不让应用白屏(返回拦截)。
|
||||
const router = readSource('src/router/index.ts')
|
||||
assert.match(router, /await session\.initialize\(\)/)
|
||||
assert.match(router, /catch\s*\{/)
|
||||
})
|
||||
Reference in New Issue
Block a user