我在我的项目中使用 Vitest,并尝试从 Vitest UI 获取覆盖率报告。我已按照文档中的步骤进行操作,但将鼠标悬停在覆盖范围图标上时收到错误“覆盖范围已启用但缺少 html 报告器”。
我已经在 vitest 配置中设置了 html 报告器,并且还设置了enabled=true,那么为什么我仍然看不到覆盖率报告?
这是我的 vitest 配置文件:
import { defineConfig } from 'vitest/config'
export default defineConfig({
test: {
coverage: {
provider: 'v8',
reporter: ['text', 'json', 'html'],
enabled: true,
},
},
})
原来这是由于 vitest 包版本不兼容造成的。我通过将我的 vitest 版本升级为与我的 package.json. 中的 @vitest/coverage-v8
相同来修复此问题确保运行
npm install
时不会产生有关 vitest 包的错误。