UNPKG

@badeball/cypress-cucumber-preprocessor

Version:

[![Build status](https://github.com/badeball/cypress-cucumber-preprocessor/actions/workflows/build.yml/badge.svg)](https://github.com/badeball/cypress-cucumber-preprocessor/actions/workflows/build.yml) [![Npm package weekly downloads](https://badgen.net/n

98 lines (97 loc) 4.63 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || (function () { var ownKeys = function(o) { ownKeys = Object.getOwnPropertyNames || function (o) { var ar = []; for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k; return ar; }; return ownKeys(o); }; return function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]); __setModuleDefault(result, mod); return result; }; })(); var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.getStepDefinitionPaths = getStepDefinitionPaths; exports.pathParts = pathParts; exports.getStepDefinitionPatterns = getStepDefinitionPatterns; const path_1 = __importDefault(require("path")); const glob = __importStar(require("glob")); const util_1 = __importDefault(require("util")); const assert_1 = __importDefault(require("assert")); const debug_1 = __importDefault(require("./helpers/debug")); async function getStepDefinitionPaths(projectRoot, stepDefinitionPatterns) { return (await Promise.all(stepDefinitionPatterns.map((pattern) => glob.glob(pattern, { cwd: projectRoot, absolute: true, nodir: true, windowsPathsNoEscape: true, })))).reduce((acum, el) => acum.concat(el), []); } function trimFeatureExtension(filepath) { return filepath.replace(/\.feature$/, ""); } function pathParts(relativePath) { (0, assert_1.default)(!path_1.default.isAbsolute(relativePath), `Expected a relative path but got ${relativePath}`); const parts = []; do { parts.push(relativePath); } while ((relativePath = path_1.default.normalize(path_1.default.join(relativePath, ".."))) !== "."); return parts; } function getStepDefinitionPatterns(configuration, filepath) { /** * The reason for these assertions is that when giving relative paths to path.relative, the result * will depend on CWD, which is affected by EG. the --config-file parameter [1]. * * [1] https://github.com/badeball/cypress-cucumber-preprocessor/issues/1243 */ (0, assert_1.default)(path_1.default.isAbsolute(configuration.implicitIntegrationFolder), `Expected an absolute path for implicit integration folder but got ${configuration.implicitIntegrationFolder}`); (0, assert_1.default)(path_1.default.isAbsolute(filepath), `Expected an absolute path for spec but got ${filepath}`); const filepathReplacement = glob.escape(trimFeatureExtension(path_1.default.relative(configuration.implicitIntegrationFolder, filepath)), { windowsPathsNoEscape: true }); (0, debug_1.default)(`replacing [filepath] with ${util_1.default.inspect(filepathReplacement)}`); const parts = pathParts(filepathReplacement); (0, debug_1.default)(`replacing [filepart] with ${util_1.default.inspect(parts)}`); const stepDefinitions = [configuration.stepDefinitions].flat(); return stepDefinitions.flatMap((pattern) => { if (pattern.includes("[filepath]") && pattern.includes("[filepart]")) { throw new Error(`Pattern cannot contain both [filepath] and [filepart], but got ${util_1.default.inspect(pattern)}`); } else if (pattern.includes("[filepath]")) { return pattern.replace("[filepath]", filepathReplacement); } else if (pattern.includes("[filepart]")) { return [ ...parts.map((part) => pattern.replace("[filepart]", part)), path_1.default.normalize(pattern.replace("[filepart]", ".")), ]; } else { return pattern; } }); }