or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

index.md
tile.json

tessl/npm-stryker-mutator--core

The extendable JavaScript mutation testing framework

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
npmpkg:npm/@stryker-mutator/core@9.1.x

To install, run

npx @tessl/cli install tessl/npm-stryker-mutator--core@9.1.0

index.mddocs/

Stryker Mutator Core

The extendable JavaScript mutation testing framework core package. StrykerJS systematically introduces small code changes (mutations) to test files to verify the effectiveness of your test suite. It provides a robust plugin architecture supporting multiple test runners and comprehensive reporting.

Package Information

  • Package Name: @stryker-mutator/core
  • Package Type: npm
  • Language: TypeScript
  • Installation: npm install @stryker-mutator/core
  • License: Apache-2.0
  • Node.js Version: >= 20.0.0

Core Imports

import { Stryker, StrykerCli } from "@stryker-mutator/core";

Default import for backward compatibility:

import Stryker from "@stryker-mutator/core";

Mixed import:

import Stryker, { StrykerCli } from "@stryker-mutator/core";

Basic Usage

Programmatic Usage

import { Stryker } from "@stryker-mutator/core";
import { PartialStrykerOptions, MutantResult } from "@stryker-mutator/api/core";

// Configure Stryker with options
const options: PartialStrykerOptions = {
  testRunner: 'jest',
  mutate: ['src/**/*.js', '!src/index.js'],
  reporters: ['html', 'clear-text'],
  coverageAnalysis: 'perTest'
};

// Create and run mutation testing
const stryker = new Stryker(options);
const results: MutantResult[] = await stryker.runMutationTest();

console.log(`Found ${results.length} mutants`);

CLI Usage

import { StrykerCli } from "@stryker-mutator/core";

// Create CLI instance with command line arguments
const cli = new StrykerCli(process.argv);
cli.run();

Architecture

Stryker Core is built around several key concepts:

  • Minimal Public API: Only 2 main exports despite extensive internal architecture
  • Plugin-Based Extension: Internal components accessible via plugin system, not direct exports
  • CLI-First Interface: Primary usage through command-line via StrykerCli
  • Configuration-Driven: Behavior controlled through configuration rather than programmatic API
  • Mutation Testing Process: Systematic introduction of code changes to validate test effectiveness

The package contains extensive internal functionality including process executors, reporters, configuration system, and DI container, but these are deliberately not exposed as public APIs.

Capabilities

Stryker Class

Main mutation testing orchestrator class that executes the complete mutation testing process.

class Stryker {
  /**
   * Creates a new Stryker instance
   * @param cliOptions - Configuration options for mutation testing
   * @param injectorFactory - Dependency injection factory (for testing purposes)
   */
  constructor(
    cliOptions: PartialStrykerOptions,
    injectorFactory?: Function
  );

  /**
   * Executes the complete mutation testing process
   * @returns Promise resolving to array of mutant test results
   */
  runMutationTest(): Promise<MutantResult[]>;
}

Usage Example:

import { Stryker } from "@stryker-mutator/core";

const stryker = new Stryker({
  testRunner: 'mocha',
  mutate: ['src/**/*.ts'],
  reporters: ['progress', 'html'],
  thresholds: { high: 80, low: 60, break: 50 }
});

const results = await stryker.runMutationTest();
console.log(`Mutation testing completed with ${results.length} mutants`);

StrykerCli Class

Command-line interface implementation providing CLI access to Stryker functionality.

import { Command } from 'commander';

class StrykerCli {
  /**
   * Creates a new StrykerCli instance
   * @param argv - Command line arguments array
   * @param program - Commander program instance (optional)
   * @param runMutationTest - Mutation test runner function (optional)
   * @param runMutationTestingServer - Mutation server runner function (optional)
   */
  constructor(
    argv: string[],
    program?: Command,
    runMutationTest?: (options: PartialStrykerOptions) => Promise<MutantResult[]>,
    runMutationTestingServer?: (options: PartialStrykerOptions) => Promise<void>
  );

  /**
   * Parses command line arguments and executes the appropriate command
   * Supports commands: run, init, runServer
   */
  run(): void;
}

Usage Example:

import { StrykerCli } from "@stryker-mutator/core";

// Create CLI with process arguments
const cli = new StrykerCli(process.argv);

// Run the CLI - will parse arguments and execute appropriate command
cli.run();

