Skip to content
← Back to rules

vitest/no-import-node-test Style

💡 A suggestion is available for this rule.

What it does ​

This rule warns when node:test is imported (usually accidentally). With --fix, it will replace the import with vitest.

Why is this bad? ​

Using node:test instead of vitest can lead to inconsistent test results and missing features. vitest should be used for all testing to ensure compatibility and access to its full functionality.

Examples ​

Examples of incorrect code for this rule:

javascript
import { test } from "node:test";
import { expect } from "vitest";

test("foo", () => {
  expect(1).toBe(1);
});

Examples of correct code for this rule:

javascript
import { test, expect } from "vitest";

test("foo", () => {
  expect(1).toBe(1);
});

How to use ​

To enable this rule using the config file or in the CLI, you can use:

json
{
  "plugins": ["vitest"],
  "rules": {
    "vitest/no-import-node-test": "error"
  }
}
ts
import { defineConfig } from "oxlint";

export default defineConfig({
  plugins: ["vitest"],
  rules: {
    "vitest/no-import-node-test": "error",
  },
});
bash
oxlint --deny vitest/no-import-node-test --vitest-plugin

Version ​

This rule was added in v0.7.0.

References ​