UNPKG

stryker

Version:
145 lines 5.77 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var SourceFile_1 = require("./SourceFile"); var objectUtils_1 = require("./utils/objectUtils"); var TestSelectionResult; (function (TestSelectionResult) { TestSelectionResult[TestSelectionResult["Failed"] = 0] = "Failed"; TestSelectionResult[TestSelectionResult["FailedButAlreadyReported"] = 1] = "FailedButAlreadyReported"; TestSelectionResult[TestSelectionResult["Success"] = 2] = "Success"; })(TestSelectionResult = exports.TestSelectionResult || (exports.TestSelectionResult = {})); var TestableMutant = /** @class */ (function () { function TestableMutant(id, mutant, sourceFile) { this.id = id; this.mutant = mutant; this.sourceFile = sourceFile; this._selectedTests = []; this.specsRan = []; this._timeSpentScopedTests = 0; this.testSelectionResult = TestSelectionResult.Success; } Object.defineProperty(TestableMutant.prototype, "selectedTests", { get: function () { return this._selectedTests; }, enumerable: true, configurable: true }); Object.defineProperty(TestableMutant.prototype, "timeSpentScopedTests", { get: function () { return this._timeSpentScopedTests; }, enumerable: true, configurable: true }); Object.defineProperty(TestableMutant.prototype, "fileName", { get: function () { return this.mutant.fileName; }, enumerable: true, configurable: true }); Object.defineProperty(TestableMutant.prototype, "mutatorName", { get: function () { return this.mutant.mutatorName; }, enumerable: true, configurable: true }); Object.defineProperty(TestableMutant.prototype, "range", { get: function () { return this.mutant.range; }, enumerable: true, configurable: true }); Object.defineProperty(TestableMutant.prototype, "replacement", { get: function () { return this.mutant.replacement; }, enumerable: true, configurable: true }); Object.defineProperty(TestableMutant.prototype, "location", { get: function () { if (!this._location) { this._location = this.sourceFile.getLocation(this.range); } return this._location; }, enumerable: true, configurable: true }); Object.defineProperty(TestableMutant.prototype, "mutatedCode", { get: function () { return this.sourceFile.content.substr(0, this.range[0]) + this.replacement + this.sourceFile.content.substr(this.range[1]); }, enumerable: true, configurable: true }); Object.defineProperty(TestableMutant.prototype, "originalCode", { get: function () { return this.sourceFile.content; }, enumerable: true, configurable: true }); TestableMutant.prototype.selectAllTests = function (runResult, testSelectionResult) { var _this = this; this.testSelectionResult = testSelectionResult; runResult.tests.forEach(function (testResult, id) { return _this.selectTest(testResult, id); }); }; TestableMutant.prototype.selectTest = function (testResult, index) { this._selectedTests.push({ id: index, name: testResult.name }); this._timeSpentScopedTests += testResult.timeSpentMs; }; Object.defineProperty(TestableMutant.prototype, "originalLines", { get: function () { var _a = this.getMutationLineIndexes(), startIndex = _a[0], endIndex = _a[1]; return this.sourceFile.content.substring(startIndex, endIndex); }, enumerable: true, configurable: true }); Object.defineProperty(TestableMutant.prototype, "mutatedLines", { get: function () { var _a = this.getMutationLineIndexes(), startIndex = _a[0], endIndex = _a[1]; return this.sourceFile.content.substring(startIndex, this.mutant.range[0]) + this.mutant.replacement + this.sourceFile.content.substring(this.mutant.range[1], endIndex); }, enumerable: true, configurable: true }); TestableMutant.prototype.getMutationLineIndexes = function () { var startIndexLines = this.mutant.range[0]; var endIndexLines = this.mutant.range[1]; while (startIndexLines > 0 && !SourceFile_1.isLineBreak(this.originalCode.charCodeAt(startIndexLines - 1))) { startIndexLines--; } while (endIndexLines < this.sourceFile.content.length && !SourceFile_1.isLineBreak(this.originalCode.charCodeAt(endIndexLines))) { endIndexLines++; } return [startIndexLines, endIndexLines]; }; TestableMutant.prototype.result = function (status, testsRan) { return objectUtils_1.freezeRecursively({ id: this.id, location: this.location, mutatedLines: this.mutatedLines, mutatorName: this.mutatorName, originalLines: this.originalLines, range: this.range, replacement: this.replacement, sourceFilePath: this.fileName, status: status, testsRan: testsRan }); }; TestableMutant.prototype.toString = function () { return this.mutant.mutatorName + ": (" + this.replacement + ") file://" + this.fileName + ":" + (this.location.start.line + 1) + ":" + this.location.start.column; }; return TestableMutant; }()); exports.default = TestableMutant; //# sourceMappingURL=TestableMutant.js.map