UNPKG

@badeball/cypress-configuration

Version:

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

86 lines (85 loc) 4.92 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.resolveTestFiles = exports.resolveConfiguration = exports.determineCypressEra = exports.CypressEra = exports.UnsupportedCypressEra = exports.UnrecognizedConfigurationFileError = exports.MultipleConfigurationFilesError = exports.MissingConfigurationFileError = exports.CypressConfigurationError = void 0; const fs_1 = __importDefault(require("fs")); const path_1 = __importDefault(require("path")); const cypress_post10_configuration_1 = require("./cypress-post10-configuration"); const cypress_pre10_configuration_1 = require("./cypress-pre10-configuration"); const errors_1 = require("./errors"); Object.defineProperty(exports, "CypressConfigurationError", { enumerable: true, get: function () { return errors_1.CypressConfigurationError; } }); Object.defineProperty(exports, "MissingConfigurationFileError", { enumerable: true, get: function () { return errors_1.MissingConfigurationFileError; } }); Object.defineProperty(exports, "MultipleConfigurationFilesError", { enumerable: true, get: function () { return errors_1.MultipleConfigurationFilesError; } }); Object.defineProperty(exports, "UnrecognizedConfigurationFileError", { enumerable: true, get: function () { return errors_1.UnrecognizedConfigurationFileError; } }); Object.defineProperty(exports, "UnsupportedCypressEra", { enumerable: true, get: function () { return errors_1.UnsupportedCypressEra; } }); const helpers_1 = require("./helpers"); const debug_1 = __importDefault(require("../debug")); var CypressEra; (function (CypressEra) { CypressEra[CypressEra["POST_V10"] = 0] = "POST_V10"; CypressEra[CypressEra["PRE_V10"] = 1] = "PRE_V10"; })(CypressEra = exports.CypressEra || (exports.CypressEra = {})); function determineCypressEra(options) { var _a; const projectRoot = (0, helpers_1.resolveProjectPath)(options); const explicitConfigFile = (_a = (0, helpers_1.findArgumentValue)(options.argv, "--config-file", true)) !== null && _a !== void 0 ? _a : (0, helpers_1.findArgumentValue)(options.argv, "-C", false); if (explicitConfigFile) { if (fs_1.default.existsSync(explicitConfigFile)) { const name = path_1.default.basename(explicitConfigFile); if (name === cypress_pre10_configuration_1.CONFIG_FILE_NAME) { (0, debug_1.default)(`Determined project ${projectRoot} to be ${CypressEra.PRE_V10}`); return CypressEra.PRE_V10; } else if (cypress_post10_configuration_1.CONFIG_FILE_NAMES.includes(name)) { (0, debug_1.default)(`Determined project ${projectRoot} to be ${CypressEra.POST_V10}`); return CypressEra.POST_V10; } else { throw new errors_1.UnrecognizedConfigurationFileError("Unrecognized file " + name); } } else { throw new errors_1.MissingConfigurationFileError("Missing Cypress configuration file."); } } else { const files = fs_1.default.readdirSync(projectRoot); const configFiles = files.filter((file) => [cypress_pre10_configuration_1.CONFIG_FILE_NAME, ...cypress_post10_configuration_1.CONFIG_FILE_NAMES].includes(file)); if (configFiles.length === 0) { throw new errors_1.MissingConfigurationFileError("Unable to find a Cypress configuration file."); } else if (configFiles.length > 1) { throw new errors_1.MultipleConfigurationFilesError("Found multiple Cypress configuration files."); } if (configFiles[0] === cypress_pre10_configuration_1.CONFIG_FILE_NAME) { (0, debug_1.default)(`Determined project ${projectRoot} to be ${CypressEra.PRE_V10}`); return CypressEra.PRE_V10; } else { (0, debug_1.default)(`Determined project ${projectRoot} to be ${CypressEra.POST_V10}`); return CypressEra.POST_V10; } } } exports.determineCypressEra = determineCypressEra; function resolveConfiguration(options) { const era = determineCypressEra(options); if (era === CypressEra.PRE_V10) { throw new errors_1.UnsupportedCypressEra("Unable resolve configuration of Cypress versions below v10"); } else { return (0, cypress_post10_configuration_1.resolvePost10Configuration)(options); } } exports.resolveConfiguration = resolveConfiguration; function resolveTestFiles(configuration) { if ("specPattern" in configuration) { return (0, cypress_post10_configuration_1.resolvePost10TestFiles)(configuration); } else { throw new errors_1.UnsupportedCypressEra("Unable resolve test files of Cypress versions below v10"); } } exports.resolveTestFiles = resolveTestFiles;