UNPKG

stryker

Version:
96 lines 4.38 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var tslib_1 = require("tslib"); var objectUtils_1 = require("../utils/objectUtils"); var plugin_1 = require("stryker-api/plugin"); var typed_inject_1 = require("typed-inject"); var di_1 = require("../di"); var BroadcastReporter = /** @class */ (function () { function BroadcastReporter(options, pluginCreator, log) { var _this = this; this.options = options; this.pluginCreator = pluginCreator; this.log = log; this.reporters = {}; this.options.reporters.forEach(function (reporterName) { return _this.createReporter(reporterName); }); this.logAboutReporters(); } BroadcastReporter.prototype.createReporter = function (reporterName) { if (reporterName === 'progress' && !process.stdout.isTTY) { this.log.info('Detected that current console does not support the "progress" reporter, downgrading to "progress-append-only" reporter'); reporterName = 'progress-append-only'; } this.reporters[reporterName] = this.pluginCreator.create(reporterName); }; BroadcastReporter.prototype.logAboutReporters = function () { var reporterNames = Object.keys(this.reporters); if (reporterNames.length) { if (this.log.isDebugEnabled()) { this.log.debug("Broadcasting to reporters " + JSON.stringify(reporterNames)); } } else { this.log.warn('No reporter configured. Please configure one or more reporters in the (for example: reporters: [\'progress\'])'); } }; BroadcastReporter.prototype.broadcast = function (methodName, eventArgs) { var _this = this; var allPromises = []; Object.keys(this.reporters).forEach(function (reporterName) { var reporter = _this.reporters[reporterName]; if (typeof reporter[methodName] === 'function') { try { var maybePromise = reporter[methodName](eventArgs); if (objectUtils_1.isPromise(maybePromise)) { allPromises.push(maybePromise.catch(function (error) { _this.handleError(error, methodName, reporterName); })); } } catch (error) { _this.handleError(error, methodName, reporterName); } } }); if (allPromises.length) { return Promise.all(allPromises); } }; BroadcastReporter.prototype.onSourceFileRead = function (file) { this.broadcast('onSourceFileRead', file); }; BroadcastReporter.prototype.onAllSourceFilesRead = function (files) { this.broadcast('onAllSourceFilesRead', files); }; BroadcastReporter.prototype.onAllMutantsMatchedWithTests = function (results) { this.broadcast('onAllMutantsMatchedWithTests', results); }; BroadcastReporter.prototype.onMutantTested = function (result) { this.broadcast('onMutantTested', result); }; BroadcastReporter.prototype.onAllMutantsTested = function (results) { this.broadcast('onAllMutantsTested', results); }; BroadcastReporter.prototype.onScoreCalculated = function (score) { this.broadcast('onScoreCalculated', score); }; BroadcastReporter.prototype.wrapUp = function () { return tslib_1.__awaiter(this, void 0, void 0, function () { return tslib_1.__generator(this, function (_a) { switch (_a.label) { case 0: return [4 /*yield*/, this.broadcast('wrapUp', undefined)]; case 1: _a.sent(); return [2 /*return*/]; } }); }); }; BroadcastReporter.prototype.handleError = function (error, methodName, reporterName) { this.log.error("An error occurred during '" + methodName + "' on reporter '" + reporterName + "'. Error is: " + error); }; BroadcastReporter.inject = typed_inject_1.tokens(plugin_1.commonTokens.options, di_1.coreTokens.pluginCreatorReporter, plugin_1.commonTokens.logger); return BroadcastReporter; }()); exports.default = BroadcastReporter; //# sourceMappingURL=BroadcastReporter.js.map