Introduction to StrykerJS
masterStrykerJS is a mutation testing framework for JavaScript and related ecosystems. It supports a wide range of modern web and backend technologies, including:
- TypeScript
- React
- Angular
- VueJS
- Svelte
- NodeJS
repository·master·Indexed 25 days ago
https://github.com/stryker-mutator/stryker-jsStrykerJS 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.
StrykerJS is a mutation testing framework for JavaScript and related ecosystems. It supports a wide range of modern web and backend technologies, including:
The @stryker-mutator/tap-runner plugin allows you to use the Tap testing framework as your test runner within StrykerJS mutation testing workflows.
For detailed configuration and usage instructions, refer to the official StrykerJS documentation at https://stryker-mutator.io/docs/stryker-js/tap-runner.
StrykerJS is designed for "JavaScript and friends." It supports all test frameworks and all Babel-parsable JavaScript languages.
Supported examples include:
react-scripts.node-tap.Unsupported: Languages not parsable by Babel (e.g., CoffeeScript or Dart).
@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.
@stryker-mutator/jasmine-runner is a plugin that allows you to use Jasmine as the test runner for Node.js environments within StrykerJS mutation testing workflows. This is useful for projects that already use Jasmine for their unit testing suite.@stryker-mutator/typescript-checker is a plugin for StrykerJS that enables type checking on mutants. By using this plugin, StrykerJS can identify and skip mutants that result in TypeScript type errors, preventing unnecessary time spent running tests on mutants that are invalid due to type mismatches.@stryker-mutator/karma-runner plugin allows you to use the Karma test runner or the Angular CLI (ng test) as the test runner within StrykerJS for mutation testing. This is particularly useful for projects that rely on browser-based testing environments.@stryker-mutator/mocha-runner is a plugin that allows you to use the Mocha testing framework as the test runner within StrykerJS mutation testing workflows. For detailed configuration and usage instructions, refer to the official StrykerJS documentation.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 @.
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:
npm test as your test command.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 runFor 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-checkerjest (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"
}