Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

mutation-testing-metrics

Package Overview
Dependencies
Maintainers
1
Versions
38
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mutation-testing-metrics - npm Package Compare versions

Comparing version 1.6.2 to 1.7.1

8

CHANGELOG.md

@@ -6,2 +6,10 @@ # Change Log

## [1.7.1](https://github.com/stryker-mutator/mutation-testing-elements/compare/v1.7.0...v1.7.1) (2021-05-02)
**Note:** Version bump only for package mutation-testing-metrics
## [1.6.2](https://github.com/stryker-mutator/mutation-testing-elements/compare/v1.6.1...v1.6.2) (2021-02-24)

@@ -8,0 +16,0 @@

35

dist/src/calculateMetrics.js

@@ -8,2 +8,3 @@ "use strict";

const model_1 = require("./model");
const test_model_1 = require("./model/test-model");
const DEFAULT_SCORE = NaN;

@@ -18,3 +19,3 @@ const ROOT_NAME = 'All files';

function calculateMetrics(files) {
const normalizedFiles = helpers_1.normalize(files, (input, name) => new model_1.FileUnderTestModel(input, name));
const normalizedFiles = helpers_1.normalize(files, '', (input, name) => new model_1.FileUnderTestModel(input, name));
return calculateDirectoryMetrics(ROOT_NAME, normalizedFiles, countFileMetrics);

@@ -29,14 +30,14 @@ }

