Stryker

ClearTextReporter.js - Stryker report

Summary

File
Mutation score
# Killed
# Survived
# Timeout
# No coverage
# Errors
Total detected
Total undetected
Total mutants
ClearTextReporter.js
64%
58/90 58 32 0 0 0 58 32 90

Code

"use strict";
var chalk = require('chalk');
var log4js = require('log4js');
var report_1 = require('stryker-api/report');
var log = log4js.getLogger('ClearTextReporter');
var ClearTextReporter = (function () 0{
    function ClearTextReporter(options) 1{
        this.options = options;
        this.out = process.stdout;
    }
    ClearTextReporter.prototype.writeLine = function (output) 2{
        this.out.write(3(4output || '') + "\n");
    };
    ClearTextReporter.prototype.onAllMutantsTested = function (mutantResults) 5{
        var _this = this;
        this.writeLine();
        var totalTests = 0;
        var mutantsKilled = 0;
        var mutantsTimedOut = 0;
        var mutantsNoCoverage = 0;
        var mutantsSurvived = 0;
        // use these fn's in order to preserve the 'this` pointer
        var logDebugFn = function (input) 6{ return log.debug(input); };
        var writeLineFn = function (input) 7{ return _this.writeLine(input); };
        mutantResults.forEach(function (result) 8{
            if (910result.testsRan) 11{
                totalTests += result.testsRan.length;
            }
            switch (result.status) {
                case report_1.MutantStatus.Killed:
                    12mutantsKilled++;
                    log.debug(chalk.bold.green('Mutant killed!'));
                    _this.logMutantResult(result, logDebugFn);
                    break;
                case report_1.MutantStatus.TimedOut:
                    13mutantsTimedOut++;
                    log.debug(chalk.bold.yellow('Mutant timed out!'));
                    _this.logMutantResult(result, logDebugFn);
                    break;
                case report_1.MutantStatus.Survived:
                    14mutantsSurvived++;
                    _this.writeLine(chalk.bold.red('Mutant survived!'));
                    _this.logMutantResult(result, writeLineFn);
                    break;
                case report_1.MutantStatus.NoCoverage:
                    15mutantsNoCoverage++;
                    _this.writeLine(chalk.bold.yellow('Mutant survived! (not covered'));
                    _this.logMutantResult(result, writeLineFn);
                    break;
            }
        });
        var mutationScoreCodebase = (16(17(18mutantsKilled + mutantsTimedOut) / mutantResults.length) * 100).toFixed(2);
        var mutationScoreCodeCoverage = (19(20(21mutantsKilled + mutantsTimedOut) / (22(23mutantResults.length - mutantsNoCoverage) || 1)) * 100).toFixed(2);
        var codebaseColor = this.getColorForMutationScore(24+mutationScoreCodebase);
        var codecoverageColor = this.getColorForMutationScore(25+mutationScoreCodeCoverage);
        this.writeLine(26mutantResults.length + " total mutants.");
        this.writeLine(27(28mutantsSurvived + mutantsNoCoverage) + ' mutants survived.');
        if (29303132mutantsNoCoverage > 0) 33{
            this.writeLine(3435"  of which " + mutantsNoCoverage + " were not covered by the tests.");
        }
        this.writeLine(36mutantsTimedOut + ' mutants timed out.');
        this.writeLine(37mutantsKilled + ' mutants killed.');
        this.writeLine(3839"Ran " + (40totalTests / mutantResults.length).toFixed(2) + " tests per mutant on average.");
        if (414243this.options.coverageAnalysis === 'off') 44{
            this.writeLine("Mutation score based on covered code: n/a");
        }
        else 45{
            this.writeLine(46"Mutation score based on covered code: " + codecoverageColor(47mutationScoreCodeCoverage + '%'));
        }
        this.writeLine(48"Mutation score based on all code: " + codebaseColor(49mutationScoreCodebase + '%'));
    };
    ClearTextReporter.prototype.logMutantResult = function (result, logImplementation) 50{
        logImplementation(51525354result.sourceFilePath + ': line ' + result.location.start.line + ':' + result.location.start.column);
        logImplementation(55'Mutator: ' + result.mutatorName);
        result.originalLines.split('\n').forEach(function (line) 56{
            logImplementation(chalk.red(57'-   ' + line));
        });
        result.mutatedLines.split('\n').forEach(function (line) 58{
            logImplementation(chalk.green(59'+   ' + line));
        });
        logImplementation('');
        if (606162this.options.coverageAnalysis === 'perTest') 63{
            if (646566result.testsRan && 6768result.testsRan.length > 0) 69{
                logImplementation('Tests ran: ');
                result.testsRan.forEach(function (spec) 70{ return logImplementation(71'    ' + spec); });
                logImplementation('');
            }
        }
        else if (727374result.testsRan && 7576result.testsRan.length > 0) 77{
            logImplementation('Ran all tests for this mutant.');
        }
    };
    /**
     * Gets the color associated with a mutation score.
     * @function
     * @param score - The mutation score.
     * @returns {Function} The function which can give the mutation score the right color.
     */
    ClearTextReporter.prototype.getColorForMutationScore = function (score) 78{
        var color;
        if (79808182score > 80) 83{
            color = chalk.green;
        }
        else if (84858687score > 50) 88{
            color = chalk.yellow;
        }
        else 89{
            color = chalk.red;
        }
        return color;
    };
    return ClearTextReporter;
}());
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = ClearTextReporter;
//# sourceMappingURL=ClearTextReporter.js.map