UNPKG

allure-js-commons

Version:
68 lines (67 loc) 2.46 kB
import { existsSync, readFileSync } from "node:fs"; import { allureIdRegexp } from "../utils.js"; export var parseTestPlan = () => { var testPlanPath = process.env.ALLURE_TESTPLAN_PATH; if (!testPlanPath) { return undefined; } if (!existsSync(testPlanPath)) { // eslint-disable-next-line no-console console.error("Test plan file is missing. Skipping test plan usage:", testPlanPath); return undefined; } try { var file = readFileSync(testPlanPath, "utf8"); var testPlan = JSON.parse(file); if (testPlan.version !== "1.0") { // eslint-disable-next-line no-console console.error("Test plan version is unsupported. Skipping test plan usage:", testPlan.version); return undefined; } // Execute all tests if test plan is empty if (!Array.isArray(testPlan.tests) || testPlan.tests.length === 0) { return undefined; } return testPlan; } catch (e) { // eslint-disable-next-line no-console console.error("could not parse test plan ".concat(testPlanPath), e); return undefined; } }; export var includedInTestPlan = (testPlan, subject) => { var _ref; var { allureId, id, fullName, nativeSelector, tags = [] } = subject; var effectiveId = (_ref = allureId !== null && allureId !== void 0 ? allureId : id) !== null && _ref !== void 0 ? _ref : tags.map(tag => { var _tag$match; return tag === null || tag === void 0 || (_tag$match = tag.match(allureIdRegexp)) === null || _tag$match === void 0 || (_tag$match = _tag$match.groups) === null || _tag$match === void 0 ? void 0 : _tag$match.id; }).find(maybeId => maybeId !== undefined); return testPlan.tests.some(test => { var idMatched = effectiveId !== undefined && test.id !== undefined && String(test.id) === effectiveId; var selectorMatched = fullName !== undefined && test.selector === fullName; var nativeSelectorMatched = nativeSelector !== undefined && test.selector === nativeSelector; return idMatched || selectorMatched || nativeSelectorMatched; }); }; export var addSkipLabel = labels => { labels.push({ name: "ALLURE_TESTPLAN_SKIP", value: "true" }); }; export var addSkipLabelAsMeta = name => { return "".concat(name, " @allure.label.ALLURE_TESTPLAN_SKIP:true"); }; export var hasSkipLabel = labels => labels.some(_ref2 => { var { name } = _ref2; return name === "ALLURE_TESTPLAN_SKIP"; }); //# sourceMappingURL=testplan.js.map