eslint-ava-rule-tester

raw JSON →
5.0.1 verified Sat Apr 25 auth: no javascript

ESLint RuleTester runner for AVA test framework. Wraps ESLint's RuleTester to produce per-test reports in AVA format. Current stable version 5.0.1, pure ESM, requires Node.js >=18 and ESLint >=8.7.0. Supports all RuleTester features including valid/invalid cases, fix output, and error options. Releases: v5 breaking change to ESM-only; v4 dropped Node <7 and upgraded to ESLint v6; v2 added support for AVA 0.19. Key differentiator: provides granular test results instead of a single pass/fail for the entire rule suite.

error Error [ERR_REQUIRE_ESM]: require() of ES Module not supported.
cause Trying to use require() with ESM-only package (v5+).
fix
Switch to import or use dynamic import: const AvaRuleTester = await import('eslint-ava-rule-tester');
error TypeError: Class extends value undefined is not a constructor or null
cause Missing or incompatible peer dependency, typically eslint is not installed or version is too low.
fix
Install eslint >=8.7.0 as a dev dependency.
error Cannot find module 'eslint-ava-rule-tester'
cause Package not installed or not in node_modules.
fix
Run npm install --save-dev eslint-ava-rule-tester
breaking v5.0.0 is pure ESM and requires Node.js >=18. CommonJS require() will not work.
fix Use import syntax and ensure Node.js version is >=18. If you must use CJS, upgrade to a dynamic import or pin to v4.x.
breaking v4.0.0 dropped support for Node.js <7 and requires ESLint v6 as peer dependency.
fix Upgrade Node.js to at least v8 and ESLint to v6 or higher.
breaking v2.0.1 requires AVA >=0.19 which enforces at least one assertion per test.
fix Ensure AVA version is at least 0.19.0.
breaking v5.0.0 changed the internal implementation to subclass RuleTester instead of modifying it. This may affect custom extensions.
fix If you were relying on prototype modifications to RuleTester, adapt to use the provided subclass instead.
npm install eslint-ava-rule-tester
yarn add eslint-ava-rule-tester
pnpm add eslint-ava-rule-tester

Shows how to create an AvaRuleTester instance, passing the AVA test function and ESLint config, then run valid and invalid test cases.

import test from 'ava';
import AvaRuleTester from 'eslint-ava-rule-tester';
import myRule from '../eslint-rules/my-rule.js';

const ruleTester = new AvaRuleTester(test, {
  languageOptions: {
    ecmaVersion: 2024,
  },
});

ruleTester.run('my-rule', myRule, {
  valid: [
    'valid code',
  ],
  invalid: [
    {
      code: 'invalid code',
      errors: [{ message: 'Error message' }],
    },
  ],
});