StrykerJS Setup
StrykerJS is the only maintained general-purpose JavaScript mutation testing tool with per-test coverage analysis. There is no alternative worth offering.
Runner selection
| Detected | Runner | Notes |
|---|---|---|
vitest dependency or vitest.config.* |
@stryker-mutator/vitest-runner |
Matches what wp-prepare scaffolds. Preferred. |
@wordpress/scripts with test-unit-js |
@stryker-mutator/jest-runner |
Jest under the hood. Slower — Jest cannot bail inside Stryker. |
jest dependency directly |
@stryker-mutator/jest-runner |
|
| mocha / karma only | none | Report and stop. The command runner has no coverage analysis, so every mutant runs the entire suite. |
Vitest
npm install --save-dev @stryker-mutator/core @stryker-mutator/vitest-runnerstryker.config.json:
{
"$schema": "./node_modules/@stryker-mutator/core/schema/stryker-schema.json",
"testRunner": "vitest",
"vitest": {
"configFile": "vitest.config.js",
"related": true
},
"mutate": [
"src/**/*.{js,jsx,ts,tsx}",
"!src/**/*.{test,spec}.{js,jsx,ts,tsx}",
"!src/**/__tests__/**"
],
"ignorePatterns": ["build", "dist", "vendor", "languages", "node_modules"],
"reporters": ["clear-text", "progress", "html"],
"incremental": true,
"thresholds": { "high": 80, "low": 60, "break": null }
}Notes specific to the Vitest runner:
coverageAnalysisis ignored — the runner always usesperTest, which is the fastest mode anyway.- Stryker forces
singleThread: truebecause it runs its own parallel workers. Do not fight this. - Set
vitest.related: falseif tests do not import source directly (for example, tests that hit a running server). - Browser mode is not supported.
Jest via @wordpress/scripts
npm install --save-dev @stryker-mutator/core @stryker-mutator/jest-runner@wordpress/scripts hides its Jest config, so give Stryker an explicit one. jest.config.js:
module.exports = {
preset: '@wordpress/jest-preset-default',
};stryker.config.json:
{
"$schema": "./node_modules/@stryker-mutator/core/schema/stryker-schema.json",
"testRunner": "jest",
"jest": {
"projectType": "custom",
"configFile": "jest.config.js",
"enableFindRelatedTests": true
},
"mutate": [
"src/**/*.{js,jsx,ts,tsx}",
"!src/**/*.{test,spec}.{js,jsx,ts,tsx}",
"!src/**/__tests__/**"
],
"ignorePatterns": ["build", "dist", "vendor", "languages", "node_modules"],
"reporters": ["clear-text", "progress", "html"],
"incremental": true,
"thresholds": { "high": 80, "low": 60, "break": null }
}Jest always runs without bail inside Stryker, so expect it to be slower than Vitest on the same suite.
Commands
# Validate the config without mutating anything
npx stryker run --dryRunOnly
# Standard run
npx stryker run --incremental
# Narrow to one file while validating the loop
npx stryker run --mutate "src/utils/format-price.js"
# Re-check a single survivor by mutation range
npx stryker run --mutate "src/utils/format-price.js:12-18"
# Ratchet
npx stryker run --incremental --concurrency 4npm script:
{
"scripts": {
"test:mutate:js": "stryker run --incremental"
}
}Suppressing an equivalent mutant
// Stryker disable next-line StringLiteral: i18n text domain, asserted by the linter
const TEXT_DOMAIN = 'acme-plugin';
// Stryker disable all: in-source test suite below
if ( import.meta.vitest ) {
// ...
}Always include the reason after the colon.
WordPress-specific notes
ignorePatternsmust excludevendor/— this is not the default. Stryker copies the project into a sandbox, and a WordPress plugin root usually contains Composer'svendor/next to the JS. WithoutignorePatterns, Stryker'sdisableTypeCheckspreprocessor tries to parse every file it finds there, including PHP CodeSniffer's HTML test fixtures, and emits thousands ofParseErrorwarnings while building a needlessly huge sandbox. Adding"ignorePatterns": ["vendor", "build", "languages", ".git"]silences it completely — verified by re-running with only that key changed.- Ignore the build output.
@wordpress/scriptswrites tobuild/; mutating compiled bundles produces meaningless mutants and enormous sandboxes. - JS does not live in
src/.admin/src/,blocks/, andassets/src/are all common in plugins. Pointmutateat wherever the detector reported the sources, not atsrc/. - Block registration entry files are low value.
src/index.jsfiles that only callregisterBlockType()mutate into survivors that no unit test can kill, because their real behaviour lives in the editor. Pointmutateat the utility and domain modules. disableTypeChecksis on by default and is what makes TypeScript sources mutable at all. Leave it alone unless the sandbox fails to build.- Add to
.gitignore:.stryker-tmp/,reports/.