Stryker

MutantTestMatcher.js - Stryker report

Summary

File
Mutation score
# Killed
# Survived
# Timeout
# No coverage
# Errors
Total detected
Total undetected
Total mutants
MutantTestMatcher.js
77%
58/75 58 17 0 0 0 58 17 75

Code

"use strict";
var MutantTestMatcher = (function () 0{
    function MutantTestMatcher(mutants, initialRunResult, statementMaps, options) 1{
        this.mutants = mutants;
        this.initialRunResult = initialRunResult;
        this.statementMaps = statementMaps;
        this.options = options;
    }
    MutantTestMatcher.prototype.matchWithMutants = function () 2{
        var _this = this;
        this.mutants.forEach(function (mutant) 3{
            var statementMap = _this.statementMaps[mutant.filename];
            var smallestStatement = _this.findSmallestCoveringStatement(mutant, statementMap);
            _this.initialRunResult.tests.forEach(function (testResult, id) 4{
                var covered = false;
                var coverageCollection = _this.findCoverageCollectionForTest(id);
                if (567coverageCollection && smallestStatement) 8{
                    var coveredFile = coverageCollection[mutant.filename];
                    if (910coveredFile) 11{
                        covered = 1213coveredFile.s[smallestStatement] > 0;
                    }
                }
                else 14{
                    // If there is no coverage data we have to assume that the test covers the mutant
                    covered = true;
                }
                if (1516covered) 17{
                    mutant.addTestResult(id, testResult);
                }
            });
        });
    };
    /**
     * Finds the smallest statement that covers a mutant.
     * @param mutant The mutant.
     * @param statementMap of the covering file.
     * @returns The index of the coveredFile which contains the smallest statement surrounding the mutant.
     */
    MutantTestMatcher.prototype.findSmallestCoveringStatement = function (mutant, statementMap) 18{
        var _this = this;
        var smallestStatement = null;
        if (1920statementMap) 21{
            Object.keys(statementMap).forEach(function (statementId) 22{
                var location = statementMap[statementId];
                if (232425_this.statementCoversMutant(mutant.location, location) && _this.isNewSmallestStatement(statementMap[smallestStatement], location)) 26{
                    smallestStatement = statementId;
                }
            });
        }
        return smallestStatement;
    };
    /**
     * Indicates whether a statement is the smallest statement of the two statements provided.
     * @param originalLocation The area which may cover a bigger area than the newLocation.
     * @param newLocation The area which may cover a smaller area than the originalLocation.
     * @returns true if the newLocation covers a smaller area than the originalLocation, making it the smaller statement.
     */
    MutantTestMatcher.prototype.isNewSmallestStatement = function (originalLocation, newLocation) 27{
        var statementIsSmallestStatement = false;
        if (2829!originalLocation) 30{
            statementIsSmallestStatement = true;
        }
        else 31{
            var lineDifference = 32(33originalLocation.end.line - originalLocation.start.line) - (34newLocation.end.line - newLocation.start.line);
            var coversLessLines = 3536lineDifference > 0;
            var coversLessColumns = 3738lineDifference === 0 && 394041(42newLocation.start.column - originalLocation.start.column) + (43originalLocation.end.column - newLocation.end.column) > 0;
            if (444546coversLessLines || coversLessColumns) 47{
                statementIsSmallestStatement = true;
            }
        }
        return statementIsSmallestStatement;
    };
    /**
     * Indicates whether a statement covers a mutant.
     * @param mutantLocation The location of the mutant.
     * @param statementLocation The location of the statement.
     * @returns true if the statment covers the mutant.
     */
    MutantTestMatcher.prototype.statementCoversMutant = function (mutantLocation, statementLocation) 48{
        var mutantIsAfterStart = 495051mutantLocation.start.line > statementLocation.start.line ||
            (5253mutantLocation.start.line === statementLocation.start.line && 5455mutantLocation.start.column >= statementLocation.start.column);
        var mutantIsBeforeEnd = 565758mutantLocation.end.line < statementLocation.end.line ||
            (5960mutantLocation.end.line === statementLocation.end.line && 6162mutantLocation.end.column <= statementLocation.end.column);
        return 63mutantIsAfterStart && mutantIsBeforeEnd;
    };
    MutantTestMatcher.prototype.findCoverageCollectionForTest = function (testId) 64{
        if (6566this.initialRunResult.coverage) 67{
            if (6869this.isCoverageCollectionPerTest(this.initialRunResult.coverage)) 70{
                return this.initialRunResult.coverage[testId];
            }
            else 71{
                return this.initialRunResult.coverage;
            }
        }
        else 72{
            return null;
        }
    };
    MutantTestMatcher.prototype.isCoverageCollectionPerTest = function (coverage) 73{
        return 74this.options.coverageAnalysis === 'perTest';
    };
    return MutantTestMatcher;
}());
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = MutantTestMatcher;
//# sourceMappingURL=MutantTestMatcher.js.map