@12-apps/payments-e2e

中文文档
2.12.0发布于 2026/11/05TypeScriptES Module零依赖构建来源已验证近 30 天下载 2.2万

The payments buyer journeys, as Gherkin a host runs against its own app

原始使用文档
文档目录8 节
  1. Why a port at all
  2. Wiring it up
  3. Three things that fail SILENTLY if you get them wrong
  4. What open must leave on screen
  5. PaymentsStore — the shapes a scenario asks for
  6. Why this package ships compiled JavaScript
  7. The platform-operations journeys (opt-in)
  8. Writing your own specs in the same vocabulary

@12-apps/payments-e2e

The buyer journeys for the payments checkout, as Gherkin you run against your own app.

Mounting createPaymentFlows gives you a checkout. This gives you its end-to-end coverage: thirty-six scenarios across thirteen features — PIX, card, digital wallets, hosted hand-off and return, provider failover, issuer declines, an unresolved charge, a store that cannot charge at all, per-provider screens, saving a card outside checkout, activating a provider with a verification charge, a dead OAuth grant and its reconnection, and a setup guide that speaks in the host platform's name. A further five scenarios in two features cover the platform-operations surface, behind their own opt-in port (below) — forty-one in all. You implement one port and add three lines of config. Nothing is copied, so a scenario added here later runs in your app on the next version bump.

Why a port at all

The scenarios are portable because every assertion in them reads a test id the payments components themselves render — card-number, list-option-CARD, pix-code, payment-paid mean the same thing in every consumer.

What is not portable is everything around them: how your app routes to a checkout, how a merchant of a given shape comes to exist, and where you record what crossed the wire. That, and only that, is PaymentsWorld.

Wiring it up

1. Implement the port, in a module inside your own steps glob:

// tests/e2e/steps/payments-world.ts
import { definePaymentsWorld } from '@12-apps/payments-e2e';

definePaymentsWorld({
  // Put the browser on a checkout for a store of this shape.
  open: async (page, store) => { /* route + seed however you do */ },
  raiseHostedPayable: async (page) => { /* …and wait for the interstitial */ },
  returnFromProvider: async (page) => { /* a real return trip */ },
  hostedReturnStatus: (page) => page.getByTestId('…'),
  authorizeOAuth: async (page) => { /* play the provider's consent screen */ },
  fixtures: { headProvider, tailProvider, hostedUrlFragment, payableRef, taxId, platformBrand, oauthProvider },
  wire: {
    paths, chargeKeys, chargeBody, tokensByProvider, providerCharges, providerChargeCount, navigated,
    connectionStatus, connectionEnabled, rotation, heartbeat /* optional */,
  },
});

It must live in the steps glob because playwright-bdd imports every step file before the first Given runs — that is what registers the world in every worker.

2. Point your bdd config at the package:

import { paymentsFeatures, paymentsFeaturesRoot, paymentsSteps } from '@12-apps/payments-e2e';

const journeys = defineBddConfig({
  features: [paymentsFeatures, 'tests/e2e/features/**/*.feature'],
  featuresRoot: paymentsFeaturesRoot,
  steps: [paymentsSteps, 'tests/e2e/steps/**/*.ts'],
  outputDir: '.features-gen',
});

Keep your own steps glob in the list — that is where your definePaymentsWorld call lives.

Three things that fail SILENTLY if you get them wrong

These are not style notes. Each one produces a green run with zero journeys, which is worse than a red one.

  • Use the exported globs, not hand-written node_modules/… paths. pnpm's store is nested and a workspace link is not a directory you can guess. A glob that matches nothing makes bddgen compile what it found — nothing — and the run passes.
  • Set featuresRoot. bddgen mirrors each feature's path relative to it. Left unset, specs compile to .features-gen/node_modules/@12-apps/payments-e2e/…, and Playwright's default testIgnore drops every path containing node_modules. Seven features compiled, zero collected, green.
  • Assert your journey count. Whatever the mechanism, put a check somewhere that the number of scenarios you expect actually ran.

What open must leave on screen

For a checkout shape, open returns with the buyer on the ONE payment list (payment-list, from paymentList), the store's checkout config already resolved, and no CPF on file: the packaged steps type the CPF at the top of Pagamento (list-buyer-taxId) when the list asks for one, choose a row (list-option-<METHOD>-radio) and press the bar (list-pay). Every purchase goes through that list (FUT-4028), so it is the screen the journeys prove.

Four things about the list a host has to provide for:

  • Every store with the Pix bank flow (pixBank) copies the code as it is generated and lands on the after-copy face. On a computer that face no longer draws the code, so the step that checks it reads the buyer's clipboard. In open, for EVERY store whose list has pixBank, grant the page clipboard-read and clipboard-write, and empty the clipboard (navigator.clipboard.writeText('')) before the checkout mounts, so a code copied earlier cannot pass for this one.
  • "Nothing was written" needs a live probe. On a store that cannot charge, the step reads wire.paths for a short window and fails on any write. It proves the probe is recording first: implement wire.heartbeat, one known read sent through the recorder your checkout uses, returning the line it records. Without it the probe must already hold a read; an empty probe is never accepted.
  • A card charge waits five seconds behind the list's charge bar before it is sent. Give the expect timeout room above that (the harness uses 15s).
  • The card row is list-option-CARD. A store whose list splits the card by funding draws list-option-CARD-CREDIT and list-option-CARD-DEBIT instead, and the card steps do not choose between those.

Which other fields a chain requires (a mobile phone, a name, an e-mail) is a fact about the store you built, so open fills them. A buyer with a CPF on file gets the payer line instead of the CPF field, so do not arrive with one. The Dados step and the Pix/Cartão tabs the steps once also drove are gone from @12-apps/payments-frontend (FUT-4028), and so are their branches here.

