eslint-node-test
ESLint rules for the Node.js built-in test runner (`node:test`)
An ESLint plugin with rules that catch mistakes and enforce consistency in tests written for Node.js's built-in test runner.
eslint-node-test is a plugin for ESLint, the popular JavaScript code checking tool, that focuses specifically on tests written with node:test, the test runner built directly into Node.js. Its job is to catch common mistakes in how tests are written and to nudge every test file in a project toward a more consistent style, the same way ESLint already does for regular application code.
Setting it up means installing it alongside ESLint and adding it to a project's ESLint configuration file, either by turning on one of the ready made presets or by picking specific rules to enable one at a time. It requires a fairly recent version of ESLint that uses the newer flat config format, along with a project set up to use ES modules rather than the older CommonJS style. The rules are written so they only turn on inside files that actually import from node:test or Node's built in assert module, so the plugin can safely be applied across an entire codebase without interfering with unrelated files.
The plugin ships a large collection of individual rules, each targeting a specific pattern such as enforcing a consistent order for setup and teardown hooks, disallowing assertions written directly inside a describe block instead of inside an actual test, requiring async test functions to actually use await, and preventing tests from mixing callback and Promise based styles at the same time. Several of these rules can automatically fix the code for you when ESLint is run with its fix option, while others offer suggested fixes that a developer can apply manually inside their editor.
Where it fits
- Catch common mistakes in tests written with Node.js's built-in node:test runner.
- Enforce a consistent order for test setup and teardown hooks across a project.
- Automatically fix simple test style issues using ESLint's fix option.
- Prevent tests from mixing callback style and Promise style in the same test.