UNPKG

testcafe-reporter-minimal

Version:
93 lines (92 loc) 3.62 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports["default"] = _default; var NEW_LINE = '\n '; function _default() { return { noColors: false, spaceLeft: 0, errDescriptors: [], currentFixtureName: null, testCount: 0, skipped: 0, reportTaskStart: function reportTaskStart(startTime, userAgents, testCount) { var _this = this; 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) { this.currentFixtureName = name; }, reportTestDone: function reportTestDone(name, testRunInfo, meta) { var _this2 = this; var hasErr = !!testRunInfo.errs.length; var symbol = null; if (testRunInfo.skipped) { this.skipped++; symbol = this.chalk.cyan('-'); } else if (hasErr) symbol = this.chalk.red('!');else symbol = '.'; var writeData = { name: name, testRunInfo: testRunInfo, meta: meta }; if (this.spaceLeft - 1 < 0) { this.spaceLeft = this.viewportWidth - NEW_LINE.length - 1; this.write(NEW_LINE, writeData); } else this.spaceLeft--; this.write(symbol, writeData); if (hasErr) { this.errDescriptors = this.errDescriptors.concat(testRunInfo.errs.map(function (err) { return { err: err, testName: name, fixtureName: _this2.currentFixtureName }; })); } }, _renderErrors: function _renderErrors(writeData) { var _this3 = this; this.newline(); this.errDescriptors.forEach(function (errDescriptor) { var title = "".concat(_this3.chalk.bold.red(_this3.symbols.err), " ").concat(errDescriptor.fixtureName, " - ").concat(errDescriptor.testName); _this3.setIndent(1).useWordWrap(true).newline().write(title, writeData).newline().newline().setIndent(3).write(_this3.formatError(errDescriptor.err), writeData).newline().newline(); }); }, _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 allPassed = !this.errDescriptors.length; var footer = allPassed ? this.chalk.bold.green("".concat(this.testCount, " passed")) : this.chalk.bold.red("".concat(this.testCount - passed, "/").concat(this.testCount, " failed")); var writeData = { endTime: endTime, passed: passed, warnings: warnings, result: result }; if (!allPassed) this._renderErrors(writeData);else this.newline(); this.setIndent(1).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;