PaymentsStore — the shapes a scenario asks for

A scenario names a kind of merchant; you decide how to produce one. A harness declares a provider chain in-page; a real storefront seeds a tenant. The feature files do not change either way.

pix-only · card · both-methods · hosted · awaiting · settles · declined · unresolved · unavailable · no-provider · no-provider-remedy · payments-off · two-mintable · redirect-head · google-pay · apple-pay · apple-pay-unsupported · wallet · activation · screen-on-page · screen-handoff · screen-undeclared · screen-unknown · setup-guide · reconnect-required

Adding a member is a breaking change for hosts, deliberately: a scenario needing a store nobody can build is a scenario that silently never runs.

wallet (added for FUT-183/FUT-478) is one of the members that are not a checkout: open(page, 'wallet') must land the buyer on the package's manage-cards surface (screens.ManageCards from createPaymentFlows) at a store whose single provider can vault — the chain head declares the adapter vault seam, the connection runs in stub mode, and the wallet starts empty. The journey types the shared DECLINE_PAN for the refusal path, so no store flag decides the outcome; the card does. Hosts upgrading across this version must add the member to their open mapping or their world stops compiling — which is the point.

activation (added for FUT-689) is the other, and the first admin-side shape: open(page, 'activation') must land the OWNER on the settings panel of one provider that declares activationCharge, connected in stub mode and never charged — the sales switch starts locked off. The host's renderVerification slot must render the shared card form plus the activation-* test ids src/steps/activation.steps.ts documents (pay button, outcome, refund line, and the raw enable-attempt probe pair). As in wallet, the typed card decides the outcome: DECLINE_PAN is refused with a named reason, anything else pays the cent and gets it refunded.

Why this package ships compiled JavaScript

Its siblings export raw .ts through their exports map, because an application's bundler consumes them and transpiles whatever it is pointed at. These files are loaded by Node — your playwright.config.ts imports this module and bddgen imports the step files — and Node refuses to strip types from anything under node_modules (ERR_UNSUPPORTED_NODE_MODULES_TYPE_STRIPPING). Playwright's own TS transform does not rescue them either; it skips node_modules by design.

Shipping source here would produce a package that type-checks, publishes, installs, and then throws on your first test run.

The platform-operations journeys (opt-in)

The buyer journeys above run in any app that mounts the checkout. A second, separate set covers the app that operates the PLATFORM — the Connect-application consult screen and the platform homologação (ConnectApplicationPanel / PlatformHomologacao from @12-apps/payments-frontend). Most checkout consumers have no such surface, so these ship behind their own port and glob triple: nothing about them lands in paymentsFeatures or paymentsSteps, and a host that never lists them is untouched.

// tests/e2e/steps/platform-world.ts — inside your super-admin steps glob
import { definePaymentsPlatformWorld } from '@12-apps/payments-e2e';

definePaymentsPlatformWorld({
  openConnectApplication: async (page, shape) => { /* sign in + route */ },
  openHomologacao: async (page, shape) => { /* sign in + produce the shape */ },
});
import {
  paymentsPlatformFeatures,
  paymentsPlatformFeaturesRoot,
  paymentsPlatformSteps,
} from '@12-apps/payments-e2e';

defineBddConfig({
  features: [paymentsPlatformFeatures],
  featuresRoot: paymentsPlatformFeaturesRoot,
  steps: [paymentsPlatformSteps, 'tests/e2e/steps/**/*.ts'],
  outputDir: '.features-gen/platform',
});

The same three silent failures apply verbatim — use the exported globs, set featuresRoot, assert your scenario count. And openHomologacao must PRODUCE its shape, not just navigate: one scenario records an outcome, so a later unrequested opening has to clear it again.

Writing your own specs in the same vocabulary

The buyer gestures are exported too, so hand-written specs beside the journeys read the same way:

import { fillCard, payCard, reachPayment, VALID_CPF } from '@12-apps/payments-e2e';

版本与发布记录

@12-apps/payments-e2e 共发布 25 个版本,首次发布于 2026/08/08;过去 12 个月发布了 25 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
2.12.0latest2026/11/051 天前
2.11.12026/10/289 天前
2.11.02026/10/2710 天前
2.10.12026/10/2610 天前
2.10.02026/10/2610 天前
2.9.02026/10/2215 天前

关于 @12-apps/payments-e2e 的常见问题

@12-apps/payments-e2e 是什么?

The payments buyer journeys, as Gherkin a host runs against its own app

如何安装 @12-apps/payments-e2e?

在项目目录运行 npm install @12-apps/payments-e2e,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:playwright-bdd(>=8.0.0)、@playwright/test(>=1.40.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@12-apps/payments-e2e 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@12-apps/payments-e2e 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@12-apps/payments-e2e 可以商用吗?

@12-apps/payments-e2e 使用 未声明 许可。package.json 没有声明许可证。没有许可证的代码默认保留全部权利,商用前请联系作者或查看仓库中的 LICENSE 文件。以上为概括,不构成法律意见,请以许可原文为准。

@12-apps/payments-e2e 的下载量有多少?

根据 npm 官方下载统计,@12-apps/payments-e2e 在 2026/10/04 – 2026/11/02 这 30 天内被下载 22,375 次,日均约 746 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@12-apps/payments-e2e 还在维护吗?

最新版本 2.12.0 发布于 2026/11/05(1 天前);至今共发布 25 个版本,其中过去 12 个月发布了 25 个;首次发布于 2026/08/08。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。