CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-jest-runner-eslint

An ESLint runner for Jest that integrates ESLint into the Jest testing framework for unified code testing and quality checks

Pending
Quality

Pending

Does it follow best practices?

Impact

Pending

No eval scenarios have been run

SecuritybySnyk

Pending

The risk profile of this skill

Overview
Eval results
Files

jest-runner.mddocs/

Jest Runner Integration

The main Jest runner that integrates ESLint into the Jest testing framework, treating linting as tests with full Jest compatibility.

Capabilities

Main Runner Export

The primary export that provides Jest runner functionality for ESLint integration.

/**
 * Jest runner that integrates ESLint into Jest testing workflow
 * Created using create-jest-runner with ESLint-specific configuration
 */
const runner = require("jest-runner-eslint");

Usage Examples:

// jest.config.js - Standalone runner
module.exports = {
  runner: 'jest-runner-eslint',
  displayName: 'lint',
  testMatch: ['<rootDir>/src/**/*.js'],
};

// jest.config.js - Multi-project setup
module.exports = {
  projects: [
    {
      displayName: 'test',
      testMatch: ['<rootDir>/src/**/*.test.js'],
    },
    {
      runner: 'jest-runner-eslint',
      displayName: 'lint',
      testMatch: ['<rootDir>/src/**/*.js'],
    },
  ],
};

ESLint Execution Engine

Core function that runs ESLint on individual files and formats results for Jest.

/**
 * Executes ESLint on a test file and returns Jest-compatible results
 * Supports both legacy and flat ESLint configurations automatically
 * @param testPath - Path to the file to lint
 * @param config - Jest configuration object
 * @param extraOptions - Additional options from runner (e.g., fix override)
 * @returns Promise resolving to Jest TestResult object
 */
async function runESLint({
  testPath: string,
  config: JestConfig,
  extraOptions: ExtraOptions
}): Promise<TestResult>;

interface JestConfig {
  rootDir: string;
  setupTestFrameworkScriptFile?: string;
  setupFilesAfterEnv?: string[];
  [key: string]: any;
}

interface ExtraOptions {
  fix?: boolean;
  [key: string]: any;
}

Usage Examples:

// Internal usage by Jest runner framework
const result = await runESLint({
  testPath: '/path/to/file.js',
  config: jestConfig,
  extraOptions: { fix: true }
});

// Result contains Jest-compatible test results
console.log(result.numFailingTests); // Number of ESLint errors
console.log(result.testResults); // Detailed error information

Test Result Formatting

Functions that convert ESLint output into Jest-compatible test results.

/**
 * Creates Jest TestResult object from ESLint execution data
 * @param options - Result creation options
 * @returns Jest TestResult object
 */
function mkTestResults({
  message?: string,
  start: number,
  end: number,
  numFailingTests: number,
  numPassingTests: number,
  testPath: string,
  assertionResults: TestAssertionResult[],
  cliOptions?: ESLintCliOptions
}): TestResult;

/**
 * Converts ESLint messages to Jest assertion results
 * @param testPath - Path to the file that was linted
 * @param report - ESLint report output
 * @returns Array of Jest assertion results
 */
function mkAssertionResults(
  testPath: string,
  report: ESLintReport[]
): TestAssertionResult[];

interface ESLintReport {
  messages: ESLintMessage[];
  errorCount: number;
  warningCount: number;
}

interface ESLintMessage {
  message: string;
  line: number;
  column: number;
  ruleId: string;
  severity: number;
}

Configuration Integration

Functions for integrating with Jest runner configuration and ESLint options.

/**
 * Computes the fix option value based on configuration
 * @param options - Configuration options
 * @returns Fix function or boolean value for ESLint
 */
function getComputedFixValue({
  fix?: boolean,
  quiet?: boolean,
  fixDryRun?: boolean
}): boolean | ((result: { severity: number }) => boolean) | undefined;

/**
 * Removes undefined values from configuration object
 * @param object - Configuration object to clean
 * @returns Object with undefined values removed
 */
function removeUndefinedFromObject(object: Record<string, any>): Record<string, any>;

/**
 * Gets cached ESLint instance and related functions
 * @param config - Jest configuration
 * @param extraOptions - Additional options
 * @returns Cached ESLint instance and utilities
 */
async function getCachedValues(
  config: JestConfig,
  extraOptions: ExtraOptions
): Promise<{
  isPathIgnored: (path: string) => Promise<boolean>;
  lintFiles: (files: string[]) => Promise<ESLintReport[]>;
  formatter: (results: ESLintReport[]) => Promise<string>;
  cliOptions: ESLintCliOptions;
  ESLintConstructor: typeof ESLint;
}>;

Usage Examples:

// Example of how ESLint execution handles different scenarios
const { isPathIgnored, lintFiles, formatter } = await getCachedValues(config, extraOptions);

// Check if file should be ignored
if (await isPathIgnored(testPath)) {
  return mkTestResults({
    start: Date.now(),
    end: Date.now(),
    testPath,
    numFailingTests: 0,
    numPassingTests: 0,
    assertionResults: [{
      title: 'ESLint',
      status: 'skipped',
    }],
  });
}

// Run ESLint and format results
const report = await lintFiles([testPath]);
const message = await formatter(report);

docs

configuration.md

index.md

jest-runner.md

watch-plugin.md

tile.json