UNPKG

lobo

Version:
83 lines (82 loc) 2.76 kB
"use strict"; exports.__esModule = true; var Bluebird = require("bluebird"); var program = require("commander"); var fs = require("fs"); var JsonReporter = /** @class */ (function () { function JsonReporter(logger) { this.logger = logger; } JsonReporter.toCommonOutput = function (summary) { return { config: summary.config, durationMilliseconds: summary.durationMilliseconds, endDateTime: summary.endDateTime, failedCount: summary.failedCount, onlyCount: summary.onlyCount, outcome: summary.outcome, passedCount: summary.passedCount, runType: summary.runType, skippedCount: summary.skippedCount, startDateTime: summary.startDateTime, success: summary.success, todoCount: summary.todoCount }; }; JsonReporter.prototype.runArgs = function () { // ignore args }; JsonReporter.prototype.init = function () { // ignore testCount }; JsonReporter.prototype.update = function (result) { this.logger.log(JSON.stringify(result)); }; JsonReporter.prototype.finish = function (results) { var _this = this; return new Bluebird(function (resolve, reject) { var toFile = program.reportFile !== undefined && program.reportFile !== null && program.reportFile.length > 0; var data = _this.toString(results, toFile); if (toFile) { fs.writeFile(program.reportFile, data, function (err) { if (!err) { resolve(); return; } reject(err); }); } else { _this.logger.log(data); resolve(); } }); }; JsonReporter.prototype.toFull = function (summary) { var output = JsonReporter.toCommonOutput(summary); output.runResults = summary.runResults; return output; }; JsonReporter.prototype.toSummary = function (summary) { return JsonReporter.toCommonOutput(summary); }; JsonReporter.prototype.toString = function (results, prettyPrint) { var output; if (program.quiet) { output = this.toSummary(results.summary); } else { output = this.toFull(results.summary); } if (prettyPrint) { return JSON.stringify(output, null, 2); } return JSON.stringify(output); }; return JsonReporter; }()); exports.JsonReporter = JsonReporter; function createPlugin() { return new JsonReporter(console); } exports.createPlugin = createPlugin;