UNPKG

testcafe-reporter-spec

Version:
126 lines (125 loc) 5.03 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports["default"] = _default; function _default() { return { noColors: false, startTime: null, afterErrorList: false, 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(); }); }, reportFixtureStart: function reportFixtureStart(name, path, meta) { this.setIndent(1).useWordWrap(true); if (this.afterErrorList) this.afterErrorList = false;else this.newline(); var writeData = { name: name, path: path, meta: meta }; this.write(name, writeData).newline(); }, _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; } var title = "".concat(symbol, " ").concat(nameStyle(name)); this.setIndent(1).useWordWrap(true); if (testRunInfo.unstable) title += this.chalk.yellow(' (unstable)'); if (testRunInfo.screenshotPath) title += " (screenshots: ".concat(this.chalk.underline.grey(testRunInfo.screenshotPath), ")"); var writeData = { name: name, testRunInfo: testRunInfo, meta: meta }; this.write(title, writeData); this._renderReportData(testRunInfo.reportData, testRunInfo.browsers, writeData); if (hasErr) this._renderErrors(testRunInfo.errs, writeData); this.afterErrorList = hasErr; this.newline(); }, _renderReportData: function _renderReportData(reportData, browsers, writeData) { var _this3 = this; if (!reportData) return; if (!Object.values(reportData).some(function (data) { return data.length; })) return; var renderBrowserName = browsers.length > 1; var dataIndent = browsers.length > 1 ? 3 : 2; this.newline().setIndent(1).write('Report data:'); browsers.forEach(function (_ref) { var testRunId = _ref.testRunId, prettyUserAgent = _ref.prettyUserAgent; var browserReportData = reportData[testRunId]; if (!browserReportData) return; if (renderBrowserName) { _this3.setIndent(2).newline().write(prettyUserAgent, writeData); } browserReportData.forEach(function (data) { _this3.setIndent(dataIndent).newline().write("- ".concat(data), writeData); }); }); }, _renderWarnings: function _renderWarnings(warnings, writeData) { var _this4 = this; this.newline().setIndent(1).write(this.chalk.bold.yellow("Warnings (".concat(warnings.length, "):")), writeData).newline(); warnings.forEach(function (msg) { _this4.setIndent(1).write(_this4.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.grey(" (".concat(durationStr, ")")); if (!this.afterErrorList) this.newline(); this.setIndent(1).useWordWrap(true); var writeData = { endTime: endTime, passed: passed, warnings: warnings, result: result }; 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;