Socket
Socket
Sign inDemoInstall

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.1 to 1.6.2

dist/src/helpers/file.d.ts

11

CHANGELOG.md

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

## [1.6.2](https://github.com/stryker-mutator/mutation-testing-elements/compare/v1.6.1...v1.6.2) (2021-02-24)
### Features
* **file:** add methods to retrieve source content ([#928](https://github.com/stryker-mutator/mutation-testing-elements/issues/928)) ([0d3d851](https://github.com/stryker-mutator/mutation-testing-elements/commit/0d3d8518e546040c7f62b10b033a283f08d435b4))
## [1.6.1](https://github.com/stryker-mutator/mutation-testing-elements/compare/v1.6.0...v1.6.1) (2021-02-23)

@@ -8,0 +19,0 @@

6

dist/src/calculateMetrics.js

@@ -17,3 +17,3 @@ "use strict";

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

@@ -29,5 +29,5 @@ }

const { files, testFiles } = result;
const fileModelsUnderTest = helpers_1.normalize(files, (input) => new model_1.FileUnderTestModel(input));
const fileModelsUnderTest = helpers_1.normalize(files, (input, name) => new model_1.FileUnderTestModel(input, name));
if (testFiles) {
const testFileModels = helpers_1.normalize(testFiles, (input) => new model_1.TestFileModel(input));
const testFileModels = helpers_1.normalize(testFiles, (input, name) => new model_1.TestFileModel(input, name));
relate(Object.values(fileModelsUnderTest).flatMap((file) => file.mutants), Object.values(testFileModels).flatMap((file) => file.tests));

@@ -34,0 +34,0 @@ return {

export { calculateMetrics, calculateMutationTestMetrics } from './calculateMetrics';
export { normalizeFileNames } from './helpers';
export { MetricsResult, Metrics, TestMetrics, TestModel, FileUnderTestModel, TestFileModel, MutantModel } from './model';
export { MetricsResult, Metrics, TestMetrics, TestModel, FileUnderTestModel, TestFileModel, MutantModel, MutationTestMetricsResult } from './model';
//# sourceMappingURL=index.d.ts.map

@@ -1,7 +0,9 @@

import { FileResult } from 'mutation-testing-report-schema';
import { FileResult, MutantResult } from 'mutation-testing-report-schema';
import { MutantModel } from './mutant-model';
import { SourceFile } from './source-file';
/**
* Represents a file which was mutated (your production code).
*/
export declare class FileUnderTestModel implements FileResult {
export declare class FileUnderTestModel extends SourceFile implements FileResult {
name: string;
/**

@@ -19,4 +21,12 @@ * Programming language that is used. Used for code highlighting, see https://prismjs.com/#examples.

mutants: MutantModel[];
constructor(input: FileResult);
/**
* @param input The file result content
* @param name The file name
*/
constructor(input: FileResult, name: string);
/**
* Retrieves the lines of code with the mutant applied to it, to be shown in a diff view.
*/
getMutationLines(mutant: MutantResult): string;
}
//# sourceMappingURL=file-under-test-model.d.ts.map

@@ -5,15 +5,35 @@ "use strict";

const mutant_model_1 = require("./mutant-model");
const source_file_1 = require("./source-file");
/**
* Represents a file which was mutated (your production code).
*/
class FileUnderTestModel {
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;
class FileUnderTestModel extends source_file_1.SourceFile {
/**
* @param input The file result content
* @param name The file name
*/
constructor(input, name) {
super();
this.name = name;
this.language = input.language;
this.source = input.source;
this.mutants = input.mutants.map((mutantResult) => {
const mutant = new mutant_model_1.MutantModel(mutantResult);
mutant.sourceFile = this;
return mutant;
});
this.mutants = input.mutants.map((mutant) => new mutant_model_1.MutantModel(mutant));
}
/**
* Retrieves the lines of code with the mutant applied to it, to be shown in a diff view.
*/
getMutationLines(mutant) {
var _a, _b;
const lineMap = this.getLineMap();
const start = lineMap[mutant.location.start.line];
const startOfEndLine = lineMap[mutant.location.end.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)}`;
}
}
exports.FileUnderTestModel = FileUnderTestModel;
//# sourceMappingURL=file-under-test-model.js.map
import { Location, MutantResult, MutantStatus } from 'mutation-testing-report-schema';
import { FileUnderTestModel } from './file-under-test-model';
import { TestModel } from './test-model';

@@ -7,4 +8,2 @@ /**

export declare class MutantModel implements MutantResult {
coveredByTests: TestModel[] | undefined;
killedByTests: TestModel[] | undefined;
coveredBy: string[] | undefined;

@@ -20,8 +19,24 @@ description: string | undefined;

status: MutantStatus;
statusReason?: string;
statusReason: string | undefined;
testsCompleted: number | undefined;
coveredByTests: TestModel[] | undefined;
killedByTests: TestModel[] | undefined;
sourceFile: FileUnderTestModel | undefined;
constructor(input: MutantResult);
addCoveredBy(test: TestModel): void;
addKilledBy(test: TestModel): void;
/**
* Retrieves the lines of code with the mutant applied to it, to be shown in a diff view.
*/
getMutatedLines(): string;
/**
* Retrieves the original source lines for this mutant, to be shown in a diff view.
*/
getOriginalLines(): string;
/**
* Helper property to retrieve the source file name
* @throws When the `sourceFile` is not defined.
*/
get fileName(): string;
}
//# sourceMappingURL=mutant-model.d.ts.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.MutantModel = void 0;
function assertSourceFileDefined(sourceFile) {
if (sourceFile === undefined) {
throw new Error('mutant.sourceFile was not defined');
}
}
/**

@@ -9,6 +14,14 @@ * Represent a model of a mutant that contains its test relationship

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;
});
this.coveredBy = input.coveredBy;
this.description = input.description;
this.duration = input.duration;
this.id = input.id;
this.killedBy = input.killedBy;
this.location = input.location;
this.mutatorName = input.mutatorName;
this.replacement = input.replacement;
this.static = input.static;
this.status = input.status;
this.statusReason = input.statusReason;
this.testsCompleted = input.testsCompleted;
}

@@ -27,4 +40,26 @@ addCoveredBy(test) {

}
/**
* Retrieves the lines of code with the mutant applied to it, to be shown in a diff view.
*/
getMutatedLines() {
assertSourceFileDefined(this.sourceFile);
return this.sourceFile.getMutationLines(this);
}
/**
* Retrieves the original source lines for this mutant, to be shown in a diff view.
*/
getOriginalLines() {
assertSourceFileDefined(this.sourceFile);
return this.sourceFile.getLines(this.location);
}
/**
* Helper property to retrieve the source file name
* @throws When the `sourceFile` is not defined.
*/
get fileName() {
assertSourceFileDefined(this.sourceFile);
return this.sourceFile.name;
}
}
exports.MutantModel = MutantModel;
//# sourceMappingURL=mutant-model.js.map
import { TestFile as TestFile } from 'mutation-testing-report-schema';
import { SourceFile } from './source-file';
import { TestModel } from './test-model';

@@ -6,7 +7,12 @@ /**

*/
export declare class TestFileModel implements TestFile {
export declare class TestFileModel extends SourceFile implements TestFile {
name: string;
tests: TestModel[];
source?: string;
constructor(input: TestFile);
source: string | undefined;
/**
* @param input the test file content
* @param name the file name
*/
constructor(input: TestFile, name: string);
}
//# sourceMappingURL=test-file-model.d.ts.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.TestFileModel = void 0;
const source_file_1 = require("./source-file");
const test_model_1 = require("./test-model");

@@ -8,4 +9,10 @@ /**

*/
class TestFileModel {
constructor(input) {
class TestFileModel extends source_file_1.SourceFile {
/**
* @param input the test file content
* @param name the file name
*/
constructor(input, name) {
super();
this.name = name;
this.source = input.source;

@@ -12,0 +19,0 @@ this.tests = input.tests.map((testDefinition) => new test_model_1.TestModel(testDefinition));

import { OpenEndLocation, TestDefinition } from 'mutation-testing-report-schema';
import { MutantModel } from './mutant-model';
import { TestFileModel } from './test-file-model';
export declare class TestModel implements TestDefinition {

@@ -9,6 +10,17 @@ id: string;

coveredMutants?: MutantModel[];
sourceFile: TestFileModel | undefined;
addCovered(mutant: MutantModel): void;
addKilled(mutant: MutantModel): void;
constructor(input: TestDefinition);
/**
* Retrieves the original source lines where this test is defined.
* @throws if source file or location is not defined
*/
getLines(): string;
/**
* Helper property to retrieve the source file name
* @throws When the `sourceFile` is not defined.
*/
get fileName(): string;
}
//# sourceMappingURL=test-model.d.ts.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.TestModel = void 0;
function assertSourceFileDefined(sourceFile) {
if (sourceFile === undefined) {
throw new Error('test.sourceFile was not defined');
}
}
function assertLocationDefined(location) {
if (location === undefined) {
throw new Error('test.location was not defined');
}
}
class TestModel {

@@ -23,4 +33,21 @@ constructor(input) {

}
/**
* Retrieves the original source lines where this test is defined.
* @throws if source file or location is not defined
*/
getLines() {
assertSourceFileDefined(this.sourceFile);
assertLocationDefined(this.location);
return this.sourceFile.getLines(this.location);
}
/**
* Helper property to retrieve the source file name
* @throws When the `sourceFile` is not defined.
*/
get fileName() {
assertSourceFileDefined(this.sourceFile);
return this.sourceFile.name;
}
}
exports.TestModel = TestModel;
//# sourceMappingURL=test-model.js.map
{
"name": "mutation-testing-metrics",
"version": "1.6.1",
"version": "1.6.2",
"description": "Utility functions to calculate mutation testing metrics.",

@@ -23,3 +23,3 @@ "main": "dist/src/index.js",

},
"gitHead": "aaf05db7dbfb6c4453501d268d0fadb199da27ed"
"gitHead": "fd0dc1a2193c8f33ef7ca2ebc643cbde0373f710"
}
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