testcafe-reporter-list
Version:
List TestCafe reporter plugin.
98 lines (97 loc) • 3.9 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = _default;
function _default() {
return {
noColors: false,
startTime: null,
afterErrList: false,
currentFixtureName: null,
testCount: 0,
skipped: 0,
reportTaskStart: function reportTaskStart(startTime, userAgents, testCount) {
var _this = this;
this.startTime = startTime;
this.testCount = testCount;
var writeData = {
startTime: startTime,
userAgents: userAgents,
testCount: testCount
};
this.setIndent(1).useWordWrap(true).write(this.chalk.bold('Running tests in:'), writeData).newline();
userAgents.forEach(function (ua) {
_this.write("- ".concat(_this.chalk.blue(ua)), writeData).newline();
});
this.newline();
},
reportFixtureStart: function reportFixtureStart(name) {
this.currentFixtureName = name;
},
_renderErrors: function _renderErrors(errs, writeData) {
var _this2 = this;
this.setIndent(3).newline();
errs.forEach(function (err, idx) {
var prefix = _this2.chalk.red("".concat(idx + 1, ") "));
_this2.newline().write(_this2.formatError(err, prefix), writeData).newline().newline();
});
},
reportTestDone: function reportTestDone(name, testRunInfo, meta) {
var hasErr = !!testRunInfo.errs.length;
var symbol = null;
var nameStyle = null;
if (testRunInfo.skipped) {
this.skipped++;
symbol = this.chalk.cyan('-');
nameStyle = this.chalk.cyan;
} else if (hasErr) {
symbol = this.chalk.red.bold(this.symbols.err);
nameStyle = this.chalk.red.bold;
} else {
symbol = this.chalk.green(this.symbols.ok);
nameStyle = this.chalk.grey;
}
name = "".concat(this.currentFixtureName, " - ").concat(name);
var title = "".concat(symbol, " ").concat(nameStyle(name));
if (testRunInfo.unstable) title += this.chalk.yellow(' (unstable)');
if (testRunInfo.screenshotPath) title += " (screenshots: ".concat(this.chalk.grey.underline(testRunInfo.screenshotPath), ")");
var writeData = {
name: name,
testRunInfo: testRunInfo,
meta: meta
};
this.setIndent(1).useWordWrap(true).write(title, writeData);
if (hasErr) this._renderErrors(testRunInfo.errs, writeData);
this.afterErrList = hasErr;
this.newline();
},
_renderWarnings: function _renderWarnings(warnings, writeData) {
var _this3 = this;
this.newline().setIndent(1).write(this.chalk.bold.yellow("Warnings (".concat(warnings.length, "):")), writeData).newline();
warnings.forEach(function (msg) {
_this3.setIndent(1).write(_this3.chalk.bold.yellow('--'), writeData).newline().setIndent(2).write(msg, writeData).newline();
});
},
reportTaskDone: function reportTaskDone(endTime, passed, warnings, result) {
var durationMs = endTime - this.startTime;
var durationStr = this.moment.duration(durationMs).format('h[h] mm[m] ss[s]');
var footer = passed === this.testCount ? this.chalk.bold.green("".concat(this.testCount, " passed")) : this.chalk.bold.red("".concat(this.testCount - passed, "/").concat(this.testCount, " failed"));
footer += this.chalk.gray(" (".concat(durationStr, ")"));
var writeData = {
endTime: endTime,
passed: passed,
warnings: warnings,
result: result
};
this.setIndent(1).useWordWrap(true);
if (!this.afterErrList) this.newline();
this.newline().write(footer, writeData).newline();
if (this.skipped > 0) {
this.write(this.chalk.cyan("".concat(this.skipped, " skipped")), writeData).newline();
}
if (warnings.length) this._renderWarnings(warnings, writeData);
}
};
}
module.exports = exports.default;