158 lines
8.0 KiB
TypeScript
158 lines
8.0 KiB
TypeScript
import { flushPromises, mount, shallowMount } from '@vue/test-utils'
|
||||
|
|
import type { Component } from 'vue'
|
|||
|
|
import { appPlugins, loginAsAdmin, mockBackend } from '../helpers/app'
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* 组件冒烟测试:逐个挂载 src/components 与 src/layout 下的组件(子组件浅渲染),
|
|||
|
|
* 走真实的 request 封装(网络层替换为空数据),断言能渲染出 DOM 且不抛异常。
|
|||
|
|
* 用于发现导入错误、setup 运行时异常、模板引用了不存在的变量等回归。
|
|||
|
|
*/
|
|||
|
|
const pages = import.meta.glob<{ default: Component }>('/src/{components,layout}/**/*.vue')
|
|||
|
|
|
|||
|
|
interface SmokeOptions {
|
|||
|
|
/** 必填 props 的最小合法值 */
|
|||
|
|
props?: Record<string, unknown>
|
|||
|
|
/** 父组件通过 provide 注入的数据 */
|
|||
|
|
provide?: Record<string, unknown>
|
|||
|
|
/** 通过 ref 调用子组件方法的页面需完整渲染子组件 */
|
|||
|
|
deep?: boolean
|
|||
|
|
/** 默认插槽内容 */
|
|||
|
|
slots?: Record<string, string>
|
|||
|
|
/** 无法在 jsdom 中渲染的页面,写明原因 */
|
|||
|
|
skip?: string
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
const node = (type: number, extra: Record<string, unknown> = {}) => ({
|
|||
|
|
id: `node-${type}`,
|
|||
|
|
name: '节点',
|
|||
|
|
type,
|
|||
|
|
showText: '',
|
|||
|
|
conditionNodes: [],
|
|||
|
|
...extra
|
|||
|
|
})
|
|||
|
|
|
|||
|
|
const options: Record<string, SmokeOptions> = {
|
|||
|
|
'/src/components/DictTag/src/DictTag.vue': { props: { type: 'common_status', value: 0 } },
|
|||
|
|
'/src/components/MarkdownView/index.vue': { props: { content: '# 标题\n\n正文' } },
|
|||
|
|
'/src/components/Highlight/src/Highlight.vue': { slots: { default: '财开云平台' } },
|
|||
|
|
'/src/components/Echart/src/Echart.vue': { skip: 'echarts 依赖 canvas,jsdom 不支持' },
|
|||
|
|
'/src/components/Qrcode/src/Qrcode.vue': { skip: '二维码绘制依赖 canvas,jsdom 不支持' },
|
|||
|
|
'/src/components/Cropper/src/CopperModal.vue': { skip: '裁剪依赖 canvas 与 cropperjs,jsdom 不支持' },
|
|||
|
|
'/src/components/Cropper/src/CropperAvatar.vue': { skip: '裁剪依赖 canvas 与 cropperjs,jsdom 不支持' },
|
|||
|
|
'/src/components/PublicView/src/PublicView.vue': {
|
|||
|
|
deep: true,
|
|||
|
|
props: {
|
|||
|
|
columns: [{ label: '名称', field: 'name' }],
|
|||
|
|
request: () => Promise.resolve({ list: [{ name: '张三' }], total: 1 })
|
|||
|
|
}
|
|||
|
|
},
|
|||
|
|
'/src/components/PublicView/src/components/PublicViewSearch.vue': {
|
|||
|
|
props: {
|
|||
|
|
columns: [{ label: '名称', field: 'name' }],
|
|||
|
|
params: {},
|
|||
|
|
config: { defaultCollapsed: false, labelWidth: 'auto', span: 6, showReset: true, collapseRows: 1 },
|
|||
|
|
fieldOptions: {},
|
|||
|
|
fieldLoading: {},
|
|||
|
|
fieldDisabled: {}
|
|||
|
|
}
|
|||
|
|
},
|
|||
|
|
'/src/components/PublicView/src/components/PublicViewSearchField.vue': {
|
|||
|
|
props: { column: { label: '名称', field: 'name', valueType: 'input' }, modelValue: '' }
|
|||
|
|
},
|
|||
|
|
'/src/components/PublicView/src/components/PublicViewTable.vue': {
|
|||
|
|
props: {
|
|||
|
|
columns: [{ label: '名称', field: 'name' }],
|
|||
|
|
data: [{ name: '张三' }],
|
|||
|
|
loading: false,
|
|||
|
|
config: { height: undefined, border: true, stripe: false, rowKey: 'id', selection: false, index: false },
|
|||
|
|
hasRequested: true
|
|||
|
|
}
|
|||
|
|
},
|
|||
|
|
'/src/components/PublicView/src/components/PublicViewTableColumn.vue': {
|
|||
|
|
props: { column: { label: '名称', field: 'name' } }
|
|||
|
|
},
|
|||
|
|
'/src/components/PublicView/src/components/PublicViewTabs.vue': {
|
|||
|
|
props: { tabs: [{ label: '全部', value: 'all' }], activeTab: 'all' }
|
|||
|
|
},
|
|||
|
|
'/src/components/PublicView/src/components/PublicViewToolbar.vue': {
|
|||
|
|
props: { tools: [{ label: '新增', key: 'add' }], selection: [] }
|
|||
|
|
},
|
|||
|
|
'/src/components/SimpleProcessDesignerV2/src/SimpleProcessDesigner.vue': {
|
|||
|
|
skip: '依赖完整模型数据与表单字段注入,在流程模型编辑页中浏览器回归'
|
|||
|
|
},
|
|||
|
|
'/src/components/SimpleProcessDesignerV2/src/nodes-config/UserTaskNodeConfig.vue': {
|
|||
|
|
props: { flowNode: node(11) }
|
|||
|
|
},
|
|||
|
|
'/src/components/SimpleProcessDesignerV2/src/nodes-config/components/HttpRequestSetting.vue': {
|
|||
|
|
props: {
|
|||
|
|
setting: { url: '', header: [], body: [], response: [] },
|
|||
|
|
responseEnable: true,
|
|||
|
|
formItemPrefix: 'httpRequestSetting'
|
|||
|
|
}
|
|||
|
|
},
|
|||
|
|
'/src/components/SimpleProcessDesignerV2/src/nodes/ChildProcessNode.vue': { props: { flowNode: node(20) } },
|
|||
|
|
'/src/components/SimpleProcessDesignerV2/src/nodes/CopyTaskNode.vue': { props: { flowNode: node(12) } },
|
|||
|
|
'/src/components/SimpleProcessDesignerV2/src/nodes/DelayTimerNode.vue': { props: { flowNode: node(14) } },
|
|||
|
|
'/src/components/SimpleProcessDesignerV2/src/nodes/ExclusiveNode.vue': { props: { flowNode: node(51) } },
|
|||
|
|
'/src/components/SimpleProcessDesignerV2/src/nodes/InclusiveNode.vue': { props: { flowNode: node(53) } },
|
|||
|
|
'/src/components/SimpleProcessDesignerV2/src/nodes/ParallelNode.vue': { props: { flowNode: node(52) } },
|
|||
|
|
'/src/components/SimpleProcessDesignerV2/src/nodes/RouterNode.vue': { props: { flowNode: node(54) } },
|
|||
|
|
'/src/components/SimpleProcessDesignerV2/src/nodes/StartUserNode.vue': { props: { flowNode: node(10) } },
|
|||
|
|
'/src/components/SimpleProcessDesignerV2/src/nodes/TriggerNode.vue': { props: { flowNode: node(15) } },
|
|||
|
|
'/src/components/SimpleProcessDesignerV2/src/nodes/UserTaskNode.vue': { props: { flowNode: node(11) } },
|
|||
|
|
'/src/components/bpmnProcessDesigner/package/designer/ProcessDesigner.vue': { skip: '依赖 bpmn-js 建模器实例(window.bpmnInstances),需在流程设计器中浏览器回归' },
|
|||
|
|
'/src/components/bpmnProcessDesigner/package/penal/signal-message/SignalAndMessage.vue': { skip: '依赖 bpmn-js 建模器实例(window.bpmnInstances),需在流程设计器中浏览器回归' },
|
|||
|
|
'/src/components/bpmnProcessDesigner/package/penal/task/ElementTask.vue': { skip: '依赖 bpmn-js 建模器实例(window.bpmnInstances),需在流程设计器中浏览器回归' },
|
|||
|
|
'/src/components/bpmnProcessDesigner/package/penal/task/task-components/ReceiveTask.vue': { skip: '依赖 bpmn-js 建模器实例(window.bpmnInstances),需在流程设计器中浏览器回归' },
|
|||
|
|
'/src/components/bpmnProcessDesigner/package/penal/task/task-components/ScriptTask.vue': { skip: '依赖 bpmn-js 建模器实例(window.bpmnInstances),需在流程设计器中浏览器回归' },
|
|||
|
|
'/src/components/bpmnProcessDesigner/package/penal/task/task-components/ServiceTask.vue': { skip: '依赖 bpmn-js 建模器实例(window.bpmnInstances),需在流程设计器中浏览器回归' },
|
|||
|
|
'/src/components/bpmnProcessDesigner/package/penal/task/task-components/UserTask.vue': { skip: '依赖 bpmn-js 建模器实例(window.bpmnInstances),需在流程设计器中浏览器回归' },
|
|||
|
|
'/src/components/bpmnProcessDesigner/package/penal/flow-condition/FlowCondition.vue': {
|
|||
|
|
skip: '依赖 bpmn-js 建模器实例(window.bpmnInstances),需在流程设计器中浏览器回归'
|
|||
|
|
},
|
|||
|
|
'/src/layout/components/TagsView/src/TagsView.vue': { skip: '依赖真实路由表与当前路由,在布局中浏览器回归' },
|
|||
|
|
'/src/layout/components/Breadcrumb/src/Breadcrumb.vue': { skip: '依赖真实路由表与当前路由,在布局中浏览器回归' },
|
|||
|
|
'/src/layout/components/CkyunHeader.vue': { props: { modules: [], activeModule: undefined } }
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
const entries = Object.keys(pages)
|
|||
|
|
.sort()
|
|||
|
|
.filter((path) => !options[path]?.skip)
|
|||
|
|
|
|||
|
|
describe('components / layout 冒烟渲染', () => {
|
|||
|
|
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,
|
|||
|
|
slots: option.slots,
|
|||
|
|
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()
|
|||
|
|
})
|
|||
|
|
})
|