Stryker

ClearTextReporter.js - Stryker report

Summary

File Based on all code Based on code coverage
ClearTextReporter.js
93%
57/61 93% 57/61

Code

"use strict";
var report_1 = require('stryker-api/report');
var chalk = require('chalk');
var _ = require('lodash');
var log4js = require('log4js');
var log = log4js.getLogger('ClearTextReporter');
var ClearTextReporter = (function () 0{
    function ClearTextReporter() 1{
        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 mutantsKilled = 0;
        var mutantsTimedOut = 0;
        var mutantsUntested = 0;
        var logDebugFn = function (input) 6{ return log.debug(input); };
        var writeLineFn = function (input) 7{ return _this.writeLine(input); };
        mutantResults.forEach(function (result) 8{
            switch (result.status) {
                case report_1.MutantStatus.KILLED:
                    9mutantsKilled++;
                    log.debug(chalk.bold.green('Mutant killed!'));
                    _this.logMutantResult(result, logDebugFn);
                    break;
                case report_1.MutantStatus.TIMEDOUT:
                    10mutantsTimedOut++;
                    log.debug(chalk.bold.yellow('Mutant timed out!'));
                    _this.logMutantResult(result, logDebugFn);
                    break;
                case report_1.MutantStatus.SURVIVED:
                    _this.writeLine(chalk.bold.red('Mutant survived!'));
                    _this.logMutantResult(result, writeLineFn);
                    break;
                case report_1.MutantStatus.UNTESTED:
                    11mutantsUntested++;
                    log.debug(chalk.bold.yellow('Mutant untested!'));
                    _this.logMutantResult(result, logDebugFn);
                    break;
            }
        });
        var mutationScoreCodebase = (12(13(14mutantsKilled + mutantsTimedOut) / mutantResults.length) * 100).toFixed(2);
        var mutationScoreCodeCoverage = (15(16(17mutantsKilled + mutantsTimedOut) / (18(19mutantResults.length - mutantsUntested) || 1)) * 100).toFixed(2);
        var codebaseColor = this.getColorForMutationScore(20+mutationScoreCodebase);
        var codecoverageColor = this.getColorForMutationScore(21+mutationScoreCodeCoverage);
        this.writeLine(22(23mutantResults.length - mutantsUntested) + ' mutants tested.');
        this.writeLine(24mutantsUntested + ' mutants untested.');
        this.writeLine(25mutantsTimedOut + ' mutants timed out.');
        this.writeLine(26mutantsKilled + ' mutants killed.');
        this.writeLine(27'Mutation score based on covered code: ' + codecoverageColor(28mutationScoreCodeCoverage + '%'));
        this.writeLine(29'Mutation score based on all code: ' + codebaseColor(30mutationScoreCodebase + '%'));
    };
    ClearTextReporter.prototype.logMutantResult = function (result, logImplementation) 31{
        logImplementation(32333435result.sourceFilePath + ': line ' + result.location.start.line + ':' + result.location.start.column);
        logImplementation(36'Mutator: ' + result.mutatorName);
        result.originalLines.split('\n').forEach(function (line) 37{
            logImplementation(chalk.red(38'-   ' + line));
        });
        result.mutatedLines.split('\n').forEach(function (line) 39{
            logImplementation(chalk.green(40'+   ' + line));
        });
        logImplementation('');
        if (414243result.testsRan && 4445result.testsRan.length > 0) 46{
            logImplementation('Tests ran: ');
            _.forEach(result.testsRan, function (spec) 47{
                logImplementation(48'    ' + spec);
            });
            logImplementation('');
        }
    };
    ClearTextReporter.prototype.getColorForMutationScore = function (score) 49{
        var color;
        if (50515253score > 80) 54{
            color = chalk.green;
        }
        else if (55565758score > 50) 59{
            color = chalk.yellow;
        }
        else 60{
            color = chalk.red;
        }
        return color;
    };
    return ClearTextReporter;
}());
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = ClearTextReporter;
//# sourceMappingURL=ClearTextReporter.js.map