@conduitvc/jest-allure-reporter
Version:
A Jest Allure Reporter, which takes the test-results from jest and creates an allure-report from it.
67 lines • 2.94 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const allure = require("allure-commandline");
const fse = require("fs-extra");
const rp = require("rootpath");
const xmlescape_1 = require("./xmlescape");
const fs = require("fs");
const st = require("string-template");
const path = require("path");
const os = require("os");
const tempDir = path.resolve(path.join(os.tmpdir(), `./allure-results`));
class Allure {
static generateAllureXMLOutput(testsuite) {
const xmlSuiteTempPath = path.resolve(path.join(__dirname, "./templates/xmlSuiteTemplate.xml"));
const xmlTestCasePath = path.resolve(path.join(__dirname, "./templates/xmlTestcaseTemplate.xml"));
const xmlSuiteTemplate = fs.readFileSync(xmlSuiteTempPath, "utf8").toString();
const xmlTestcaseTemplate = fs.readFileSync(xmlTestCasePath, "utf8").toString();
let testcases = "";
testsuite.testcases.forEach((testcase) => {
testcases += st(xmlTestcaseTemplate, {
testStartTime: testcase.startTime,
testStatus: testcase.status,
testStopTime: testcase.stopTime,
testName: testcase.fullName,
testTitle: testcase.title,
testMessage: xmlescape_1.escapeXml(testcase.failureMessages, "")
});
});
const allureXMLstring = st(xmlSuiteTemplate, {
suiteStartTime: testsuite.startTime,
suiteStopTime: testsuite.stopTime,
suiteName: testsuite.name,
testCases: testcases
});
if (!(testsuite.name.includes("undefined"))) {
this.writeXMLToFile(allureXMLstring, testsuite.name);
}
}
static removeOldResults() {
fse.remove(`${tempDir}/*`, (err) => {
if (err)
console.log("Deleting old result-files failed. There might be no old results or something unexpected happened.");
else
console.log("Successfully deleted old results!");
});
}
static writeXMLToFile(xmlstring, name) {
const target = path.resolve(path.join(tempDir, `./${name}-testsuite.xml`));
fs.writeFileSync(target, xmlstring, 'utf8');
}
static generateReport() {
rp();
const historyDir = path.resolve(path.join(tempDir, "./history/"));
fse.copy("allure-report/history/", historyDir, err => {
if (err)
return console.log("Copying old history failed. There might be no history or something unexpected happened.");
else
console.log("Successfully copied history!");
});
const generation = allure(["generate", `${tempDir}`, "--clean"]);
generation.on("exit", function (exitCode) {
console.log("Generation is finished with code:", exitCode);
});
}
}
exports.Allure = Allure;
//# sourceMappingURL=allure.js.map