codeceptjs-testit-reporter
Version:
Plugin for sending CodeceptJS test run reports to TestIT
54 lines (53 loc) • 2.43 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.log = exports.cjs2testItStepStatus = exports.cjs2testItStatus = exports.getTestId = exports.parseTestError = exports.parseError = void 0;
var crypto_1 = require("crypto");
var axios_1 = __importDefault(require("axios"));
var codeceptjs_1 = require("codeceptjs");
var constants_1 = require("./constants");
var parseError = function (e) {
return axios_1.default.isAxiosError(e) && e.response
? "Request failed with status code ".concat(e.response.status, " (").concat(e.response.statusText, "). ") +
"Payload: \"".concat(e.response.data, "\"")
: e instanceof Error
? e.toString()
: 'Unknown error';
};
exports.parseError = parseError;
var parseTestError = function (test) {
var _a, _b;
var msg = (_a = test === null || test === void 0 ? void 0 : test.err) === null || _a === void 0 ? void 0 : _a.stack;
if (typeof ((_b = test.err) === null || _b === void 0 ? void 0 : _b.inspect) === "function") {
msg = test === null || test === void 0 ? void 0 : test.err.inspect();
if ((test === null || test === void 0 ? void 0 : test.err.expected) && (test === null || test === void 0 ? void 0 : test.err.actual))
msg += " (expected: ".concat(test.err.expected, ", actual: ").concat(test.err.actual, ")");
}
return msg;
};
exports.parseTestError = parseTestError;
var genTestId = function (test) {
return (0, crypto_1.createHash)("md5")
.update(test.fullTitle())
.digest('base64')
// eslint-disable-next-line no-magic-numbers
.slice(0, -2);
};
var getTestId = function (test) { return test.uid || genTestId(test); };
exports.getTestId = getTestId;
var cjs2testItStatus = function (status) {
if (status)
return constants_1.CJS_2_TESTIT_STATUS_MAP[status];
return undefined;
};
exports.cjs2testItStatus = cjs2testItStatus;
var cjs2testItStepStatus = function (status) {
if (status)
return constants_1.CJS_2_TESTIT_STEP_STATUS_MAP[status];
return undefined;
};
exports.cjs2testItStepStatus = cjs2testItStepStatus;
var log = function (msg) { return codeceptjs_1.output.print("[".concat(constants_1.PLUGIN_NAME, "] ").concat(msg)); };
exports.log = log;