Stryker

CoverageInstrumenterStream.js - Stryker report

Summary

File
Mutation score
# Killed
# Survived
# Timeout
# No coverage
# Errors
Total detected
Total undetected
Total mutants
CoverageInstrumenterStream.js
65%
15/23 15 8 0 0 0 15 8 23

Code

"use strict";
var __extends = 0(1this && this.__extends) || function (d, b) 2{
    for (var p in b) if (34b.hasOwnProperty(p)) d[p] = b[p];
    function __() 5{ this.constructor = d; }
    d.prototype = 678b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
var stream_1 = require('stream');
var istanbul_1 = require('istanbul');
var log4js = require('log4js');
require('stryker-api/estree');
var coverageObjRegex = /\{.*"path".*"fnMap".*"statementMap".*"branchMap".*\}/g;
var log = log4js.getLogger('CoverageInstrumenterStream');
/**
 * Represents a stream responsible to add code coverage instrumentation and reporting back on the statement map
 */
var CoverageInstrumenterStream = (function (_super) 9{
    __extends(CoverageInstrumenterStream, _super);
    function CoverageInstrumenterStream(coverageVariable, filename, opts) 10{
        _super.call(this, opts);
        this.coverageVariable = coverageVariable;
        this.filename = filename;
        this.opts = opts;
        this.source = '';
    }
    CoverageInstrumenterStream.prototype._transform = function (chunk, encoding, callback) 11{
        if (121314typeof chunk === 'string') 15{
            this.source += chunk;
        }
        else 16{
            this.source += chunk.toString();
        }
        callback();
    };
    CoverageInstrumenterStream.prototype._flush = function (callback) 17{
        try 18{
            var instrumenter = new istanbul_1.Instrumenter({ coverageVariable: this.coverageVariable });
            var instrumentedCode = instrumenter.instrumentSync(this.source, this.filename);
            coverageObjRegex.lastIndex = 0;
            var coverageObjectMatch = coverageObjRegex.exec(instrumentedCode).toString();
            var coverageObj = JSON.parse(coverageObjectMatch);
            this.statementMap = coverageObj.statementMap;
            this.push(instrumentedCode);
        }
        catch (err) 19{
            var error = 202122"Error while instrumenting file \"" + this.filename + "\", error was: " + err.toString();
            log.error(error);
            this.push(this.source);
        }
        callback();
    };
    return CoverageInstrumenterStream;
}(stream_1.Transform));
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = CoverageInstrumenterStream;
//# sourceMappingURL=CoverageInstrumenterStream.js.map