Files
it/frontend/vitest.config.js
XCool f25b0307db
Some checks failed
CI/CD Pipeline / 测试 (18.x) (push) Has been cancelled
CI/CD Pipeline / 测试 (20.x) (push) Has been cancelled
CI/CD Pipeline / 安全检查 (push) Has been cancelled
CI/CD Pipeline / 部署 (push) Has been cancelled
CI/CD Pipeline / 通知 (push) Has been cancelled
初始化
2025-11-03 19:47:36 +08:00

97 lines
2.2 KiB
JavaScript

import { defineConfig } from 'vitest/config'
import vue from '@vitejs/plugin-vue'
import { resolve } from 'path'
export default defineConfig({
plugins: [vue()],
resolve: {
alias: {
'@': resolve(__dirname, './src')
}
},
test: {
// 启用类似Jest的API
globals: true,
// 测试环境
environment: 'jsdom',
// 包含的测试文件
include: [
'src/**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}',
'tests/**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}'
],
// 排除的测试文件
exclude: [
'node_modules',
'dist',
'.idea',
'.git',
'.cache'
],
// 覆盖率配置
coverage: {
// 启用覆盖率报告
enabled: true,
// 覆盖率报告格式
reporter: ['text', 'json', 'html'],
// 覆盖率输出目录
reportsDirectory: 'coverage',
// 覆盖率阈值
thresholds: {
global: {
branches: 80,
functions: 80,
lines: 80,
statements: 80
}
},
// 包含的文件
include: [
'src/**/*.{js,jsx,ts,tsx,vue}'
],
// 排除的文件
exclude: [
'src/main.js',
'src/**/*.d.ts',
'src/**/index.js',
'src/**/*.stories.{js,jsx,ts,tsx}',
'src/**/__tests__/**/*',
'src/**/test/**/*',
'src/**/*.test.{js,jsx,ts,tsx}',
'src/**/*.spec.{js,jsx,ts,tsx}'
]
},
// 测试超时时间(毫秒)
testTimeout: 10000,
// 钩子超时时间(毫秒)
hookTimeout: 10000,
// 并发测试
threads: true,
// 监听模式下是否只运行相关测试
watchExclude: [
'node_modules',
'dist',
'.idea',
'.git',
'.cache'
],
// 设置全局变量
setupFiles: ['./tests/setup.js'],
// 模拟文件
mockReset: true,
// 清除模拟
clearMocks: true,
// 强制退出
bail: 0,
// 详细输出
verbose: true,
// 静默输出
silent: false,
// 报告器
reporter: ['verbose', 'html', 'json'],
// 输出文件
outputFile: {
html: './tests/reports/index.html',
json: './tests/reports/report.json'
}
}
})