Getting started
Mootant makes small changes to your code, called mutants, and runs the tests that should notice them. A mutant that survives points to a test that is missing or too weak.
Mootant needs Node.js and tests on Vitest, Jest or Node Test, the test runner built into Node.js. The tests have to pass as they are: Mootant runs them without mutants first.
Node.js
20.19, 22.12 or later
Vitest
Version 5
Jest
Version 29.7+
Node Test
Built-in
See compatibility for test runner and framework limits. Vitest 5 does not support Node.js 20.
Add Mootant to the development dependencies of your project:
npm install -D mootantPoint Mootant at your source code:
npx mootant run srcMootant finds Vitest, Jest or Node Test and uses your existing configuration. The mutants are compiled into your code in memory, so your files stay untouched, and each mutant runs only the test files that reach it.
● mootant run src vitest 5.0.4
dry run 11 tests in 0.2s
mutants 26 in 3 files
time 1.5s (start 0.1s, dry run 0.2s, isolated 1.2s)
killed 25
survived 1
timeout 0
no coverage 0
score 96.15%
survived 1
src/discount.ts
2:7 comparison-operator q31p
- if (total >= 100 || isMember) {
+ if (total > 100 || isMember) {
test: test/discount.test.ts
re-check one: mootant run src --mutant q31p The report lists the mutants that survived, the ones no test reached and the ones that caused an error, file by file. Each mutant comes with:
comparison-operator: the mutator that made it-
q31p: its short id - The
-and+lines: the change test:: the test file to extend
re-check one: at the end of the report is the command that runs the first
survivor again.
This mutant is total → >= 100total > 100. The two versions differ only for
an order of exactly 100, and no test uses one. Move the slider to find it:
total >= 100 | 0 |
|---|---|
total > 100 | 0 |
Write a test with that value:
it('gives orders of exactly 100 10% off', () => {
expect(getDiscount(100, false)).toBe(10)
})Then run the mutant again by its id:
npx mootant run src --mutant q31p● mootant run src --mutant q31p vitest 5.1.0
dry run 26 tests in 0.4s
mutants 1 in 1 file
time 0.7s (start 0.2s, dry run 0.4s, isolated 0.1s)
killed 1
survived 0
timeout 0
no coverage 0
score 100% Verdicts are cached, so the next full run reuses them for mutants whose file and tests did not change.
Check only the lines a pull request changed, and fail the build when the mutation score drops below a threshold:
npx mootant run src --since origin/main --threshold 80The ref must exist locally: in CI, fetch the base branch with enough history to find its merge base. The CLI reference lists the other options.
Mootant ships with an agent skill. It reads the report, writes the missing tests and asks Mootant to confirm each kill:
npx skills add azat-io/mootant> fix the surviving mutants in src
$ mootant run src --json
{ …, "mutants": [{ …, "file": "src/discount.ts", "line": 2,
"after": [" if (total > 100 || isMember) {"],
"testFiles": { "test/discount.test.ts": 3, … },
"recheck": "mootant run src --mutant q31p780qv6yk" }] }
test/discount.test.ts
+ test('orders of exactly 100 get 10% off', () => {
+ expect(getDiscount(100, false)).toBe(10)
+ })
$ mootant run src --mutant q31p780qv6yk
killed 1
survived 0
score 100% The agent skill page shows what the skill changes in your project.