jest-zephyr-scale-reporter
Version:
A test reporter for zephyr scale
50 lines (49 loc) • 2.16 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
var path_1 = __importDefault(require("path"));
var fs_1 = __importDefault(require("fs"));
var JestZephyrScaleReporter = /** @class */ (function () {
function JestZephyrScaleReporter(globalConfig, options) {
this.globalConfig = globalConfig;
this.options = options;
this.tests = [];
this.parseContent = function (testCase) {
var name = testCase.fullName.trim();
var testCaseKey = null;
var matcher = /[A-Z]+-T[0-9]+/;
var matches = name.match(matcher);
if (matches !== undefined && matches !== null) {
testCaseKey = matches[0];
name = name.replace(testCaseKey, "");
name = name.replace(/\s{2,}/g, ' ');
}
if (testCaseKey === null) {
return null;
}
return {
source: name,
result: testCase.status.charAt(0).toUpperCase() + testCase.status.slice(1),
testcase: {
key: testCaseKey
}
};
};
}
JestZephyrScaleReporter.prototype.onRunComplete = function (context, results) {
var _this = this;
var testResults = this.tests.map(function (x) { return _this.parseContent(x); }).filter(function (x) { return x !== null; });
this.writeJson(testResults, "zephyr-report.json");
};
JestZephyrScaleReporter.prototype.onTestResult = function (test, testResults, runResults) {
this.tests = this.tests.concat(testResults.testResults);
};
JestZephyrScaleReporter.prototype.writeJson = function (content, filename) {
fs_1.default.writeFileSync(path_1.default.join('./', filename), JSON.stringify({ version: 1, executions: content }));
console.log("Wrote Zephyr Scale report to " + filename);
};
return JestZephyrScaleReporter;
}());
exports.default = JestZephyrScaleReporter;