StrykerJS Documentation

repository·master·Indexed 25 days ago

https://github.com/stryker-mutator/stryker-js

StrykerJS is a mutation testing framework for JavaScript that injects mutants into code to measure test suite effectiveness. It supports various test runners including Jest, Mocha, Jasmine, Karma, Tap, and CucumberJS, and provides a TypeScript checker to skip mutants with type errors. The framework is extensible via plugins for mutators, reporters, and test runners, and can be configured through a CLI, JSON, or JavaScript configuration files.

Tokens
27.8K
Snippets
96
Records
206
Agent score
84%

What's inside StrykerJS

  1. Understand the scope of StrykerJS

    master

    StrykerJS is designed for "JavaScript and friends." It supports all test frameworks and all Babel-parsable JavaScript languages.

    Supported examples include:

    • TypeScript with Mocha.
    • Flow with Jest.
    • React projects using react-scripts.
    • Angular projects using the Angular CLI.
    • Vue projects using the Vue CLI.
    • Koa.js apps with node-tap.
    • Plain ES5 projects.

    Unsupported: Languages not parsable by Babel (e.g., CoffeeScript or Dart).

  2. Use CucumberJS with StrykerJS via @stryker-mutator/cucumber-runner

    master

    @stryker-mutator/cucumber-runner is a plugin that allows you to use CucumberJS as the test runner within the StrykerJS mutation testing framework. This enables mutation testing for projects that rely on CucumberJS for behavior-driven development (BDD).

    For detailed configuration and usage instructions, refer to the official StrykerJS documentation: https://stryker-mutator.io/docs/stryker-js/cucumber-runner.

  3. Use Globbing Expressions in Configuration Options

    master

    Options that refer to source files, such as ignorePatterns and mutate, support globbing expressions via node-glob. You can use standard .gitignore-style patterns.

    Command Line Warning: When using globbing patterns (especially those containing * or **) on the command line, you must escape them to prevent your shell (e.g., bash, cmd, or powershell) from expanding them. Use double quotes or backslashes around strings containing *, **, !, ?, +, [], (), or @.

  4. Get started with StrykerJS for small projects

    master

    For small JavaScript projects, you can quickly set up and run StrykerJS by installing the core package and using the npx stryker run command. By default, this configuration:

    • Uses npm test as your test command.
    • Searches for files to mutate in the lib and src directories.

    Note: This approach is intended only for small projects. For larger projects, follow the full configuration guide on the official website.

    pnpm add --save-dev @stryker-mutator/core
    # Only for small projects:
    npx stryker run
  5. Set up StrykerJS for React TSX projects

    master

    For React projects using TypeScript and TSX, you must include the TypeScript checker to ensure mutations don't break type safety.

    Required packages:

    • @stryker-mutator/core
    • @stryker-mutator/jest-runner
    • @stryker-mutator/typescript-checker
    • jest (version 23.0.0 or higher)

    Create a stryker.config.json file in your repository root with the following configuration, ensuring the tsconfigFile points to your actual TypeScript configuration file.

    npm i -D @stryker-mutator/core @stryker-mutator/jest-runner @stryker-mutator/typescript-checker
    {
      "testRunner": "jest",
      "jest": {
        "projectType": "create-react-app"
      },
      "checkers": ["typescript"],
      "tsconfigFile": "tsconfig.json"
    }