{"id":10844,"library":"eslint-tester","title":"ESLint Test Utility","description":"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.","status":"deprecated","version":"0.8.2","language":"javascript","source_language":"en","source_url":"https://github.com/eslint/eslint-tester","tags":["javascript","eslint","test"],"install":[{"cmd":"npm install eslint-tester","lang":"bash","label":"npm"},{"cmd":"yarn add eslint-tester","lang":"bash","label":"yarn"},{"cmd":"pnpm add eslint-tester","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Runtime dependency for linting capabilities.","package":"eslint"},{"reason":"Used internally for schema validation, moved to direct dependency in v0.8.1.","package":"is-my-json-valid"}],"imports":[{"note":"Primarily designed for CommonJS environments given its age. Modern Node.js projects should use `RuleTester` from `eslint` itself.","wrong":"import { ESLintTester } from 'eslint-tester';","symbol":"ESLintTester","correct":"const ESLintTester = require('eslint-tester');"}],"quickstart":{"code":"const ESLintTester = require('eslint-tester');\n\n// Mock a simple ESLint rule for demonstration\nconst myCustomRule = {\n  meta: {\n    type: 'suggestion',\n    schema: [],\n    messages: {\n      avoidFoo: 'Avoid using the identifier `foo`.'\n    }\n  },\n  create(context) {\n    return {\n      Identifier(node) {\n        if (node.name === 'foo') {\n          context.report({ node, messageId: 'avoidFoo' });\n        }\n      }\n    };\n  }\n};\n\n// Instantiate ESLintTester (note: actual usage would involve an ESLint config)\n// This is a simplified example based on internal testing patterns.\n// In a real scenario, you'd pass a configured ESLint instance or path to rules.\n// As this package is deprecated, detailed external API examples are scarce.\nconst tester = new ESLintTester();\n\n// An example of a valid test case (no errors expected)\nconst validCase = {\n  code: 'const bar = 1;',\n  parserOptions: { ecmaVersion: 6 }\n};\n\n// An example of an invalid test case (errors expected)\nconst invalidCase = {\n  code: 'const foo = 2;',\n  parserOptions: { ecmaVersion: 6 },\n  errors: [{ messageId: 'avoidFoo', line: 1, column: 7 }]\n};\n\n// Run a test (this API is inferred and might not match direct public usage perfectly for older versions)\n// The actual `eslint-tester` API is complex and meant for internal ESLint use.\n// For modern rule testing, use `RuleTester` directly from `eslint`.\nconsole.log('Running tests...');\n// This part of the quickstart is conceptual as eslint-tester's public API for rule testing is not straightforward.\n// Its primary use was internal to ESLint development.\n// For actual rule testing, one would register rules and then run tests, similar to RuleTester.\n// const results = tester.run('my-custom-rule', myCustomRule, { valid: [validCase], invalid: [invalidCase] });\n// console.log(results);\nconsole.log('`eslint-tester` is deprecated. Use `RuleTester` from `eslint` for modern rule testing.');\nconsole.log('A complete runnable example for `eslint-tester` is difficult due to its internal-focused API and deprecation.');","lang":"javascript","description":"Demonstrates the conceptual usage of `eslint-tester` for defining and testing a simple custom ESLint rule. Note its deprecation."},"warnings":[{"fix":"Review all test case options for adherence to ESLint's configuration schema. Ensure properties like `code`, `errors`, `parserOptions` are correctly structured.","message":"As 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.","severity":"breaking","affected_versions":">=0.8.0"},{"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.","message":"The `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.","severity":"deprecated","affected_versions":">=0.8.2"},{"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.","message":"The 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.","severity":"gotcha","affected_versions":"<=0.8.2"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"fix":"Ensure you are using CommonJS `require` syntax: `const ESLintTester = require('eslint-tester');`","cause":"Attempting to import `ESLintTester` using ES Modules syntax (`import`) in an environment that only supports CommonJS for this legacy package, or incorrect capitalization/destructuring.","error":"TypeError: ESLintTester is not a constructor"},{"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).","cause":"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`.","error":"Error: Missing definition for `afterAll` - you must set one using `RuleTester.afterAll` or there must be one defined globally as `afterAll`."}],"ecosystem":"npm"}