Files
caikai-assets/tests/unit/views/smoke.spec.ts
T
liujjandClaude Opus 5.5 2072c6780f
CI / build-and-test (push) Canceled after 0s
feat: 资产管理前端从管理端拆分为独立工程
以 ckcloudManage a44810c 为基础,只保留资产页面(台账、单据、基础数据、同步任务)、
登录/错误/个人资料等公共页面,以及资产单据“查看流程”用到的流程详情页;
统一登录应用编码默认 CK_ASSET,标题“资产管理”,本地端口 9090。

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-20 03:44:26 -08:00

68 lines
2.2 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { flushPromises, mount, shallowMount } from '@vue/test-utils'
import type { Component } from 'vue'
import { appPlugins, loginAsAdmin, mockBackend } from '../helpers/app'
/**
* 页面冒烟测试:逐个挂载 src/views 下的页面与页面组件(子组件浅渲染),
* 走真实的 request 封装(网络层替换为空数据),断言能渲染出 DOM 且不抛异常。
* 用于发现导入错误、setup 运行时异常、模板引用了不存在的变量等回归。
*/
const pages = import.meta.glob<{ default: Component }>('/src/views/**/*.vue')
interface SmokeOptions {
/** 必填 props 的最小合法值 */
props?: Record<string, unknown>
/** 父组件通过 provide 注入的数据 */
provide?: Record<string, unknown>
/** 通过 ref 调用子组件方法的页面需完整渲染子组件 */
deep?: boolean
/** 无法在 jsdom 中渲染的页面,写明原因 */
skip?: string
}
const options: Record<string, SmokeOptions> = {
'/src/views/Home/Index2.vue': { skip: 'echarts-wordcloud 依赖 canvas,jsdom 不支持' },
'/src/views/Redirect/Redirect.vue': { skip: '依赖路由 params.path,由路由守卫在浏览器中验证' },
'/src/views/Profile/components/BasicInfo.vue': { deep: true }
}
const entries = Object.keys(pages)
.sort()
.filter((path) => !options[path]?.skip)
describe('views 冒烟渲染', () => {
it('跳过的页面都写明了原因', () => {
for (const [path, option] of Object.entries(options)) {
expect(Object.keys(pages)).toContain(path)
if (option.skip !== undefined) expect(option.skip.length).toBeGreaterThan(5)
}
})
beforeEach(async () => {
await loginAsAdmin()
})
it.each(entries)('%s', async (path) => {
mockBackend()
const errors: unknown[] = []
const mod = await pages[path]()
const option = options[path] ?? {}
const wrapper = (option.deep ? mount : shallowMount)(mod.default, {
props: option.props,
global: {
plugins: appPlugins(),
provide: option.provide,
config: {
errorHandler: (err) => {
errors.push(err)
}
}
}
})
await flushPromises()
expect(errors).toEqual([])
expect(wrapper.html().length).toBeGreaterThan(0)
wrapper.unmount()
})
})