UNPKG

apidog-reporter-allure

Version:
124 lines (123 loc) 3.32 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; var _allureJsCommons = require("allure-js-commons"); var _utils = require("../utils"); const allureConfig = { resultsDir: 'allure-results' }; const allureAdapter = function () { const data = { allureConfig, allureRuntime: new _allureJsCommons.AllureRuntime(allureConfig), startGroup: function (groupName = 'standalone') { this.currentGroup = this.allureRuntime.startGroup(groupName); }, endGroup: function () { if (!this.currentGroup) { console.log("No group exists"); return; } this.currentGroup.endGroup(); this.currentGroup = undefined; }, startTest: function (testName, started) { if (this.currentTest) { console.log('Previous test was run'); this.currentTest.endTest(started); } if (!this.currentGroup) { console.log("No group exists"); this.startGroup(); } this.currentTest = this.currentGroup?.startTest(testName, started); }, endTest: function (end) { if (!this.currentTest) { console.log('Could not end test. No Test exists'); return; } this.currentTest.endTest(end); this.currentTest = undefined; }, startStep: function (stepName, start) { if (!this.currentTest) { console.log('Could not attach step. No test exists'); return; } if (this.currentStep) { this.currentStep = { step: this.currentStep.step.startStep(stepName, start), parent: this.currentStep }; } else { this.currentStep = { step: this.currentTest.startStep(stepName, start) }; } }, endStep: function (end) { if (!this.currentStep) { console.log('No step was running'); return; } this.currentStep.step.endStep(end); this.currentStep = this.currentStep.parent; }, stepStatus: function ({ status, message, trace, end }) { if (!this.currentStep) { console.log('No step was running'); return; } if (status) { this.currentStep.step.status = status; } if (message || trace) { this.currentStep.step.statusDetails = { message, trace }; } if (end) { this.endStep(end); } }, testStatus: function ({ message, trace }) { this.testStatusDetails = { message, trace }; if (!this.currentTest) { console.log('No test was running'); return; } if (message || trace) { this.currentTest.statusDetails = this.testStatusDetails; } }, attach: function (name, content, contentType = _allureJsCommons.ContentType.TEXT) { if (!content) { return; } const target = this.currentStep?.step || this.currentTest; if (!target) { console.log('Could not attach. No step or test exists'); return; } target.addAttachment(name, contentType, this.allureRuntime.writeAttachment(content, contentType)); } }; (0, _utils.joinMethods)(data); return data; }(); var _default = exports.default = allureAdapter;