Registry / testing / eslint-tester

eslint-tester

JSON →
library0.8.2jsnpmunverified

eslint-tester is a utility package designed to facilitate testing within the ESLint project itself, and was initially intended for broader use by authors of custom ESLint rules. However, as of ESLint v1.0.0, this package has been deprecated and is no longer actively developed. Its functionality has been superseded by the `RuleTester` class, which is directly exposed within the main `eslint` package and is the recommended way to test ESLint rules. The package's last significant update (`v0.8.2`) was in June 2015, and its GitHub repository explicitly marks it as 'DEPRECATED'. Users should avoid this package and instead use `RuleTester` from `eslint` for current projects. The release cadence was irregular, with its primary focus being internal ESLint development.

npm install eslint-tester
INSTALL
IMPORT
SIG · ESLINT-TESTER
E
eslint-tester
testingjavascriptv0.8.2
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

ESLintTester
const ESLintTester = require('eslint-tester');
import { ESLintTester } from 'eslint-tester';
Primarily designed for CommonJS environments given its age. Modern Node.js projects should use `RuleTester` from `eslint` itself.

Demonstrates the conceptual usage of `eslint-tester` for defining and testing a simple custom ESLint rule. Note its deprecation.

const ESLintTester = require('eslint-tester'); // Mock a simple ESLint rule for demonstration const myCustomRule = { meta: { type: 'suggestion', schema: [], messages: { avoidFoo: 'Avoid using the identifier `foo`.' } }, create(context) { return { Identifier(node) { if (node.name === 'foo') { context.report({ node, messageId: 'avoidFoo' }); } } }; } }; // Instantiate ESLintTester (note: actual usage would involve an ESLint config) // This is a simplified example based on internal testing patterns. // In a real scenario, you'd pass a configured ESLint instance or path to rules. // As this package is deprecated, detailed external API examples are scarce. const tester = new ESLintTester(); // An example of a valid test case (no errors expected) const validCase = { code: 'const bar = 1;', parserOptions: { ecmaVersion: 6 } }; // An example of an invalid test case (errors expected) const invalidCase = { code: 'const foo = 2;', parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: 'avoidFoo', line: 1, column: 7 }] }; // Run a test (this API is inferred and might not match direct public usage perfectly for older versions) // The actual `eslint-tester` API is complex and meant for internal ESLint use. // For modern rule testing, use `RuleTester` directly from `eslint`. console.log('Running tests...'); // This part of the quickstart is conceptual as eslint-tester's public API for rule testing is not straightforward. // Its primary use was internal to ESLint development. // For actual rule testing, one would register rules and then run tests, similar to RuleTester. // const results = tester.run('my-custom-rule', myCustomRule, { valid: [validCase], invalid: [invalidCase] }); // console.log(results); console.log('`eslint-tester` is deprecated. Use `RuleTester` from `eslint` for modern rule testing.'); console.log('A complete runnable example for `eslint-tester` is difficult due to its internal-focused API and deprecation.');
Debug
Known issues
breakingAs of `v0.8.0`, test options are now validated, which may cause existing tests with malformed options to fail. This aligns `eslint-tester` with `eslint`'s more stringent configuration validation.
fix
Review all test case options for adherence to ESLint's configuration schema. Ensure properties like `code`, `errors`, `parserOptions` are correctly structured.
affects: >=0.8.0
deprecatedThe `eslint-tester` package has been officially deprecated since ESLint v1.0.0 and is no longer under active development. It has been replaced by the `RuleTester` class available directly in the `eslint` package.
fix
Migrate all rule testing logic to use `RuleTester` imported from the `eslint` package. Refer to the ESLint v1.0.0 migration guide for details.
affects: >=0.8.2
gotchaThe package's primary use was internal to the ESLint project development. Its public API, especially for external custom rule authors, was not extensively documented or stable. Attempting to use it for complex external rule testing may lead to unexpected behavior or API inconsistencies.
fix
For testing custom ESLint rules, use `RuleTester` from `eslint` (or `@typescript-eslint/rule-tester` for TypeScript rules) which provides a stable and well-documented API for this purpose.
affects: <=0.8.2
Errors
Common errors & fixes
TypeError: ESLintTester is not a constructor
Attempting to import `ESLintTester` using ES Modules syntax (`import`) in an environment that only supports CommonJS for this legacy package, or incorrect capitalization/destructuring.
fix
Ensure you are using CommonJS `require` syntax: `const ESLintTester = require('eslint-tester');`
Error: Missing definition for `afterAll` - you must set one using `RuleTester.afterAll` or there must be one defined globally as `afterAll`.
This specific error usually comes from `RuleTester` (the replacement for `eslint-tester`) but it signifies that the test environment lacks global hooks (`beforeAll`, `afterAll`, etc.) expected by test utilities. It might surface if `eslint-tester` internally relied on similar patterns, or when migrating tests away from `eslint-tester`.
fix
Ensure your test runner (e.g., Mocha, Jest, Vitest) is correctly configured to provide global test hooks, or explicitly set `RuleTester.afterAll` (and similar hooks) before running tests: `RuleTester.afterAll = require('mocha').after;` (or equivalent for your test framework).
Upgrade
Version history
0.8.2latest on npm
Audit
Dependencies
eslintrequiredRuntime dependency for linting capabilities.
is-my-json-validrequiredUsed internally for schema validation, moved to direct dependency in v0.8.1.
Agent activity
2 hits · last 30 days
node
2
Resources
eslint-tester — npm install eslint-tester · libregistry