Innovenergy_trunk/frontend/node_modules/testcafe/lib/reporter/plugin-host.js

142 lines
23 KiB
JavaScript
Raw Normal View History

"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const chalk_1 = __importDefault(require("chalk"));
const indent_string_1 = __importDefault(require("indent-string"));
const lodash_1 = require("lodash");
const moment_loader_1 = __importDefault(require("../utils/moment-loader"));
const string_1 = require("../utils/string");
const get_viewport_width_1 = __importDefault(require("../utils/get-viewport-width"));
const colors_1 = require("../utils/diff/colors");
const symbols_1 = __importDefault(require("../reporter/symbols"));
// NOTE: we should not expose internal state to
// the plugin, to avoid accidental rewrites.
// Therefore we use symbols to store them.
const stream = Symbol();
const wordWrapEnabled = Symbol();
const indent = Symbol();
const errorDecorator = Symbol();
class ReporterPluginHost {
constructor(plugin, outStream, name) {
this.name = name;
this.streamController = null;
this[stream] = outStream || process.stdout;
this[wordWrapEnabled] = false;
this[indent] = 0;
const useColors = this[stream] === process.stdout && chalk_1.default.enabled && !plugin.noColors;
this.chalk = new chalk_1.default.constructor({ enabled: useColors });
this.moment = moment_loader_1.default;
this.viewportWidth = (0, get_viewport_width_1.default)(this[stream]);
this.symbols = Object.assign({}, symbols_1.default);
(0, lodash_1.assignIn)(this, plugin);
this[errorDecorator] = this.createErrorDecorator();
}
// Error decorator
createErrorDecorator() {
return {
'span user-agent': (str) => this.chalk.grey(str),
'span subtitle': (str) => `- ${this.chalk.bold.red(str)} -`,
'div message': (str) => this.chalk.bold.red(str),
'div screenshot-info': lodash_1.identity,
'a screenshot-path': (str) => this.chalk.grey.underline(str),
'code': lodash_1.identity,
'span syntax-string': (str) => this.chalk.green(str),
'span syntax-punctuator': (str) => this.chalk.grey(str),
'span syntax-keyword': (str) => this.chalk.cyan(str),
'span syntax-number': (str) => this.chalk.magenta(str),
'span syntax-regex': (str) => this.chalk.magenta(str),
'span syntax-comment': (str) => this.chalk.grey.bold(str),
'span syntax-invalid': (str) => this.chalk.inverse(str),
[`span ${colors_1.DIFF_COLORS.DIFF_NOT_MODIFIED}`]: (str) => this.chalk.gray(str),
[`span ${colors_1.DIFF_COLORS.DIFF_ADDED}`]: (str) => this.chalk.green(str),
[`span ${colors_1.DIFF_COLORS.DIFF_REMOVED}`]: (str) => this.chalk.red(str),
'div code-frame': lodash_1.identity,
'div code-line': (str) => str + '\n',
'div code-line-last': lodash_1.identity,
'div code-line-num': (str) => ` ${str} |`,
'div code-line-num-base': (str) => this.chalk.bgRed(` > ${str} `) + '|',
'div code-line-src': lodash_1.identity,
'div stack': (str) => '\n\n' + str,
'div stack-line': (str) => str + '\n',
'div stack-line-last': lodash_1.identity,
'div stack-line-name': (str) => ` at ${this.chalk.bold(str)}`,
'div stack-line-location': (str) => ` (${this.chalk.grey.underline(str)})`,
'strong': (str) => this.chalk.bold(str),
'a': (str) => `"${this.chalk.underline(str)}"`,
};
}
// String helpers
indentString(str, indentVal) {
return (0, indent_string_1.default)(str, ' ', indentVal);
}
wordWrap(str, indentVal, width) {
return (0, string_1.wordWrap)(str, indentVal, width);
}
escapeHtml(str) {
return (0, lodash_1.escape)(str);
}
formatError(err, prefix = '') {
const prefixLengthWithoutColors = (0, string_1.removeTTYColors)(prefix).length;
const maxMsgLength = this.viewportWidth - this[indent] - prefixLengthWithoutColors;
let msg = err.formatMessage(this[errorDecorator], maxMsgLength);
if (this[wordWrapEnabled])
msg = this.wordWrap(msg, prefixLengthWithoutColors, maxMsgLength);
else
msg = this.indentString(msg, prefixLengthWithoutColors);
return prefix + msg.substr(prefixLengthWithoutColors);
}
// Writing helpers
newline() {
this._writeToUniqueStream('\n');
return this;
}
write(text) {
if (this[wordWrapEnabled])
text = this.wordWrap(text, this[indent], this.viewportWidth);
else
text = this.indentString(text, this[indent]);
this._writeToUniqueStream(text);
return this;
}
useWordWrap(use) {
this[wordWrapEnabled] = use;
return this;
}
setIndent(val) {
this[indent] = val;
return this;
}
_writeToUniqueStream(text) {
if (!this.streamController || this.streamController.ensureUniqueStream(this[stream], this))
this[stream].write(text);
}
// Abstract methods implemented in plugin
async reportTaskStart( /* startTime, userAgents, testCount, testStructure, taskProperties */) {
throw new Error('Not implemented');
}
async reportFixtureStart( /* name, path */) {
throw new Error('Not implemented');
}
// NOTE: It's an optional method
// async reportTestStart (/* name, testMeta */) {
// throw new Error('Not implemented');
// }
async reportTestDone( /* name, testRunInfo */) {
throw new Error('Not implemented');
}
async reportTaskDone( /* endTime, passed, warnings */) {
throw new Error('Not implemented');
}
// NOTE: It's an optional method
async init() {
// Optional
}
// NOTE: It's an optional method
async reportWarnings( /* warnings */) {
}
}
exports.default = ReporterPluginHost;
module.exports = exports.default;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoicGx1Z2luLWhvc3QuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvcmVwb3J0ZXIvcGx1Z2luLWhvc3QudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7Ozs7QUFBQSxrREFBcUM7QUFDckMsa0VBQXlDO0FBRXpDLG1DQUlnQjtBQUVoQiwyRUFBNEM7QUFDNUMsNENBQTREO0FBQzVELHFGQUEyRDtBQUMzRCxpREFBbUQ7QUFLbkQsa0VBQW1EO0FBR25ELCtDQUErQztBQUMvQyw0Q0FBNEM7QUFDNUMsMENBQTBDO0FBQzFDLE1BQU0sTUFBTSxHQUFZLE1BQU0sRUFBRSxDQUFDO0FBQ2pDLE1BQU0sZUFBZSxHQUFHLE1BQU0sRUFBRSxDQUFDO0FBQ2pDLE1BQU0sTUFBTSxHQUFZLE1BQU0sRUFBRSxDQUFDO0FBQ2pDLE1BQU0sY0FBYyxHQUFJLE1BQU0sRUFBRSxDQUFDO0FBRWpDLE1BQXFCLGtCQUFrQjtJQVluQyxZQUFvQixNQUFXLEVBQUUsU0FBb0IsRUFBRSxJQUFhO1FBQ2hFLElBQUksQ0FBQyxJQUF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