# Mootant

> Mutation testing for JavaScript and TypeScript

**Find the tests that test nothing.** Mootant changes your code in hundreds of small ways and runs the tests that should notice. The mutants that survive are the gaps in your suite, and the agent skill in the box knows how to close them.

```sh
npm install -D mootant
```

- [Get Started](https://mootant.org/guide/getting-started.md)
- [View on GitHub](https://github.com/azat-io/mootant)

## Coverage lies

Coverage shows which lines ran. It can't tell whether any test would notice them change.

**Code coverage**, `vitest run --coverage`: 100%. Every statement, branch and line ran.

| File | Stmts | Branch | Lines |
| --- | --- | --- | --- |
| cart.ts | 100% | 100% | 100% |
| discount.ts | 100% | 100% | 100% |
| shipping.ts | 100% | 100% | 100% |

**Mutation testing**, `mootant run src`: 1 survived of 26 mutants, score 96.15%.

`src/discount.ts:2:7`:

```diff
- if (total >= 100 || isMember) {
+ if (total > 100 || isMember) {
```

No test checks an order of exactly 100, so all 11 tests still pass.

## Why Mootant

Mutation testing is often slow, noisy, and hard to act on. Mootant was built to fix all three.

### Less noise

Mootant skips duplicate, likely equivalent, and likely hanging mutants, so you spend less time investigating false alarms.

### Finds hidden gaps

Mootant mutates numbers, return values, and awaits-not just operators-to expose tests that miss changes in behavior.

### Fast reruns

Mootant caches results and tracks their dependencies. Mutants unaffected by your changes don't need to run again.

### Ready for CI

Test only the lines changed in a pull request, and fail CI when the mutation score falls below your threshold.

### Actionable reports

Every survivor shows the code change and a suggested test file to improve. Uncovered mutants are reported separately.

### Fits your stack

Use your existing Vitest, Jest or Node Test setup. JavaScript and TypeScript work with all three, Vue and Svelte with Vitest.

## How it works

### 01 · Instrument: Built once, switched at runtime

Mootant picks the changes worth testing and compiles them all into your code in memory, each behind a switch. Your files stay untouched.

### 02 · Run: Each mutant on its own

A dry run maps which test files reach which mutant. Then every mutant runs alone, on a fresh module graph, with only those files, until a test fails.

### 03 · Fix: Survivors become tests

Each survivor comes with a diff, the test file to extend and a command to re-check it. Fix it yourself or hand it to the agent skill.

## Ships with an agent skill

Mutation testing produces a to-do list that nobody wants to work through by hand.

The skill reads the report, writes the missing tests and asks Mootant to confirm each kill. You review the new tests.

```sh
npx skills add azat-io/mootant
```

## Works with your stack

### File extensions

`.js`, `.mjs`, `.cjs`, `.jsx`, `.ts`, `.mts`, `.cts`, `.tsx`, `.vue`, `.svelte`

### Test runners

- Vitest: `^5.0.0`
- Jest: `^29.7.0 || ^30.0.0`
- Node Test: `^20.19.0 || >=22.12.0`

## See what survives

The report of a small sample shop: scores, every mutant in its code and what each test reaches.

Add `--html` to a run to write the same report for your project.

[View Demo](https://mootant.org/reports/html/demo)

## Documentation

### Guide

- [Getting started](https://mootant.org/guide/getting-started.md): Install Mootant, run it against your tests and turn the mutants that survive into better tests.
- [CLI reference](https://mootant.org/guide/cli.md): List mutants, run your tests against them and choose the scope, output and passing score with Mootant's command line options.
- [Configuration](https://mootant.org/guide/configuration.md): Set the presets, mutators and their options, shared settings and the defaults of mootant run in a configuration file.
- [Compatibility](https://mootant.org/guide/compatibility.md): Supported Node.js versions, test runners and source files, with the limits of Vitest, Jest, Node Test, Vue, Svelte and Astro support.

### Mutators

- [Mutators](https://mootant.org/mutators.md): The 20 built-in mutators of Mootant, what each one changes in your code, what a surviving mutant tells you and why Mootant skips some changes.
- [arithmetic-operator](https://mootant.org/mutators/arithmetic-operator.md): Swaps an arithmetic operator or drops the right side of a +.
- [array-element](https://mootant.org/mutators/array-element.md): Removes one array element, or puts undefined into an empty array.
- [assignment-operator](https://mootant.org/mutators/assignment-operator.md): Swaps a compound assignment operator or changes when it assigns.
- [bitwise-operator](https://mootant.org/mutators/bitwise-operator.md): Swaps a bitwise or shift operator, or drops a | 0.
- [boolean-literal](https://mootant.org/mutators/boolean-literal.md): Flips true to false and false to true.
- [comparison-operator](https://mootant.org/mutators/comparison-operator.md): Moves the boundary of a comparison or swaps its operator.
- [condition](https://mootant.org/mutators/condition.md): Forces a condition to true or false.
- [logical-operator](https://mootant.org/mutators/logical-operator.md): Drops one side of &&, || or ??, or swaps || and ??.
- [method-call](https://mootant.org/mutators/method-call.md): Swaps a method for its opposite or removes a call like trim().
- [missing-await](https://mootant.org/mutators/missing-await.md): Removes an await, as if it had been forgotten.
- [number-literal](https://mootant.org/mutators/number-literal.md): Adds one to a number.
- [object-property](https://mootant.org/mutators/object-property.md): Removes one property or spread from an object literal.
- [optional-chaining](https://mootant.org/mutators/optional-chaining.md): Replaces ?. with a plain property access or call.
- [regex-flag](https://mootant.org/mutators/regex-flag.md): Removes a flag of a regular expression.
- [regex-pattern](https://mootant.org/mutators/regex-pattern.md): Changes one part of a regular expression pattern.
- [return-value](https://mootant.org/mutators/return-value.md): Replaces a returned value with a fixed value picked by its type.
- [statement-removal](https://mootant.org/mutators/statement-removal.md): Removes one statement that has an effect, such as a call.
- [string-literal](https://mootant.org/mutators/string-literal.md): Empties a string or fills an empty one.
- [unary-operator](https://mootant.org/mutators/unary-operator.md): Removes the -, + or ~ in front of a value.
- [update-operator](https://mootant.org/mutators/update-operator.md): Swaps ++ and --, or prefix and postfix when the value is used.

### Reports

- [HTML report](https://mootant.org/reports/html.md): Write the results of a run to one HTML file and browse the score, the files with their mutants in place, the mutators and the tests.
- [JSON report](https://mootant.org/reports/json.md): Read mutation results in scripts and agents, choose the compact or full report and use its mutants, scores, test suggestions and diagnostics.

### Agent skill

- [Agent skill](https://mootant.org/agent-skill.md): Install the Mootant agent skill, which turns surviving mutants into tests and asks Mootant to confirm each kill, and see what the skill changes in your project.

### Advanced

- [Plugins](https://mootant.org/advanced/plugins.md): Add mutators, presets and skip rules from a plugin package or a file of your project, see the ids Mootant gives them and publish a plugin of your own.
- [Custom mutators](https://mootant.org/advanced/custom-mutators.md): Write a mutator for a mistake that the built-in mutators don't make, turn it on from a plugin in your project and skip the changes that aren't worth a test.

### Community

- [Branding](https://mootant.org/community/branding.md): The Mootant visual identity. Download the logo and wordmark, explore the colors and meet the typefaces.
- [Contributing](https://mootant.org/community/contributing.md): Help improve Mootant: report issues, suggest features, add mutators and contribute code.
- [Changelog](https://mootant.org/community/changelog.md): Follow Mootant releases, new features, bug fixes and breaking changes.
