Registry /
testing / mutation-testing-metrics
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
muslnode 18–226 runs
build_error
glibcnode 18–226 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) + '%');
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.
fixEnsure 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.
fixFor 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`.
fixReview 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.
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.