当不满足阈值时,vitest测试覆盖率不会失败



如果不满足阈值,我希望我的测试覆盖率失败

export default defineConfig({
plugins: [vue()],
test: {
environment: "happy-dom",
exclude: [...configDefaults.exclude, "**/tests/e2e/*"],
coverage: {
reporter: ['text', 'json', 'html'],
lines: 80,
functions: 80,
branches: 80,
statements: 80,
}
},

即使我收到错误消息,它仍然显示通过

File                    | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s 
------------------------|---------|----------|---------|---------|-------------------
All files               |     100 |    33.33 |     100 |     100 |                   
components/base/button |     100 |    33.33 |     100 |     100 |                   
Button.vue            |     100 |    33.33 |     100 |     100 | 36-53             
config                 |     100 |      100 |     100 |     100 |                   
index.ts              |     100 |      100 |     100 |     100 |                   
------------------------|---------|----------|---------|---------|-------------------
ERROR: Coverage for branches (33.33%) does not meet global threshold (80%)
PASS  Waiting for file changes...
press h to show help, press q to quit

有什么帮助吗?

我认为我的工作正常,我正在分享我的vite配置文件,希望它能帮助你:

/// <reference types="vitest" />
import { fileURLToPath, URL } from 'url';
import { defineConfig, loadEnv } from 'vite';
import vue from '@vitejs/plugin-vue';
import type { UserConfig as VitestUserConfigInterface } from 'vitest/config';
const vitestConfig: VitestUserConfigInterface = {
test: {
watch: false,
include: ['**/tests/unit/**/*.spec.{js,mjs,cjs,ts,mts,cts,jsx,tsx}'],
globals: true,
environment: 'jsdom',
reporters: ['verbose'],
coverage: {
include: ['src/**/*'],
exclude: [
'src/main.ts',
'src/plugins/',
'src/App.vue',
'src/shims-vue.d.ts',
'src/router/*',
'src/stores/*',
'src/types/*',
'src/components/icons/*'
],
reporter: ['text', 'json', 'html'],
all: true,
lines: 80,
functions: 80,
branches: 80,
statements: 80
}
}
};
export default defineConfig(({ mode }) => {
// https://github.com/vitejs/vite/issues/1149#issuecomment-857686209
const env = loadEnv(mode, process.cwd());
const envWithProcessPrefix = Object.entries(env).reduce(
(prev, [key, val]) => {
const [, keyNoVite] = key.split('VITE_');
return {
...prev,
['process.env.' + key]: `"${val}"`,
['process.env.' + keyNoVite]: `"${val}"`
};
},
{}
);
return {
define: envWithProcessPrefix,
test: vitestConfig.test,
resolve: {
alias: { '@': fileURLToPath(new URL('./src', import.meta.url)) }
},
plugins: [vue()]
};
});

您正在监视模式下运行测试(等待文件更改…(

使用此命令在没有监视模式的情况下运行:vitest run

或者,如果您想在监视模式ON下运行,请使用:vitest watch

最新更新