@hayspec/reporter
Version:
Reporter for Hayspec framework.
110 lines • 4.28 kB
JavaScript
"use strict";
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
if (typeof b !== "function" && b !== null)
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
exports.DefaultReporter = void 0;
var spec_1 = require("@hayspec/spec");
var printer_1 = require("../lib/printer");
var DefaultReporter = (function (_super) {
__extends(DefaultReporter, _super);
function DefaultReporter(_a) {
var _b = _a === void 0 ? {} : _a, _c = _b.mute, mute = _c === void 0 ? false : _c;
var _this = _super.call(this) || this;
_this.assertionResults = [];
_this.passedCount = 0;
_this.skippedCount = 0;
_this.failedCount = 0;
_this.printer = new printer_1.Printer({ mute: mute });
return _this;
}
DefaultReporter.prototype.reset = function () {
_super.prototype.reset.call(this);
this.passedCount = 0;
this.skippedCount = 0;
this.failedCount = 0;
};
DefaultReporter.prototype.onBegin = function () {
this.printer.end();
};
DefaultReporter.prototype.onEnd = function () {
var _a;
this.printer.end();
var messages = [];
if (this.passedCount) {
messages.push(this.printer.indent(1, ''), this.printer.colorize('greenBright', this.passedCount), ' passing');
}
if (this.skippedCount) {
messages.push(this.printer.indent(1, ''), this.printer.colorize('yellowBright', this.skippedCount), ' skipped');
}
if (this.failedCount) {
messages.push(this.printer.indent(1, ''), this.printer.colorize('redBright', this.failedCount), ' failed');
}
if (messages.length) {
(_a = this.printer).end.apply(_a, messages);
}
this.printer.end();
};
DefaultReporter.prototype.onSpecStartNote = function (note) {
this.printer.write(this.printer.indent(this.level, ''), note.message);
this.printer.end();
};
DefaultReporter.prototype.onTestStartNote = function (note) {
var skipped = !note.perform;
if (skipped) {
this.skippedCount++;
}
this.printer.write(this.printer.indent(this.level, ''), this.printer.colorize('gray', note.message), ' ', skipped ? this.printer.colorize('yellowBright', '⚑ ') : '');
};
DefaultReporter.prototype.onTestEndNote = function (note) {
var passing = this.assertionResults.indexOf(false) === -1;
if (passing) {
this.passedCount++;
}
else {
this.failedCount++;
}
this.assertionResults = [];
var color = this.getDurationColor(note.duration);
if (color) {
this.printer.write(this.printer.colorize(color, note.duration + "ms"));
}
this.printer.end();
};
DefaultReporter.prototype.onAssertionNote = function (note) {
this.assertionResults.push(note.success);
var passing = note.success;
if (passing) {
this.printer.write(this.printer.colorize('greenBright', '⚑ '));
}
else {
this.printer.write(this.printer.colorize('redBright', '⚑ '));
}
};
DefaultReporter.prototype.getDurationColor = function (duration) {
if (duration > 1000) {
return 'redBright';
}
else if (duration > 500) {
return 'yellowBright';
}
else {
return null;
}
};
return DefaultReporter;
}(spec_1.Reporter));
exports.DefaultReporter = DefaultReporter;
//# sourceMappingURL=default.js.map