function calculateMutationTestMetrics(result) {
const { files, testFiles } = result;
const fileModelsUnderTest = helpers_1.normalize(files, (input, name) => new model_1.FileUnderTestModel(input, name));
const { files, testFiles, projectRoot = '' } = result;
const fileModelsUnderTest = helpers_1.normalize(files, projectRoot, (input, name) => new model_1.FileUnderTestModel(input, name));
if (testFiles) {
const testFileModels = helpers_1.normalize(testFiles, (input, name) => new model_1.TestFileModel(input, name));
const testFileModels = helpers_1.normalize(testFiles, projectRoot, (input, name) => new model_1.TestFileModel(input, name));
relate(Object.values(fileModelsUnderTest).flatMap((file) => file.mutants), Object.values(testFileModels).flatMap((file) => file.tests));
return {
systemUnderTestMetrics: calculateDirectoryMetrics(ROOT_NAME, fileModelsUnderTest, countFileMetrics),
testMetrics: calculateDirectoryMetrics(ROOT_NAME_TESTS, testFileModels, countTestFileMetrics),
systemUnderTestMetrics: calculateRootMetrics(ROOT_NAME, fileModelsUnderTest, countFileMetrics),
testMetrics: calculateRootMetrics(ROOT_NAME_TESTS, testFileModels, countTestFileMetrics),
};
}
return {
systemUnderTestMetrics: calculateDirectoryMetrics(ROOT_NAME, fileModelsUnderTest, countFileMetrics),
systemUnderTestMetrics: calculateRootMetrics(ROOT_NAME, fileModelsUnderTest, countFileMetrics),
testMetrics: undefined,

@@ -46,2 +47,15 @@ };

exports.calculateMutationTestMetrics = calculateMutationTestMetrics;
function calculateRootMetrics(name, files, calculateMetrics) {
const fileNames = Object.keys(files);
/**
* When a mutation testing framework doesn't report test files, but _does want to report a list of tests_,
* it will put those tests in a 'dummy' file with an empty string as name.
*/
if (fileNames.length === 1 && fileNames[0] === '') {
return calculateFileMetrics(name, files[fileNames[0]], calculateMetrics);
}
else {
return calculateDirectoryMetrics(name, files, calculateMetrics);
}
}
function calculateDirectoryMetrics(name, files, calculateMetrics) {

@@ -99,7 +113,8 @@ const metrics = calculateMetrics(Object.values(files));

const tests = testFile.flatMap((_) => _.tests);
const count = (status) => tests.filter((_) => _.status === status).length;
return {
total: tests.length,
killing: tests.reduce((acc, test) => { var _a; return (((_a = test.killedMutants) === null || _a === void 0 ? void 0 : _a.length) ? ++acc : acc); }, 0),
notKilling: tests.reduce((acc, test) => { var _a; return (!((_a = test.killedMutants) === null || _a === void 0 ? void 0 : _a.length) ? ++acc : acc); }, 0),
notCovering: tests.reduce((acc, test) => { var _a; return (!((_a = test.coveredMutants) === null || _a === void 0 ? void 0 : _a.length) ? ++acc : acc); }, 0),
killing: count(test_model_1.TestStatus.Killing),
covering: count(test_model_1.TestStatus.Covering),
notCovering: count(test_model_1.TestStatus.NotCovering),
};

@@ -106,0 +121,0 @@ }

import { MetricsResult } from '../model/metrics-result';
export declare function normalizeFileNames<TIn>(input: Record<string, TIn>): Record<string, TIn>;
export declare function normalize<TIn, TOut>(input: Record<string, TIn>, factory: (input: TIn, fileName: string) => TOut): Record<string, TOut>;
export declare function normalizeFileNames<TIn>(input: Record<string, TIn>, projectRoot?: string): Record<string, TIn>;
export declare function normalize<TIn, TOut>(input: Record<string, TIn>, projectRoot: string, factory: (input: TIn, relativeFileName: string) => TOut): Record<string, TOut>;
export declare function compareNames(a: MetricsResult<any, any>, b: MetricsResult<any, any>): number;
//# sourceMappingURL=file.d.ts.map

@@ -5,7 +5,7 @@ "use strict";

const SEPARATOR = '/';
function normalizeFileNames(input) {
return normalize(input, (input) => input);
function normalizeFileNames(input, projectRoot = '') {
return normalize(input, projectRoot, (input) => input);
}
exports.normalizeFileNames = normalizeFileNames;
function normalize(input, factory) {
function normalize(input, projectRoot, factory) {
const fileNames = Object.keys(input);

@@ -15,3 +15,4 @@ const commonBasePath = determineCommonBasePath(fileNames);

fileNames.forEach((fileName) => {
output[normalizeName(fileName.substr(commonBasePath.length))] = factory(input[fileName], fileName);
const relativeFileName = normalizeName(fileName.startsWith(projectRoot) ? fileName.substr(projectRoot.length) : fileName);
output[normalizeName(fileName.substr(commonBasePath.length))] = factory(input[fileName], relativeFileName);
});

@@ -18,0 +19,0 @@ return output;

export { calculateMetrics, calculateMutationTestMetrics } from './calculateMetrics';
export { normalizeFileNames } from './helpers';
export { MetricsResult, Metrics, TestMetrics, TestModel, FileUnderTestModel, TestFileModel, MutantModel, MutationTestMetricsResult } from './model';
export { MetricsResult, Metrics, TestMetrics, TestModel, FileUnderTestModel, TestFileModel, MutantModel, MutationTestMetricsResult, TestStatus, } from './model';
//# sourceMappingURL=index.d.ts.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.MutantModel = exports.TestFileModel = exports.FileUnderTestModel = exports.TestModel = exports.normalizeFileNames = exports.calculateMutationTestMetrics = exports.calculateMetrics = void 0;
exports.TestStatus = exports.MutantModel = exports.TestFileModel = exports.FileUnderTestModel = exports.TestModel = exports.normalizeFileNames = exports.calculateMutationTestMetrics = exports.calculateMetrics = void 0;
var calculateMetrics_1 = require("./calculateMetrics");

@@ -14,2 +14,3 @@ Object.defineProperty(exports, "calculateMetrics", { enumerable: true, get: function () { return calculateMetrics_1.calculateMetrics; } });

Object.defineProperty(exports, "MutantModel", { enumerable: true, get: function () { return model_1.MutantModel; } });
Object.defineProperty(exports, "TestStatus", { enumerable: true, get: function () { return model_1.TestStatus; } });
//# sourceMappingURL=index.js.map

@@ -8,3 +8,3 @@ export { FileUnderTestModel } from './file-under-test-model';

export { TestMetrics } from './test-metrics';
export { TestModel } from './test-model';
export { TestModel, TestStatus } from './test-model';
//# sourceMappingURL=index.d.ts.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.TestModel = exports.TestFileModel = exports.MutantModel = exports.FileUnderTestModel = void 0;
exports.TestStatus = exports.TestModel = exports.TestFileModel = exports.MutantModel = exports.FileUnderTestModel = void 0;
var file_under_test_model_1 = require("./file-under-test-model");

@@ -12,2 +12,3 @@ Object.defineProperty(exports, "FileUnderTestModel", { enumerable: true, get: function () { return file_under_test_model_1.FileUnderTestModel; } });

Object.defineProperty(exports, "TestModel", { enumerable: true, get: function () { return test_model_1.TestModel; } });
Object.defineProperty(exports, "TestStatus", { enumerable: true, get: function () { return test_model_1.TestStatus; } });
//# sourceMappingURL=index.js.map

@@ -18,3 +18,7 @@ "use strict";

this.source = input.source;
this.tests = input.tests.map((testDefinition) => new test_model_1.TestModel(testDefinition));
this.tests = input.tests.map((testDefinition) => {
const test = new test_model_1.TestModel(testDefinition);
test.sourceFile = this;
return test;
});
}

@@ -21,0 +25,0 @@ }

@@ -13,3 +13,3 @@ export interface TestMetrics {

*/
notKilling: number;
covering: number;
/**

@@ -16,0 +16,0 @@ * The total number of tests that didn't even cover a single mutant (useless tests?).

import { OpenEndLocation, TestDefinition } from 'mutation-testing-report-schema';
import { MutantModel } from './mutant-model';
import { TestFileModel } from './test-file-model';
export declare enum TestStatus {
Killing = "Killing",
Covering = "Covering",
NotCovering = "NotCovering"
}
export declare class TestModel implements TestDefinition {

@@ -24,3 +29,4 @@ id: string;

get fileName(): string;
get status(): TestStatus;
}
//# sourceMappingURL=test-model.d.ts.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.TestModel = void 0;
exports.TestModel = exports.TestStatus = void 0;
function assertSourceFileDefined(sourceFile) {

@@ -14,2 +14,8 @@ if (sourceFile === undefined) {

}
var TestStatus;
(function (TestStatus) {
TestStatus["Killing"] = "Killing";
TestStatus["Covering"] = "Covering";
TestStatus["NotCovering"] = "NotCovering";
})(TestStatus = exports.TestStatus || (exports.TestStatus = {}));
class TestModel {

@@ -51,4 +57,16 @@ constructor(input) {

}
get status() {
var _a, _b;
if ((_a = this.killedMutants) === null || _a === void 0 ? void 0 : _a.length) {
return TestStatus.Killing;
}
else if ((_b = this.coveredMutants) === null || _b === void 0 ? void 0 : _b.length) {
return TestStatus.Covering;
}
else {
return TestStatus.NotCovering;
}
}
}
exports.TestModel = TestModel;
//# sourceMappingURL=test-model.js.map
{
"name": "mutation-testing-metrics",
"version": "1.6.2",
"version": "1.7.1",
"description": "Utility functions to calculate mutation testing metrics.",

@@ -19,7 +19,6 @@ "main": "dist/src/index.js",

},
"homepage": "https://github.com/stryker-mutator/mutation-testing-elements/tree/master/packages/mutation-testing-metrics#readme",
"homepage": "https://github.com/stryker-mutator/mutation-testing-elements/tree/master/packages/metrics#readme",
"dependencies": {
"mutation-testing-report-schema": "^1.6.0"
},
"gitHead": "fd0dc1a2193c8f33ef7ca2ebc643cbde0373f710"
"mutation-testing-report-schema": "^1.7.1"
}
}

@@ -29,3 +29,3 @@ [![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)

Calculates the metrics for a MutationTestResult. This result must be valid according to the [https://github.com/stryker-mutator/mutation-testing-elements/tree/master/packages/mutation-testing-report-schema#readme].
Calculates the metrics for a MutationTestResult. This result must be valid according to the [https://github.com/stryker-mutator/mutation-testing-elements/tree/master/packages/report-schema#readme].

@@ -32,0 +32,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc