@systemfsoftware/stryker-js-vitest-runner
v8.1.1
Published
Vitest test-runner plugin for Stryker
Maintainers
Readme
@systemfsoftware/stryker-js-vitest-runner
Vitest test-runner plugin for Stryker mutation testing. Provides fast in-process sandboxing, per-test coverage tracking, and native TypeScript support.
Prerequisites
- Node.js
>=22.18.0 - Vitest
>=2.0.0 @systemfsoftware/stryker-js>=5.0.0
Install
pnpm add -D @systemfsoftware/stryker-js-vitest-runner vitestSetup in stryker.config.ts
Plugins in Stryker 5.0 take bare package names resolved from your project — no import.meta.resolve() needed:
import { defineConfig } from '@systemfsoftware/stryker-js/config'
export default defineConfig({
testRunner: 'vitest',
plugins: ['@systemfsoftware/stryker-js-vitest-runner'],
mutate: [
'src/**/*.ts',
'!src/**/*.test.ts',
'!src/**/*.d.ts',
],
})How It Works
- Dry-run phase: The Vitest runner executes your existing test suite, collecting per-test execution profiles and code coverage data.
- Mutant sandbox: During the mutation test phase, worker processes run only the subset of tests that cover each mutant, terminating early on test failure to maximize speed.
- Vitest Config: By default, Stryker automatically discovers your
vitest.config.tsorvite.config.ts. If your configuration is located elsewhere, specify it in your config:
export default defineConfig({
testRunner: 'vitest',
plugins: ['@systemfsoftware/stryker-js-vitest-runner'],
vitest: {
configFile: 'vitest.unit.config.ts',
},
})Worker pool
The runner uses the pool your Vitest config selects. Set pool: 'threads' in the runner's options to run every test file on Vitest's isolated threads pool instead, with no child processes. This is what testRunner: 'vm' in @systemfsoftware/stryker-js does. With pool set, a Vitest config that enables browser mode for any project is refused at startup; leave pool unset to run browser-mode suites.
export default defineConfig({
testRunner: {
plugin: '@systemfsoftware/stryker-js-vitest-runner',
options: { pool: 'threads' },
},
})In-Source Tests (import.meta.vitest)
If your project uses in-source testing with if (import.meta.vitest) blocks, add the companion ignorer plugin so unreachable test mutants are excluded from your score:
pnpm add -D @systemfsoftware/stryker-ignorer-in-source-vitest-blockexport default defineConfig({
testRunner: {
plugin: '@systemfsoftware/stryker-js-vitest-runner',
},
ignorers: ['@systemfsoftware/stryker-ignorer-in-source-vitest-block'],
})