Supported CLI Commands:

  • run - Execute mutation testing
  • init - Initialize Stryker configuration for project
  • runServer - Start mutation testing server (implements mutation-server-protocol)

Types

The package relies on types from @stryker-mutator/api/core:

// Key configuration interface - comprehensive configuration options
interface PartialStrykerOptions {
  // Core testing configuration
  testRunner?: string;
  mutate?: string[];
  reporters?: string[];
  coverageAnalysis?: 'off' | 'all' | 'perTest';
  
  // File and pattern configuration
  files?: string[];
  ignorePatterns?: string[];
  ignoreStatic?: boolean;
  
  // Test execution configuration
  buildCommand?: string;
  dryRunOnly?: boolean;
  allowEmpty?: boolean;
  checkers?: string[];
  checkerNodeArgs?: string[];
  testRunnerNodeArgs?: string[];
  
  // Performance and concurrency
  concurrency?: number;
  maxConcurrentTestRunners?: number;
  maxTestRunnerReuse?: number;
  disableBail?: boolean;
  
  // Timeout configuration
  timeoutMS?: number;
  timeoutFactor?: number;
  dryRunTimeoutMinutes?: number;
  
  // Incremental mutation testing
  incremental?: boolean;
  incrementalFile?: string;
  force?: boolean;
  
  // Thresholds and reporting
  thresholds?: {
    high?: number;
    low?: number;
    break?: number;
  };
  dashboard?: {
    project?: string;
    version?: string;
    module?: string;
    baseUrl?: string;
    reportType?: 'full' | 'mutationScore';
  };
  
  // Directory and file management
  inPlace?: boolean;
  tempDirName?: string;
  cleanTempDir?: boolean | 'always';
  
  // Logging configuration
  logLevel?: 'fatal' | 'error' | 'warn' | 'info' | 'debug' | 'trace' | 'off';
  fileLogLevel?: 'fatal' | 'error' | 'warn' | 'info' | 'debug' | 'trace' | 'off';
  allowConsoleColors?: boolean;
  
  // Plugin configuration
  plugins?: string[];
  appendPlugins?: string[];
  
  // Configuration file
  configFile?: string;
  
  // ... many other advanced configuration properties
}

// Result of mutation testing - key properties shown
interface MutantResult {
  id: string;
  mutatorName: string;
  replacement: string;
  fileName: string;
  status: MutantStatus;
  statusReason?: string;
  // ... additional result properties from mutation-testing-report-schema
}

// Mutation status enumeration
type MutantStatus = 'Killed' | 'Survived' | 'NoCoverage' | 'TimedOut' | 'CompileError' | 'RuntimeError';

CLI Binary

The package provides the stryker CLI binary as the primary interface for mutation testing:

# Run mutation testing (most common usage)
npx stryker run

# Initialize Stryker configuration
npx stryker init

# Start mutation testing server
npx stryker runServer

# Direct binary execution
./node_modules/.bin/stryker run

# Via npm script (add to package.json)
npm run stryker

# Global installation
npm install -g @stryker-mutator/core
stryker run

Common CLI Options:

# Specify files to mutate
stryker run --mutate "src/**/*.js" --testRunner jest

# Set coverage analysis strategy
stryker run --coverageAnalysis perTest

# Configure reporters
stryker run --reporters html,clear-text,progress

# Set concurrency
stryker run --concurrency 4

# Incremental mutation testing
stryker run --incremental

Error Handling

The package handles errors through several mechanisms:

  • ConfigError: Thrown for configuration validation issues
  • Promise Rejection: runMutationTest() returns rejected promises for mutation testing failures
  • CLI Exit Codes: CLI exits with code 1 on failures
  • Node Version Guard: Throws errors for unsupported Node.js versions
import { Stryker } from "@stryker-mutator/core";

try {
  const stryker = new Stryker({
    testRunner: 'jest',
    mutate: ['src/**/*.js']
  });
  const results = await stryker.runMutationTest();
  console.log(`Mutation testing completed: ${results.length} mutants tested`);
} catch (error) {
  if (error.name === 'ConfigError') {
    console.error('Configuration error:', error.message);
  } else if (error.message.includes('Node.js version')) {
    console.error('Node.js version incompatibility:', error.message);
  } else {
    console.error('Mutation testing failed:', error.message);
  }
  process.exit(1);
}