no-mixed-test-and-bench-apis
Disallow mixing Vitest bench() calls with test() or it() in the same file.
Rule catalog ID: R005
Targeted pattern scopeโ
- Vitest benchmark files
- repositories that keep tests and benchmarks close together
What this rule reportsโ
This rule reports files that use benchmark APIs and correctness-test APIs together.
Why this rule existsโ
Benchmarks answer a different question than tests.
- tests verify correctness
- benchmarks measure performance
Mixing them in the same file makes ownership, review, and execution intent harder to read.
โ Incorrectโ
import { bench, test } from "vitest";
test("adds numbers", () => {
expect(1 + 1).toBe(2);
});
bench("adds numbers", () => {
1 + 1;
});
โ Correctโ
import { test } from "vitest";
test("adds numbers", () => {
expect(1 + 1).toBe(2);
});
import { bench } from "vitest";
bench("adds numbers", () => {
1 + 1;
});
Behavior and migration notesโ
- keep correctness assertions in
.test.*or.spec.*files - keep performance checks in
.bench.*files or a dedicated benchmark folder
ESLint flat config exampleโ
import vite from "@typpi/eslint-plugin-vite";
export default [vite.configs.vitest, vite.configs["vitest-bench"]];
When not to use itโ
Disable this rule only if your repository intentionally treats tests and benchmarks as a single artifact.