mutation-testing-metrics
Advanced tools
Comparing version 1.7.10 to 1.7.14
@@ -12,3 +12,2 @@ "use strict"; | ||
function aggregateResultsByModule(resultsByModule) { | ||
var _a, _b; | ||
const projectRoots = Object.values(resultsByModule) | ||
@@ -20,3 +19,3 @@ .map((report) => report.projectRoot) | ||
schemaVersion: '1.7', | ||
thresholds: (_b = (_a = resultsByModule[0]) === null || _a === void 0 ? void 0 : _a.thresholds) !== null && _b !== void 0 ? _b : { high: 80, low: 60 }, | ||
thresholds: resultsByModule[0]?.thresholds ?? { high: 80, low: 60 }, | ||
projectRoot: projectRoots.length ? (0, helpers_1.determineCommonBasePath)(projectRoots) : undefined, | ||
@@ -26,3 +25,2 @@ config: {}, | ||
return Object.entries(resultsByModule).reduce((acc, [moduleName, report]) => { | ||
var _a; | ||
Object.entries((0, helpers_1.normalizeFileNames)(report.files)).forEach(([fileName, fileResult]) => { | ||
@@ -42,3 +40,3 @@ aggregatedResult.files[`${moduleName}/${fileName}`] = { | ||
if (report.testFiles) { | ||
const aggregatedTestFiles = (_a = aggregatedResult.testFiles) !== null && _a !== void 0 ? _a : (aggregatedResult.testFiles = Object.create(null)); | ||
const aggregatedTestFiles = aggregatedResult.testFiles ?? (aggregatedResult.testFiles = Object.create(null)); | ||
Object.entries((0, helpers_1.normalizeFileNames)(report.testFiles)).forEach(([fileName, testFileResult]) => { | ||
@@ -45,0 +43,0 @@ aggregatedTestFiles[`${moduleName}/${fileName}`] = { |
@@ -30,3 +30,3 @@ "use strict"; | ||
const fileModelsUnderTest = (0, helpers_1.normalize)(files, projectRoot, (input, name) => new model_1.FileUnderTestModel(input, name)); | ||
if (testFiles) { | ||
if (testFiles && Object.keys(testFiles).length) { | ||
const testFileModels = (0, helpers_1.normalize)(testFiles, projectRoot, (input, name) => new model_1.TestFileModel(input, name)); | ||
@@ -92,7 +92,6 @@ relate(Object.values(fileModelsUnderTest).flatMap((file) => file.mutants), Object.values(testFileModels).flatMap((file) => file.tests)); | ||
function relate(mutants, tests) { | ||
var _a, _b, _c, _d; | ||
// Create a testId -> TestModel map for fast lookup | ||
const testMap = new Map(tests.map((test) => [test.id, test])); | ||
for (const mutant of mutants) { | ||
const coveringTests = (_b = (_a = mutant.coveredBy) === null || _a === void 0 ? void 0 : _a.map((testId) => testMap.get(testId))) !== null && _b !== void 0 ? _b : []; | ||
const coveringTests = mutant.coveredBy?.map((testId) => testMap.get(testId)) ?? []; | ||
for (const test of coveringTests) { | ||
@@ -104,3 +103,3 @@ if (test) { | ||
} | ||
const killingTests = (_d = (_c = mutant.killedBy) === null || _c === void 0 ? void 0 : _c.map((testId) => testMap.get(testId))) !== null && _d !== void 0 ? _d : []; | ||
const killingTests = mutant.killedBy?.map((testId) => testMap.get(testId)) ?? []; | ||
for (const test of killingTests) { | ||
@@ -107,0 +106,0 @@ if (test) { |
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); | ||
var desc = Object.getOwnPropertyDescriptor(m, k); | ||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
desc = { enumerable: true, get: function() { return m[k]; } }; | ||
} | ||
Object.defineProperty(o, k2, desc); | ||
}) : (function(o, m, k, k2) { | ||
@@ -6,0 +10,0 @@ if (k2 === undefined) k2 = k; |
@@ -16,6 +16,6 @@ "use strict"; | ||
// breaking characters are treated as white space but not as line terminators. | ||
return (ch === 10 /* lineFeed */ || | ||
ch === 13 /* carriageReturn */ || | ||
ch === 8232 /* lineSeparator */ || | ||
ch === 8233 /* paragraphSeparator */); | ||
return (ch === 10 /* CharacterCodes.lineFeed */ || | ||
ch === 13 /* CharacterCodes.carriageReturn */ || | ||
ch === 8232 /* CharacterCodes.lineSeparator */ || | ||
ch === 8233 /* CharacterCodes.paragraphSeparator */); | ||
} | ||
@@ -36,4 +36,4 @@ function computeLineStarts(text) { | ||
switch (ch) { | ||
case 13 /* carriageReturn */: | ||
if (text.charCodeAt(pos) === 10 /* lineFeed */) { | ||
case 13 /* CharacterCodes.carriageReturn */: | ||
if (text.charCodeAt(pos) === 10 /* CharacterCodes.lineFeed */) { | ||
pos++; | ||
@@ -43,7 +43,7 @@ } | ||
break; | ||
case 10 /* lineFeed */: | ||
case 10 /* CharacterCodes.lineFeed */: | ||
progressLineStart(pos); | ||
break; | ||
default: | ||
if (ch > 127 /* maxAsciiCharacter */ && isLineBreak(ch)) { | ||
if (ch > 127 /* CharacterCodes.maxAsciiCharacter */ && isLineBreak(ch)) { | ||
progressLineStart(pos); | ||
@@ -50,0 +50,0 @@ } |
@@ -29,3 +29,2 @@ "use strict"; | ||
getMutationLines(mutant) { | ||
var _a, _b; | ||
const lineMap = this.getLineMap(); | ||
@@ -35,3 +34,3 @@ const start = lineMap[mutant.location.start.line]; | ||
const end = lineMap[mutant.location.end.line + 1]; | ||
return `${this.source.substr(start, mutant.location.start.column - 1)}${(_b = (_a = mutant.replacement) !== null && _a !== void 0 ? _a : mutant.description) !== null && _b !== void 0 ? _b : mutant.mutatorName}${this.source.substring(startOfEndLine + mutant.location.end.column - 1, end)}`; | ||
return `${this.source.substr(start, mutant.location.start.column - 1)}${mutant.replacement ?? mutant.description ?? mutant.mutatorName}${this.source.substring(startOfEndLine + mutant.location.end.column - 1, end)}`; | ||
} | ||
@@ -38,0 +37,0 @@ } |
@@ -20,6 +20,5 @@ "use strict"; | ||
getLines(location) { | ||
var _a; | ||
assertSourceDefined(this.source); | ||
const lineMap = this.getLineMap(); | ||
return this.source.substring(lineMap[location.start.line], lineMap[((_a = location.end) !== null && _a !== void 0 ? _a : location.start).line + 1]); | ||
return this.source.substring(lineMap[location.start.line], lineMap[(location.end ?? location.start).line + 1]); | ||
} | ||
@@ -26,0 +25,0 @@ } |
@@ -21,8 +21,2 @@ "use strict"; | ||
class TestModel { | ||
constructor(input) { | ||
Object.entries(input).forEach(([key, value]) => { | ||
// @ts-expect-error dynamic assignment so we won't forget to add new properties | ||
this[key] = value; | ||
}); | ||
} | ||
addCovered(mutant) { | ||
@@ -40,2 +34,8 @@ if (!this.coveredMutants) { | ||
} | ||
constructor(input) { | ||
Object.entries(input).forEach(([key, value]) => { | ||
// @ts-expect-error dynamic assignment so we won't forget to add new properties | ||
this[key] = value; | ||
}); | ||
} | ||
/** | ||
@@ -59,7 +59,6 @@ * Retrieves the original source lines where this test is defined. | ||
get status() { | ||
var _a, _b; | ||
if ((_a = this.killedMutants) === null || _a === void 0 ? void 0 : _a.length) { | ||
if (this.killedMutants?.length) { | ||
return TestStatus.Killing; | ||
} | ||
else if ((_b = this.coveredMutants) === null || _b === void 0 ? void 0 : _b.length) { | ||
else if (this.coveredMutants?.length) { | ||
return TestStatus.Covering; | ||
@@ -66,0 +65,0 @@ } |
{ | ||
"name": "mutation-testing-metrics", | ||
"version": "1.7.10", | ||
"version": "1.7.14", | ||
"description": "Utility functions to calculate mutation testing metrics.", | ||
@@ -21,5 +21,5 @@ "main": "dist/src/index.js", | ||
"dependencies": { | ||
"mutation-testing-report-schema": "1.7.10" | ||
"mutation-testing-report-schema": "1.7.14" | ||
}, | ||
"gitHead": "1df68c02ccfcbcb9499524f22183c1950d50f1ac" | ||
"gitHead": "deb605dda044f7b3df4a8535bfcc3b483b611b9b" | ||
} |
@@ -52,1 +52,56 @@ [![Mutation testing badge](https://img.shields.io/endpoint?style=flat&url=https%3A%2F%2Fbadge-api.stryker-mutator.io%2Fgithub.com%2Fstryker-mutator%2Fmutation-testing-elements%2Fmaster%3Fmodule%3Dmetrics)](https://badge-api.stryker-mutator.io/github.com/stryker-mutator/mutation-testing-elements/master?module=metrics) | ||
Types are included and documented with TypeScript. | ||
## Use case: merging multiple JSON reports | ||
You can use this script to merge multiple JSON reports together. | ||
```js | ||
const { aggregateResultsByModule } = require('mutation-testing-metrics'); | ||
const fs = require('fs'); | ||
const packagesRoot = './packages'; | ||
const reportsPerModule = fs | ||
.readdirSync(packagesRoot) | ||
.map((pkg) => [pkg, `${packagesRoot}/${pkg}/reports/mutation/mutation.json`]) | ||
.filter(([, report]) => fs.existsSync(report)) | ||
.map(([pkg, report]) => [pkg, require(report)]) | ||
.reduce((acc, [pkg, report]) => { | ||
acc[pkg] = report; | ||
return acc; | ||
}, {}); | ||
const monoReport = aggregateResultsByModule(reportsPerModule); | ||
fs.writeFileSync('./mono-report.html', reportTemplate(monoReport), 'utf-8'); | ||
function reportTemplate(report) { | ||
const scriptContent = fs.readFileSync(require.resolve('mutation-testing-elements/dist/mutation-test-elements.js'), 'utf-8'); | ||
return `<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8"> | ||
<script> | ||
${scriptContent} | ||
</script> | ||
</head> | ||
<body> | ||
<mutation-test-report-app> | ||
Your browser doesn't support <a href="https://caniuse.com/#search=custom%20elements">custom elements</a>. | ||
Please use a latest version of an evergreen browser (Firefox, Chrome, Safari, Opera, Edge, etc). | ||
</mutation-test-report-app> | ||
<script> | ||
const app = document.querySelector('mutation-test-report-app'); | ||
app.report = ${escapeHtmlTags(JSON.stringify(report))}; | ||
function updateTheme() { | ||
document.body.style.backgroundColor = app.theme === 'dark' ? '#222' : '#fff'; | ||
} | ||
app.addEventListener('theme-changed', updateTheme); | ||
updateTheme(); | ||
</script> | ||
</body> | ||
</html>`; | ||
} | ||
function escapeHtmlTags(json) { | ||
return json.replace(/</g, '<" + "'); | ||
} | ||
``` |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
107
54662
39
911
+ Addedmutation-testing-report-schema@1.7.14(transitive)
- Removedmutation-testing-report-schema@1.7.10(transitive)