Innovenergy_trunk/frontend/node_modules/testcafe/lib/notifications/warning-log.js

63 lines
8.2 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 render_template_1 = __importDefault(require("../utils/render-template"));
const message_bus_1 = __importDefault(require("../utils/message-bus"));
class WarningLog {
constructor(globalLog = null, callback) {
this.messageInfos = [];
this.globalLog = globalLog;
this.callback = callback;
this._isCopying = false;
}
get messages() {
return this.messageInfos.map(msg => msg.message);
}
addPlainMessage(msg) {
// NOTE: avoid duplicates
if (!this.messageInfos.find(m => m.message === msg.message))
this.messageInfos.push(msg);
}
addWarning(msg, ...args) {
let message = '';
let actionId = null;
if (typeof msg !== 'string')
({ message, actionId } = msg);
else
message = msg;
args = [message].concat(args);
// @ts-ignore
message = render_template_1.default.apply(null, args); // eslint-disable-line prefer-spread
this.addPlainMessage({ message, actionId });
if (this.globalLog)
this.globalLog.addPlainMessage({ message, actionId });
if (this.callback && !this._isCopying)
this.callback(message, actionId);
}
clear() {
this.messageInfos = [];
}
copyFrom(warningLog) {
this._isCopying = true;
warningLog.messages.forEach(msg => this.addWarning(msg));
this._isCopying = false;
}
static createAddWarningCallback(messageBus, testRun) {
return async (message, actionId) => {
if (messageBus && messageBus instanceof message_bus_1.default) {
const warning = {
message,
testRun,
actionId,
};
await messageBus.emit('before-warning-add', warning);
await messageBus.emit('warning-add', warning);
}
};
}
}
exports.default = WarningLog;
module.exports = exports.default;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoid2FybmluZy1sb2cuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvbm90aWZpY2F0aW9ucy93YXJuaW5nLWxvZy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7OztBQUFBLCtFQUFzRDtBQUV0RCx1RUFBOEM7QUFTOUMsT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