Innovenergy_trunk/frontend/node_modules/testcafe/lib/utils/prepare-reporters.js

32 lines
3.8 KiB
JavaScript
Raw Normal View History

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const is_stream_1 = require("is-stream");
const runtime_1 = require("../errors/runtime");
const types_1 = require("../errors/types");
function isStreamMock(obj) {
return obj &&
typeof obj.write === 'function' &&
typeof obj.end === 'function';
}
function validateReporterOutput(obj) {
const isValidReporterOutput = obj === void 0 ||
typeof obj === 'string' ||
(0, is_stream_1.writable)(obj) ||
isStreamMock(obj);
if (!isValidReporterOutput)
throw new runtime_1.GeneralError(types_1.RUNTIME_ERRORS.invalidReporterOutput);
}
function default_1(name, output) {
let reporters = [];
if (name instanceof Array)
reporters = name.map(r => typeof r === 'string' || typeof r === 'function' ? { name: r } : r);
else {
const reporter = { name, output };
reporters.push(reporter);
}
reporters.forEach(r => validateReporterOutput(r.output));
return reporters;
}
exports.default = default_1;
module.exports = exports.default;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoicHJlcGFyZS1yZXBvcnRlcnMuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvdXRpbHMvcHJlcGFyZS1yZXBvcnRlcnMuanMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7QUFBQSx5Q0FBeUQ7QUFDekQsK0NBQWlEO0FBQ2pELDJDQUFpRDtBQUVqRCxTQUFTLFlBQVksQ0FBRSxHQUFHO0lBQ3RCLE9BQU8sR0FBRztRQUNILE9BQU8sR0FBRyxDQUFDLEtBQUssS0FBSyxVQUFVO1FBQy9CLE9BQU8sR0FBRyxDQUFDLEdBQUcsS0FBSyxVQUFVLENBQUM7QUFDekMsQ0FBQztBQUVELFNBQVMsc0JBQXNCLENBQUUsR0FBRztJQUNoQyxNQUFNLHFCQUFxQixHQUFHLEdBQUcsS0FBSyxLQUFLLENBQUM7UUFDdEMsT0FBTyxHQUFHLEtBQUssUUFBUTtRQ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