vitest/no-focused-tests Correctness
作用
此规则会在你使用排他性特性时发出警告,提醒你从测试中移除 .only。
为什么这不好?
Jest 有一个特性,允许你通过在测试套件或测试用例后追加 .only,或者在前面加上 f 来聚焦测试。这个特性对于调试失败的测试非常有用,这样你就不必执行所有测试。等你修复测试之后,在提交更改之前,你必须移除 .only,以确保构建系统会执行所有测试。
示例
以下是此规则的错误代码示例:
javascript
describe.only("foo", () => {});
it.only("foo", () => {});
describe["only"]("bar", () => {});
it["only"]("bar", () => {});
test.only("foo", () => {});
test["only"]("bar", () => {});
fdescribe("foo", () => {});
fit("foo", () => {});
fit.each`
table
`();如何使用
To enable this rule using the config file or in the CLI, you can use:
json
{
"plugins": ["vitest"],
"rules": {
"vitest/no-focused-tests": "error"
}
}ts
import { defineConfig } from "oxlint";
export default defineConfig({
plugins: ["vitest"],
rules: {
"vitest/no-focused-tests": "error",
},
});bash
oxlint --deny vitest/no-focused-tests --vitest-plugin版本
此规则是在 v0.0.8 中添加的。
