UNPKG

@testauto/jest-allure

Version:

A Jest Allure Reporter, which takes the test-results from jest and creates an allure-report from it.

69 lines (68 loc) 2.93 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const save = require("save-file"); 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.homedir(), `./allure-results`)); class Allure { static generateAllureXMLOutput(testsuite) { const xmlSuiteTempPath = path.resolve(path.join(__dirname, "./xmlSuiteTemplate")); const xmlTestCasePath = path.resolve(path.join(__dirname, "./xmlTestcaseTemplate")); 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`)); save(xmlString, target); } 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