jest-trx-results-processor
Version:
Jest results processor for exporting into TRX files for Visual Studio
74 lines (73 loc) • 3.08 kB
JavaScript
;
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.getEnvInfo = exports.getTestClassName = exports.getFullTestName = exports.formatDuration = void 0;
var os = __importStar(require("os"));
// Adapted from https://github.com/hatchteam/karma-trx-reporter
var formatDuration = function (duration) {
var durationInner = duration || 0;
var ms = durationInner % 1000;
durationInner -= ms;
var s = (durationInner / 1000) % 60;
durationInner -= s * 1000;
var m = (durationInner / 60000) % 60;
durationInner -= m * 60000;
var h = (durationInner / 3600000) % 24;
durationInner -= h * 3600000;
var d = durationInner / 86400000;
var dayPart = d > 0 ? "".concat(d, ".") : "";
var hours = h.toString().padStart(2, "0");
var minutes = m.toString().padStart(2, "0");
var seconds = s.toString().padStart(2, "0");
var milliseconds = ms.toString().padStart(3, "0");
return "".concat(dayPart + hours, ":").concat(minutes, ":").concat(seconds, ".").concat(milliseconds);
};
exports.formatDuration = formatDuration;
// Auxillary test data functions
var getFullTestName = function (testResult) {
return testResult.ancestorTitles && testResult.ancestorTitles.length
? "".concat(testResult.ancestorTitles.join(" / "), " / ").concat(testResult.title)
: testResult.title;
};
exports.getFullTestName = getFullTestName;
var getTestClassName = function (testResult) {
return testResult.ancestorTitles && testResult.ancestorTitles.length
? testResult.ancestorTitles[0]
: "No suite";
};
exports.getTestClassName = getTestClassName;
var getEnvInfo = function (defaultUserName) {
if (defaultUserName === void 0) { defaultUserName = "anonymous"; }
return ({
computerName: os.hostname(),
userName: process.env.SUDO_USER ||
process.env.LOGNAME ||
process.env.USER ||
process.env.LNAME ||
process.env.USERNAME ||
defaultUserName,
});
};
exports.getEnvInfo = getEnvInfo;