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

233 lines (232 loc) 14 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.COMPILED_REPORTER_ENTRYPOINT = void 0; exports.combineIntoConfiguration = combineIntoConfiguration; exports.resolve = resolve; const node_util_1 = __importDefault(require("node:util")); const cosmiconfig_1 = require("cosmiconfig"); const Either_1 = require("fp-ts/Either"); const D = __importStar(require("io-ts/Decoder")); const debug_1 = __importDefault(require("./helpers/debug")); const error_1 = require("./helpers/error"); const paths_1 = require("./helpers/paths"); function decode(decoder, val) { const res = decoder.decode(val); if ((0, Either_1.isRight)(res)) { return res.right; } else { throw new error_1.CypressCucumberError(D.draw(res.left)); } } function stringToMaybeBoolean(value) { if (value === "") { return; } const falsyValues = ["0", "false"]; if (falsyValues.includes(value)) { return false; } else { return true; } } const FilterSpecsMixedMode = D.union(D.literal("hide"), D.literal("show"), D.literal("empty-set")); const StringishToBoolean = { decode: (val) => { if (typeof val === "string") { return D.success(stringToMaybeBoolean(val)); } else if (typeof val === "boolean") { return D.success(val); } else { return D.failure(val, "string"); } }, }; const EnvironmentOverrides = D.partial({ stepDefinitions: D.union(D.string, D.array(D.string)), stateSoftErrors: StringishToBoolean, messagesEnabled: StringishToBoolean, messagesOutput: D.string, jsonEnabled: StringishToBoolean, jsonOutput: D.string, htmlEnabled: StringishToBoolean, htmlOutput: D.string, usageEnabled: StringishToBoolean, usageOutput: D.string, prettyEnabled: StringishToBoolean, filterSpecsMixedMode: FilterSpecsMixedMode, filterSpecs: StringishToBoolean, omitFiltered: StringishToBoolean, dryRun: StringishToBoolean, attachmentsAddScreenshots: StringishToBoolean, attachmentsAddVideos: StringishToBoolean, }); const BaseConfiguration = D.partial({ stepDefinitions: D.union(D.string, D.array(D.string)), state: D.partial({ softErrors: D.boolean, }), messages: D.partial({ enabled: D.boolean, output: D.string, }), json: D.partial({ enabled: D.boolean, output: D.string, }), html: D.partial({ enabled: D.boolean, output: D.string, }), usage: D.partial({ enabled: D.boolean, output: D.string, }), pretty: D.partial({ enabled: D.boolean, }), filterSpecsMixedMode: FilterSpecsMixedMode, filterSpecs: D.boolean, omitFiltered: D.boolean, dryRun: D.boolean, attachments: D.partial({ addScreenshots: D.boolean, addVideos: D.boolean, }), }); const UserConfiguration = D.intersect(D.partial({ e2e: BaseConfiguration, component: BaseConfiguration, }))(BaseConfiguration); const DEFAULT_STEP_DEFINITIONS = [ "[integration-directory]/[filepath]/**/*.{js,mjs,ts,tsx}", "[integration-directory]/[filepath].{js,mjs,ts,tsx}", "cypress/support/step_definitions/**/*.{js,mjs,ts,tsx}", ]; exports.COMPILED_REPORTER_ENTRYPOINT = "dist/subpath-entrypoints/pretty-reporter.js"; function combineIntoConfiguration(configuration, overrides, cypress, implicitIntegrationFolder) { var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, _20, _21, _22, _23, _24, _25, _26, _27, _28, _29, _30, _31, _32, _33, _34, _35, _36, _37, _38, _39, _40, _41, _42, _43, _44, _45, _46, _47, _48, _49, _50, _51; const defaultStepDefinitions = DEFAULT_STEP_DEFINITIONS.map((pattern) => pattern.replace("[integration-directory]", (0, paths_1.ensureIsRelative)(cypress.projectRoot, implicitIntegrationFolder))); const specific = configuration[cypress.testingType]; const unspecific = configuration; const stepDefinitions = (_c = (_b = (_a = overrides.stepDefinitions) !== null && _a !== void 0 ? _a : specific === null || specific === void 0 ? void 0 : specific.stepDefinitions) !== null && _b !== void 0 ? _b : unspecific.stepDefinitions) !== null && _c !== void 0 ? _c : defaultStepDefinitions; const json = { enabled: (_h = (_f = (_d = overrides.jsonEnabled) !== null && _d !== void 0 ? _d : (_e = specific === null || specific === void 0 ? void 0 : specific.json) === null || _e === void 0 ? void 0 : _e.enabled) !== null && _f !== void 0 ? _f : (_g = unspecific.json) === null || _g === void 0 ? void 0 : _g.enabled) !== null && _h !== void 0 ? _h : false, output: (_o = (_l = (_j = overrides.jsonOutput) !== null && _j !== void 0 ? _j : (_k = specific === null || specific === void 0 ? void 0 : specific.json) === null || _k === void 0 ? void 0 : _k.output) !== null && _l !== void 0 ? _l : (_m = unspecific.json) === null || _m === void 0 ? void 0 : _m.output) !== null && _o !== void 0 ? _o : "cucumber-report.json", }; const html = { enabled: (_t = (_r = (_p = overrides.htmlEnabled) !== null && _p !== void 0 ? _p : (_q = specific === null || specific === void 0 ? void 0 : specific.html) === null || _q === void 0 ? void 0 : _q.enabled) !== null && _r !== void 0 ? _r : (_s = unspecific.html) === null || _s === void 0 ? void 0 : _s.enabled) !== null && _t !== void 0 ? _t : false, output: (_y = (_w = (_u = overrides.htmlOutput) !== null && _u !== void 0 ? _u : (_v = specific === null || specific === void 0 ? void 0 : specific.html) === null || _v === void 0 ? void 0 : _v.output) !== null && _w !== void 0 ? _w : (_x = unspecific.html) === null || _x === void 0 ? void 0 : _x.output) !== null && _y !== void 0 ? _y : "cucumber-report.html", }; const messages = { enabled: (_3 = (_1 = (_z = overrides.messagesEnabled) !== null && _z !== void 0 ? _z : (_0 = specific === null || specific === void 0 ? void 0 : specific.messages) === null || _0 === void 0 ? void 0 : _0.enabled) !== null && _1 !== void 0 ? _1 : (_2 = unspecific.messages) === null || _2 === void 0 ? void 0 : _2.enabled) !== null && _3 !== void 0 ? _3 : false, output: (_8 = (_6 = (_4 = overrides.messagesOutput) !== null && _4 !== void 0 ? _4 : (_5 = specific === null || specific === void 0 ? void 0 : specific.messages) === null || _5 === void 0 ? void 0 : _5.output) !== null && _6 !== void 0 ? _6 : (_7 = unspecific.messages) === null || _7 === void 0 ? void 0 : _7.output) !== null && _8 !== void 0 ? _8 : "cucumber-messages.ndjson", }; const state = { softErrors: (_13 = (_11 = (_9 = overrides.stateSoftErrors) !== null && _9 !== void 0 ? _9 : (_10 = specific === null || specific === void 0 ? void 0 : specific.state) === null || _10 === void 0 ? void 0 : _10.softErrors) !== null && _11 !== void 0 ? _11 : (_12 = unspecific.state) === null || _12 === void 0 ? void 0 : _12.softErrors) !== null && _13 !== void 0 ? _13 : false, }; const usage = { enabled: (_18 = (_16 = (_14 = overrides.usageEnabled) !== null && _14 !== void 0 ? _14 : (_15 = specific === null || specific === void 0 ? void 0 : specific.usage) === null || _15 === void 0 ? void 0 : _15.enabled) !== null && _16 !== void 0 ? _16 : (_17 = unspecific.usage) === null || _17 === void 0 ? void 0 : _17.enabled) !== null && _18 !== void 0 ? _18 : false, output: (_23 = (_21 = (_19 = overrides.usageOutput) !== null && _19 !== void 0 ? _19 : (_20 = specific === null || specific === void 0 ? void 0 : specific.usage) === null || _20 === void 0 ? void 0 : _20.output) !== null && _21 !== void 0 ? _21 : (_22 = unspecific.usage) === null || _22 === void 0 ? void 0 : _22.output) !== null && _23 !== void 0 ? _23 : "stdout", }; const usingPrettyReporter = cypress.reporter.endsWith(exports.COMPILED_REPORTER_ENTRYPOINT); if (usingPrettyReporter) { (0, debug_1.default)("detected use of @badeball/cypress-cucumber-preprocessor/pretty-reporter, enabling pretty output"); } const pretty = { enabled: (_28 = (_26 = (_24 = overrides.prettyEnabled) !== null && _24 !== void 0 ? _24 : (_25 = specific === null || specific === void 0 ? void 0 : specific.pretty) === null || _25 === void 0 ? void 0 : _25.enabled) !== null && _26 !== void 0 ? _26 : (_27 = unspecific.pretty) === null || _27 === void 0 ? void 0 : _27.enabled) !== null && _28 !== void 0 ? _28 : usingPrettyReporter, }; const filterSpecsMixedMode = (_31 = (_30 = (_29 = overrides.filterSpecsMixedMode) !== null && _29 !== void 0 ? _29 : specific === null || specific === void 0 ? void 0 : specific.filterSpecsMixedMode) !== null && _30 !== void 0 ? _30 : unspecific.filterSpecsMixedMode) !== null && _31 !== void 0 ? _31 : "hide"; const filterSpecs = (_34 = (_33 = (_32 = overrides.filterSpecs) !== null && _32 !== void 0 ? _32 : specific === null || specific === void 0 ? void 0 : specific.filterSpecs) !== null && _33 !== void 0 ? _33 : unspecific.filterSpecs) !== null && _34 !== void 0 ? _34 : false; const omitFiltered = (_37 = (_36 = (_35 = overrides.omitFiltered) !== null && _35 !== void 0 ? _35 : specific === null || specific === void 0 ? void 0 : specific.omitFiltered) !== null && _36 !== void 0 ? _36 : unspecific.omitFiltered) !== null && _37 !== void 0 ? _37 : false; const dryRun = (_40 = (_39 = (_38 = overrides.dryRun) !== null && _38 !== void 0 ? _38 : specific === null || specific === void 0 ? void 0 : specific.dryRun) !== null && _39 !== void 0 ? _39 : unspecific.dryRun) !== null && _40 !== void 0 ? _40 : false; const isTrackingState = ((_41 = cypress.isTextTerminal) !== null && _41 !== void 0 ? _41 : false) && (messages.enabled || json.enabled || html.enabled || pretty.enabled || usage.enabled || usingPrettyReporter); const attachments = { addScreenshots: (_46 = (_44 = (_42 = overrides.attachmentsAddScreenshots) !== null && _42 !== void 0 ? _42 : (_43 = specific === null || specific === void 0 ? void 0 : specific.attachments) === null || _43 === void 0 ? void 0 : _43.addScreenshots) !== null && _44 !== void 0 ? _44 : (_45 = unspecific.attachments) === null || _45 === void 0 ? void 0 : _45.addScreenshots) !== null && _46 !== void 0 ? _46 : true, addVideos: (_51 = (_49 = (_47 = overrides.attachmentsAddVideos) !== null && _47 !== void 0 ? _47 : (_48 = specific === null || specific === void 0 ? void 0 : specific.attachments) === null || _48 === void 0 ? void 0 : _48.addVideos) !== null && _49 !== void 0 ? _49 : (_50 = unspecific.attachments) === null || _50 === void 0 ? void 0 : _50.addVideos) !== null && _51 !== void 0 ? _51 : false, }; return { stepDefinitions, state, messages, json, html, pretty, usage, filterSpecsMixedMode, filterSpecs, omitFiltered, implicitIntegrationFolder, isTrackingState, dryRun, attachments, }; } async function cosmiconfigResolver(projectRoot) { const result = await (0, cosmiconfig_1.cosmiconfig)("cypress-cucumber-preprocessor", { searchStrategy: "project", }).search(projectRoot); return result === null || result === void 0 ? void 0 : result.config; } async function resolve(cypressConfig, environment, implicitIntegrationFolder, configurationFileResolver = cosmiconfigResolver) { const result = await configurationFileResolver(cypressConfig.projectRoot); const environmentOverrides = decode(EnvironmentOverrides, environment); (0, debug_1.default)(`resolved environment overrides ${node_util_1.default.inspect(environmentOverrides)}`); let explicitConfiguration; if (result) { explicitConfiguration = decode(UserConfiguration, result); (0, debug_1.default)(`resolved explicit user configuration ${node_util_1.default.inspect(explicitConfiguration)}`); } else { explicitConfiguration = {}; (0, debug_1.default)("resolved no explicit user configuration"); } const configuration = combineIntoConfiguration(explicitConfiguration, environmentOverrides, cypressConfig, implicitIntegrationFolder); (0, debug_1.default)(`resolved configuration ${node_util_1.default.inspect(configuration)}`); return configuration; }