apidog-reporter-allure
Version:
An adapter for apidog proving reports in allure format
72 lines (71 loc) • 1.97 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
exports.findTestCase = findTestCase;
exports.isFolder = isFolder;
var _files = require("../files");
function isFolder(node) {
return !node.hasOwnProperty('steps');
}
const apidogData = function () {
console.log('Parsing apidog model');
const result = (0, _files.loadJson)('apidogExport.json');
if (!result) {
console.log('Could not parse apidog data');
}
return result;
}();
function getTestPath(node, name, path = []) {
const currentPath = [...path, node.name];
const testCase = node.items.find(item => item.name === name);
if (testCase) {
return {
...testCase,
path: currentPath
};
}
if (node.name === name) {
return {
id: node.id ?? 0,
name: node.name,
tags: node.tags ?? [],
path: currentPath
};
}
for (const child of node.children) {
const result = getTestPath(child, name, currentPath);
if (result) return result;
}
return undefined;
}
function findTestCase(name) {
if (!apidogData) return undefined;
const collection = apidogData.apiTestCaseCollection;
if (!Array.isArray(collection)) {
console.log(`[apidog-allure] apiTestCaseCollection is not an array (got ${typeof collection}). Available keys: ${Object.keys(apidogData).join(', ')}`);
return undefined;
}
for (const node of collection) {
if (isFolder(node)) {
// The top-level node is a "Root" container — start paths from its children
for (const child of node.children) {
const result = getTestPath(child, name);
if (result) return result;
}
const direct = node.items.find(i => i.name === name);
if (direct) return {
...direct,
path: []
};
} else if (node.name === name) {
return {
...node,
path: []
};
}
}
return undefined;
}
var _default = exports.default = apidogData;