Registry / testing / mutation-testing-metrics

mutation-testing-metrics

JSON →
library3.7.3jsnpmunverified

The `mutation-testing-metrics` package provides a set of utility functions designed to calculate and aggregate mutation testing metrics from mutation test reports. Currently at version 3.7.3, it is an actively maintained component within the Stryker Mutator ecosystem, with a release cadence that appears to be every few months, addressing bug fixes and minor feature enhancements. Its key differentiators include the ability to programmatically process `MutationTestResult` objects, perform detailed metric calculations, and aggregate multiple module-level reports into a single, consolidated view. This enables developers and CI/CD pipelines to deeply analyze the effectiveness of their test suites, going beyond simple code coverage by evaluating how well tests detect intentionally introduced faults (mutants). It is built with TypeScript, providing strong type guarantees for its API.

npm install mutation-testing-metrics
INSTALL
IMPORT
SIG · MUTATION-TESTING-M
M
mutation-testing-metrics
testingjavascriptv3.7.3
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

calculateMutationTestMetrics
import { calculateMutationTestMetrics } from 'mutation-testing-metrics';
const calculateMutationTestMetrics = require('mutation-testing-metrics').calculateMutationTestMetrics;
ESM named import is the modern approach. For CommonJS, use destructuring from `require()`.
MetricsResult
import type { MetricsResult } from 'mutation-testing-metrics';
Type-only import for the structure returned by metric calculation functions.
aggregateResultsByModule
import { aggregateResultsByModule } from 'mutation-testing-metrics';
const aggregateResultsByModule = require('mutation-testing-metrics'); // or const { default: aggregateResultsByModule } = require('mutation-testing-metrics');
Available as a named export in both ESM and CJS contexts. The README provides a CJS example using destructuring from `require()` for this function.

This example demonstrates how to use `calculateMutationTestMetrics` to process a `MutationTestResult` object and output key metrics like total mutants, killed, survived, and the overall mutation score.

import { MetricsResult, calculateMutationTestMetrics } from 'mutation-testing-metrics'; import type { MutationTestResult } from 'mutation-testing-report-schema'; // In a real scenario, mutationTestReport would be loaded from a file or generated const mutationTestReport: MutationTestResult = { $schema: 'https://raw.githubusercontent.com/stryker-mutator/mutation-testing-elements/master/packages/report-schema/src/mutation-testing-report-schema.json', schemaVersion: '1.4', thresholds: { high: 80, low: 60 }, files: { 'src/calculator.js': { language: 'javascript', mutants: [ { id: '1', mutatorName: 'BinaryExpression', replacement: 'a - b', location: { start: { line: 1, column: 15 }, end: { line: 1, column: 20 } }, status: 'Survived' }, { id: '2', mutatorName: 'BinaryExpression', replacement: 'a / b', location: { start: { line: 1, column: 15 }, end: { line: 1, column: 20 } }, status: 'Killed' } ], source: 'const add = (a, b) => a + b;' }, 'src/subtract.js': { language: 'javascript', mutants: [ { id: '3', mutatorName: 'BinaryExpression', replacement: 'a + b', location: { start: { line: 1, column: 18 }, end: { line: 1, column: 23 } }, status: 'NoCoverage' } ], source: 'const subtract = (a, b) => a - b;' } } }; const result: MetricsResult = calculateMutationTestMetrics(mutationTestReport); console.log('--- Mutation Test Metrics ---'); console.log('Total mutants:', result.metrics.totalMutants); console.log('Killed mutants:', result.metrics.killed); console.log('Survived mutants:', result.metrics.survived); console.log('No Coverage mutants:', result.metrics.noCoverage); console.log('Mutation score:', result.metrics.mutationScore.toFixed(2) + '%');
Debug
Known issues
gotchaOlder versions of `mutation-testing-metrics` might encounter compatibility issues with Node.js 20+. A fix for Node 20 compatibility was released in version 3.7.1, so it's recommended to upgrade if using newer Node.js runtimes.
fix
Update to `mutation-testing-metrics` version 3.7.1 or higher: `npm install mutation-testing-metrics@latest`
affects: <3.7.1
gotchaThe package relies heavily on the `mutation-testing-report-schema` for its input data structure. Any deviation from this schema will lead to incorrect metric calculations or runtime errors.
fix
Always ensure your mutation test report JSON adheres strictly to the `mutation-testing-report-schema`. Consult the schema documentation for details.
affects: >=1.0
gotchaThis package is part of the larger `stryker-mutator` monorepo. While it aims for semantic versioning, its major/minor versions are often synchronized with `mutation-testing-elements` and not strictly with the underlying schema, which can sometimes lead to unexpected versioning behavior if only specific sub-packages are updated.
fix
For best compatibility, it's often advisable to keep `mutation-testing-metrics` aligned with other `stryker-mutator` packages you are using, especially `mutation-testing-elements` and `mutation-testing-report-schema`.
affects: >=1.0
Errors
Common errors & fixes
Cannot find module 'mutation-testing-metrics' or its corresponding type declarations.
The package is not installed, or the import path is incorrect, or TypeScript cannot find the type definitions.
fix
Ensure the package is installed: `npm install mutation-testing-metrics` or `yarn add mutation-testing-metrics`. Verify the import path is exactly `mutation-testing-metrics`.
TypeError: calculateMutationTestMetrics is not a function
This typically occurs in a CommonJS environment when trying to access a named export without destructuring it from the `require()` call.
fix
For CommonJS, use destructuring: `const { calculateMutationTestMetrics } = require('mutation-testing-metrics');`
Argument of type '{ ... }' is not assignable to parameter of type 'MutationTestResult'.
The input object provided to functions like `calculateMutationTestMetrics` does not match the expected structure defined by `mutation-testing-report-schema`.
fix
Review the `MutationTestResult` schema and ensure your input object conforms to it, including all required properties like `schemaVersion`, `thresholds`, and `files` with their correct internal structures.
Upgrade
Version history
3.7.3latest on npm
Audit
Dependencies
mutation-testing-report-schemarequiredProvides the required TypeScript types and defines the expected JSON data structure for mutation test reports, which are the primary input for all metric calculations and aggregations.
Agent activity
2 hits · last 30 days
node
2
Resources
mutation-testing-metrics — npm install mutation-testing-metrics · libregistry