Open source, composable payments platform | PCI compliant | SaaS and Self-host options | Enables connectivity to multiple payment, payout, fraud, vault and tokenization providers | Uplifts authorization with intelligent routing and revenue recovery | Reduce payment processing costs with cost observability | Reduces payment ops with reconciliation
Rust adyenbeginner-friendlyfeaturedfinancefintechhacktoberfesthigh-performanceopen-sourceorchestrationpaymentpayment-gatewaypayment-integrationpayment-processingpaymentspayments-platformrestful-apirustsdkstripeworks-with-react
ci(cypress): run only payment-method-relevant specs per connector (#13496)
likhinbopanna81c01f8a4239
diff --git a/cypress-tests/README.md b/cypress-tests/README.mdindex 5dd8070fc2..00df7323b6 100644--- a/cypress-tests/README.md+++ b/cypress-tests/README.md@@ -23,6 +23,7 @@ This is a comprehensive testing framework built with [Cypress](https://cypress.i- [Development Mode (Interactive)](#development-mode-interactive)- [CI Mode (Headless)](#ci-mode-headless)- [Execute tests against multiple connectors or in parallel](#execute-tests-against-multiple-connectors-or-in-parallel)+ - [Payment-method based spec selection](#payment-method-based-spec-selection)- [Test reports](#test-reports)- [Folder structure](#folder-structure)- [Adding tests](#adding-tests)@@ -165,6 +166,40 @@ npm run cypress:routing # Routing testsOptionally, `--parallel <jobs (integer)>` can be passed to run cypress tests in parallel. By default, when `parallel` command is passed, it will be run in batches of `5`.+#### Payment-method based spec selection++`npm run cypress:payments` runs every payment spec by default. Connectors listed+in `CONNECTOR_PAYMENT_METHODS` (`cypress/utils/specSelection/config.js`) instead+run the mandatory setup specs (`01-AccountCreate`, `02-CustomerCreate`,+`03-ConnectorCreate`) plus only the specs matching their payment methods:++```js+loonio: ["bank_redirect"], // 4 specs instead of 89+cryptopay: ["crypto"],+```++The table is opt-in — **listing a connector only affects that connector**, every+other connector keeps running the full suite. It currently covers the connectors+that do not support cards, where the saving is largest.++Valid payment methods are in `PAYMENT_METHODS` in the same file.++To see what would run without executing anything:++```shell+CYPRESS_CONNECTOR=loonio npm run cypress:specs -- payments --print-specs+```++Implementation lives in `cypress/utils/specSelection/`:++| File | Responsibility |+| ----------- | --------------------------------------------------- |+| `config.js` | Connector → payment methods, spec → payment methods |+| `index.js` | `resolveSpecs({ service, connectorId })` |++When adding a payment spec, tag it in `config.js`. Untagged specs run for every+connector, so forgetting to tag one costs time but never coverage.+## Test reportsThe test reports are generated in the `cypress/reports` directory. The reports are generated in the `mochawesome` format and can be viewed in the browser.diff --git a/cypress-tests/cypress/utils/specSelection/config.js b/cypress-tests/cypress/utils/specSelection/config.jsnew file mode 100644index 0000000000..12671df716--- /dev/null+++ b/cypress-tests/cypress/utils/specSelection/config.js@@ -0,0 +1,186 @@+/**+ * Data behind payment-method based spec selection. Logic lives in `index.js`.+ */++/**+ * Payment methods a spec can be tagged with, and the vocabulary of+ * `CONNECTOR_PAYMENT_METHODS` below.+ */+export const PAYMENT_METHODS = Object.freeze([+ "bank_debit",+ "bank_redirect",+ "bank_transfer",+ "card",+ "card_redirect",+ "crypto",+ "gift_card",+ "mobile_payment",+ "open_banking",+ "pay_later",+ "real_time_payment",+ "reward",+ "upi",+ "voucher",+ "wallet",+]);++/**+ * Payment methods supported by connectors that do not support cards.+ *+ * This table is opt-in: a connector listed here runs only the specs matching+ * its payment methods, and any connector *not* listed runs every spec. Card+ * connectors are therefore deliberately absent — add one only when trimming its+ * run is worth maintaining the entry.+ *+ * Card-shaped methods (credit, debit, network token) all collapse into `card`;+ * the card specs do not distinguish them.+ */+export const CONNECTOR_PAYMENT_METHODS = Object.freeze({+ affirm: ["pay_later"],+ bitpay: ["crypto"],+ calida: ["wallet"],+ cashtocode: ["reward"],+ checkbook: ["bank_transfer"],+ coingate: ["crypto"],+ cryptopay: ["crypto"],+ facilitapay: ["bank_transfer"],+ gigadat: ["bank_redirect"],+ globepay: ["wallet"],+ iatapay: ["bank_redirect", "real_time_payment", "upi"],+ inespay: ["bank_debit"],+ itaubank: ["bank_transfer"],+ klarna: ["pay_later"],+ loonio: ["bank_redirect"],+ mifinity: ["wallet"],+ payjustnow: ["pay_later"],+ payjustnowinstore: ["pay_later"],+ paystack: ["bank_redirect"],+ plaid: ["open_banking"],+ prophetpay: ["card_redirect"],+ volt: ["bank_redirect"],+});++/**+ * Payment spec -> the payment methods it exercises, from `PAYMENT_METHODS`.+ *+ * A spec runs when the connector supports *any* of its payment methods, so+ * specs covering several (`52-AlternativePayments`) stay enabled for connectors+ * supporting only one of them.+ *+ * `null` means "always run". `01`-`03` seed the shared `globalState` (merchant,+ * API key, customer, merchant connector account) that every later spec reads+ * through the `getGlobalState` task, so dropping them breaks the whole run.+ * Specs missing from this map are treated the same way, so a newly added spec+ * stays visible until it is tagged here.+ */+const PAYMENT_SPEC_METHODS = Object.freeze({+ "01-AccountCreate.cy.js": null,+ "02-CustomerCreate.cy.js": null,+ "03-ConnectorCreate.cy.js": null,++ // Merchant-platform specs: they exercise merchant/customer/profile/dispute+ // APIs rather than a payment method, but they are re-run for every connector.+ // Tagging them `card` keeps that coverage on the card suites while sparing+ // single-payment-method connectors a run that yields no connector signal.+ "00-CoreFlows.cy.js": ["card"],+ "34-CustomerListTests.cy.js": ["card"],+ "36-DiffCheckValidation.cy.js": ["card"],+ "47-DisputeTests.cy.js": ["card"],+ "52-AcquirerConfigs.cy.js": ["card"],++ "04-NoThreeDSAutoCapture.cy.js": ["card"],+ "05-ThreeDSAutoCapture.cy.js": ["card"],+ "06-NoThreeDSManualCapture.cy.js": ["card"],+ "07-VoidPayment.cy.js": ["card"],+ "08-SyncPayment.cy.js": ["card"],+ "09-RefundPayment.cy.js": ["card"],+ "10-SyncRefund.cy.js": ["card"],+ "11-CreateSingleuseMandate.cy.js": ["card"],+ "12-CreateMultiuseMandate.cy.js": ["card"],+ "13-ListAndRevokeMandate.cy.js": ["card"],+ "14-SaveCardFlow.cy.js": ["card"],+ "15-ZeroAuthMandate.cy.js": ["card"],+ "16-ThreeDSManualCapture.cy.js": ["card"],+ "17-BankTransfers.cy.js": ["bank_transfer"],+ "18-BankRedirect.cy.js": ["bank_redirect"],+ "19-Wallet.cy.js": ["wallet"],+ "20-MandatesUsingPMID.cy.js": ["card"],+ "21-MandatesUsingNTIDProxy.cy.js": ["card"],+ "22-UPI.cy.js": ["upi"],+ "23-Variations.cy.js": ["card"],+ "24-PaymentMethods.cy.js": ["card"],+ "25-ConnectorAgnosticNTID.cy.js": ["card"],+ "26-SessionCall.cy.js": ["card", "wallet"],+ "27-DeletedCustomerPsyncFlow.cy.js": ["card"],+ "28-BusinessProfileConfigs.cy.js": ["card"],+ "29-IncrementalAuth.cy.js": ["card"],+ "30-Overcapture.cy.js": ["card"],+ "31-RealTimePayment.cy.js": ["real_time_payment"],+ "32-DDCRaceCondition.cy.js": ["card"],+ "33-ManualRetry.cy.js": ["card"],+ "35-PaymentsEligibilityAPI.cy.js": ["card"],+ "37-RewardPayment.cy.js": ["reward"],+ "38-CardInstallments.cy.js": ["card"],+ "39-CryptoPayment.cy.js": ["crypto"],+ "40-ExternalVault.cy.js": ["card"],+ "41-CardPaymentBlocking.cy.js": ["card"],+ "42-AutoRetries.cy.js": ["card"],+ "42-CardRedirect.cy.js": ["card_redirect"],+ "42-GiftCardPayment.cy.js": ["gift_card"],+ "42-RequiresCVV.cy.js": ["card"],+ "43-AuthenticationServiceEligibility.cy.js": ["card"],+ "43-BillingDescriptor.cy.js": ["card"],+ "43-PartnerMerchantIdentifier.cy.js": ["card"],+ "43-PayLater.cy.js": ["pay_later"],+ "43-ThreeDSRoutingRegionUAS.cy.js": ["card"],+ "44-ExternalThreeDS.cy.js": ["card"],+ "45-BankDebit.cy.js": ["bank_debit"],+ "46-ConnectorTestingData.cy.js": ["card"],+ "46-ExtendAuthorization.cy.js": ["card"],+ "46-L2L3DataProcessing.cy.js": ["card"],+ "46-StepUpRetries.cy.js": ["card"],+ "47-ManualPaymentUpdate.cy.js": ["card"],+ "47-PollConfig.cy.js": ["card"],+ "47-RefundManualUpdate.cy.js": ["card"],+ "47-StepUpAuth.cy.js": ["card"],+ "47-WalletMandates.cy.js": ["wallet"],+ "48-CardTestingGuard.cy.js": ["card"],+ "48-MITWithLimitedCardData.cy.js": ["card"],+ "48-PaymentLink.cy.js": ["card"],+ "49-PaymentWebhook.cy.js": ["card"],+ "50-PartialAuthorization.cy.js": ["card"],+ "50-RefundWebhook.cy.js": ["card"],+ "51-ExtendedCardInfo.cy.js": ["card"],+ "51-FeatureMetadata.cy.js": ["card"],+ "52-AlternativePayments.cy.js": ["wallet", "pay_later"],+ "52-ClientSessionValidation.cy.js": ["card"],+ "52-FRM.cy.js": ["card"],+ "52-IframeRedirection.cy.js": ["card"],+ "52-MerchantRedirectMethod.cy.js": ["upi"],+ "52-MultipleCapture.cy.js": ["card"],+ "52-OrderDetails.cy.js": ["card"],+ "52-PaymentResponseHash.cy.js": ["card"],+ "52-RelayOperations.cy.js": ["card"],+ "52-UseBillingAsPaymentMethodBilling.cy.js": ["card"],+ "52-VoucherPayment.cy.js": ["voucher"],+ "53-ClearPanRetry.cy.js": ["card"],+ "53-DelayedSessionToken.cy.js": ["wallet"],+ "54-OpenBanking.cy.js": ["open_banking"],+ "54-RefundType.cy.js": ["card"],+ "55-DynamicFields.cy.js": ["card"],+ "56-VaultTokenizationDisable.cy.js": ["card"],+});++/**+ * Services whose specs are selected per connector, keyed by the+ * `cypress:<service>` npm script that runs them.+ *+ * Only `payments` is wired today; the remaining `cypress:*` scripts keep their+ * plain spec globs. Register a service here to filter it too.+ */+export const SERVICES = Object.freeze({+ payments: {+ specDir: "cypress/e2e/spec/Payment",+ specMethods: PAYMENT_SPEC_METHODS,+ },+});diff --git a/cypress-tests/cypress/utils/specSelection/index.js b/cypress-tests/cypress/utils/specSelection/index.jsnew file mode 100644index 0000000000..07c4f4adf7--- /dev/null+++ b/cypress-tests/cypress/utils/specSelection/index.js@@ -0,0 +1,77 @@+import fs from "fs";+import path from "path";+import { fileURLToPath } from "url";++import { CONNECTOR_PAYMENT_METHODS, SERVICES } from "./config.js";++export { PAYMENT_METHODS, SERVICES } from "./config.js";++// .../cypress-tests/cypress/utils/specSelection -> .../cypress-tests+const PACKAGE_ROOT = path.resolve(+ path.dirname(fileURLToPath(import.meta.url)),+ "../../.."+);++/**+ * Resolves the spec files to hand to Cypress for a connector + service pair.+ *+ * Filtering is opt-in: every spec of the service is returned unless the+ * connector has a `CONNECTOR_PAYMENT_METHODS` entry. An unlisted or newly+ * onboarded connector therefore runs everything rather than silently running+ * nothing.+ *+ * @param {object} options+ * @param {string} options.service - Key of `SERVICES`.+ * @param {string} [options.connectorId] - Value of `CYPRESS_CONNECTOR`.+ * @returns {{ specs: string[], skipped: string[], filtered: boolean, reason: string }}+ */+export function resolveSpecs({ service, connectorId }) {+ const config = SERVICES[service];+ if (!config) {+ throw new Error(+ `Unknown Cypress service "${service}". Known services: ${Object.keys(SERVICES).join(", ")}`+ );+ }++ const { specDir, specMethods } = config;++ // Sorted to match the order Cypress would have globbed the directory in,+ // which the `0x-` prerequisite specs depend on.+ const files = fs+ .readdirSync(path.join(PACKAGE_ROOT, specDir))+ .filter((file) => file.endsWith(".cy.js"))+ .sort();++ const toSpecPath = (file) => `${specDir}/${file}`;++ const supported =+ CONNECTOR_PAYMENT_METHODS[String(connectorId).toLowerCase()];++ if (!supported) {+ return {+ specs: files.map(toSpecPath),+ skipped: [],+ filtered: false,+ reason: `no CONNECTOR_PAYMENT_METHODS entry for "${connectorId || "(unset)"}"`,+ };+ }++ const specs = [];+ const skipped = [];++ for (const file of files) {+ // No payment methods means "always run": a prerequisite, or a spec that has+ // not been tagged yet.+ const methods = specMethods[file];+ const shouldRun = !methods || methods.some((m) => supported.includes(m));++ (shouldRun ? specs : skipped).push(toSpecPath(file));+ }++ return {+ specs,+ skipped,+ filtered: true,+ reason: `connector "${connectorId}" supports ${supported.join(", ")}`,+ };+}diff --git a/cypress-tests/package.json b/cypress-tests/package.jsonindex b72d58d5a0..577e4c617f 100644--- a/cypress-tests/package.json+++ b/cypress-tests/package.json@@ -11,10 +11,11 @@"cypress:misc": "cypress run --headless --spec 'cypress/e2e/spec/Misc/**/*'","cypress:modular-pm-service": "cypress run --headless --spec 'cypress/e2e/spec/ModularPmService/**/*'","cypress:payment-method-list": "cypress run --headless --spec 'cypress/e2e/spec/PaymentMethodList/**/*'",- "cypress:payments": "cypress run --headless --spec 'cypress/e2e/spec/Payment/**/*'",+ "cypress:payments": "node scripts/run-cypress.js payments","cypress:payouts": "cypress run --headless --spec 'cypress/e2e/spec/Payout/**/*'","cypress:platform": "cypress run --headless --spec 'cypress/e2e/spec/Platform/**/*'","cypress:routing": "cypress run --headless --spec 'cypress/e2e/spec/Routing/**/*'",+ "cypress:specs": "node scripts/run-cypress.js","report:generate": "node scripts/report-generator.js","report:open": "open dashboard/index.html || start dashboard/index.html || xdg-open dashboard/index.html","dashboard:serve": "node scripts/serve-dashboard.js",diff --git a/cypress-tests/scripts/run-cypress.js b/cypress-tests/scripts/run-cypress.jsnew file mode 100644index 0000000000..c0463994b4--- /dev/null+++ b/cypress-tests/scripts/run-cypress.js@@ -0,0 +1,79 @@+#!/usr/bin/env node+/* eslint-disable no-console */++/**+ * Entry point behind every `cypress:<service>` npm script.+ *+ * Resolves the spec list for `CYPRESS_CONNECTOR` — the mandatory setup specs+ * plus only the specs whose payment methods the connector supports — and runs+ * Cypress against exactly that list. Falls back to the full spec directory when+ * the connector's payment methods cannot be determined.+ *+ * Usage:+ * node scripts/run-cypress.js <service> [...extra cypress args]+ * node scripts/run-cypress.js <service> --print-specs # dry run+ */++import { spawnSync } from "child_process";+import path from "path";+import { fileURLToPath } from "url";++import {+ resolveSpecs,+ SERVICES,+} from "../cypress/utils/specSelection/index.js";++const PACKAGE_ROOT = path.resolve(+ path.dirname(fileURLToPath(import.meta.url)),+ ".."+);++const [service, ...args] = process.argv.slice(2);++if (!SERVICES[service]) {+ console.error(+ `Usage: node scripts/run-cypress.js <${Object.keys(SERVICES).join("|")}> [...cypress args]`+ );+ process.exit(1);+}++const { specs, skipped, filtered, reason } = resolveSpecs({+ service,+ connectorId: process.env.CYPRESS_CONNECTOR,+});++const summary = filtered+ ? `running ${specs.length} spec(s), skipping ${skipped.length}`+ : `running all ${specs.length} spec(s)`;+console.log(`[spec-selection] ${service}: ${summary} — ${reason}`);++if (args.includes("--print-specs")) {+ console.log(specs.join("\n"));+ process.exit(0);+}++const cypress = spawnSync(+ "npm",+ [+ "exec",+ "--",+ "cypress",+ "run",+ "--headless",+ "--spec",+ specs.join(","),+ ...args,+ ],+ {+ cwd: PACKAGE_ROOT,+ stdio: "inherit",+ shell: process.platform === "win32",+ }+);++if (cypress.error) {+ console.error(cypress.error.message);+ process.exit(1);+}++process.exit(cypress.status ?? 1);