├── cypress.json
├── .gitignore
├── .envrc.sample
├── assets
└── cover.jpg
├── cypress
├── fixtures
│ └── example.json
├── support
│ ├── index.js
│ └── commands.js
├── plugins
│ └── index.js
├── integration
│ └── basic_spec.ts
└── server
│ └── index.js
├── tsconfig.json
├── .github
└── workflows
│ └── main.yml
├── index.d.ts
├── LICENSE
├── package.json
├── src
└── index.ts
├── README.md
└── yarn.lock
/cypress.json:
--------------------------------------------------------------------------------
1 | {
2 | "chromeWebSecurity": false
3 | }
4 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | node_modules
2 | /dist
3 | .envrc
4 | /cypress/screenshots
5 | /cypress/videos
6 |
--------------------------------------------------------------------------------
/.envrc.sample:
--------------------------------------------------------------------------------
1 | export CYPRESS_TEST_APP_PORT=4000
2 | export STRIPE_PUBLISHABLE_KEY=pk_test_...
3 |
--------------------------------------------------------------------------------
/assets/cover.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dbalatero/cypress-plugin-stripe-elements/HEAD/assets/cover.jpg
--------------------------------------------------------------------------------
/cypress/fixtures/example.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "Using fixtures to represent data",
3 | "email": "hello@cypress.io",
4 | "body": "Fixtures are a great way to mock data for responses to routes"
5 | }
--------------------------------------------------------------------------------
/tsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "include": ["./src", "index.d.ts"],
3 | "compilerOptions": {
4 | "target": "es5",
5 | "module": "commonjs",
6 | "declaration": false,
7 | "outDir": "./dist",
8 | "strict": true,
9 | "moduleResolution": "node",
10 | "types": ["cypress"],
11 | "esModuleInterop": true,
12 | "skipLibCheck": true,
13 | "forceConsistentCasingInFileNames": true
14 | },
15 | "exclude": [
16 | "dist",
17 | "node_modules"
18 | ]
19 | }
20 |
--------------------------------------------------------------------------------
/cypress/support/index.js:
--------------------------------------------------------------------------------
1 | // ***********************************************************
2 | // This example support/index.js is processed and
3 | // loaded automatically before your test files.
4 | //
5 | // This is a great place to put global configuration and
6 | // behavior that modifies Cypress.
7 | //
8 | // You can change the location of this file or turn off
9 | // automatically serving support files with the
10 | // 'supportFile' configuration option.
11 | //
12 | // You can read more here:
13 | // https://on.cypress.io/configuration
14 | // ***********************************************************
15 |
16 | // Import commands.js using ES2015 syntax:
17 | import './commands'
18 |
19 | // Alternatively you can use CommonJS syntax:
20 | // require('./commands')
21 |
--------------------------------------------------------------------------------
/cypress/plugins/index.js:
--------------------------------------------------------------------------------
1 | ///
2 | // ***********************************************************
3 | // This example plugins/index.js can be used to load plugins
4 | //
5 | // You can change the location of this file or turn off loading
6 | // the plugins file with the 'pluginsFile' configuration option.
7 | //
8 | // You can read more here:
9 | // https://on.cypress.io/plugins-guide
10 | // ***********************************************************
11 |
12 | // This function is called when a project is opened or re-opened (e.g. due to
13 | // the project's config changing)
14 |
15 | /**
16 | * @type {Cypress.PluginConfig}
17 | */
18 | module.exports = (on, config) => {
19 | // `on` is used to hook into various events Cypress emits
20 | // `config` is the resolved Cypress config
21 | }
22 |
--------------------------------------------------------------------------------
/.github/workflows/main.yml:
--------------------------------------------------------------------------------
1 | name: End-to-end tests
2 | on: [push]
3 | jobs:
4 | cypress-run:
5 | environment: ci
6 | runs-on: ubuntu-latest
7 | steps:
8 | - name: Checkout
9 | uses: actions/checkout@v1
10 |
11 | - name: Cypress run
12 | uses: cypress-io/github-action@v1
13 | with:
14 | start: yarn start
15 | wait-on: http://localhost:4000
16 | env:
17 | CYPRESS_TEST_APP_PORT: 4000
18 | STRIPE_PUBLISHABLE_KEY: ${{ secrets.STRIPE_PUBLISHABLE_KEY }}
19 | ACTIONS_ALLOW_UNSECURE_COMMANDS: true
20 |
21 | - name: Archive screenshot and video results
22 | uses: actions/upload-artifact@v2
23 | with:
24 | name: cypress-results
25 | path: |
26 | cypress/screenshots
27 | cypress/videos
28 |
--------------------------------------------------------------------------------
/index.d.ts:
--------------------------------------------------------------------------------
1 | ///
2 |
3 | // All Stripe Elements fields have a `data-elements-stable-field-name`
4 | // attribute that can be used to target it.
5 | //
6 | // This type is meant to hint you about the basic card input fields you can fill.
7 | //
8 | // In case we haven't added a stable field name to this list, you can always
9 | // fallback to passing a `string`.
10 | declare module "cypress-plugin-stripe-elements" {
11 | export type CypressStripeElementsFieldName = 'cardCvc' | 'cardNumber' | 'cardExpiry' | 'postalCode' | string;
12 | }
13 |
14 | declare namespace Cypress {
15 | interface Chainable {
16 | /**
17 | * Custom command to select DOM element by data-cy attribute.
18 | * @example cy.dataCy('greeting')
19 | */
20 | fillElementsInput(field: CypressStripeElementsFieldName, value: string): Chainable
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/cypress/support/commands.js:
--------------------------------------------------------------------------------
1 | // ***********************************************
2 | // This example commands.js shows you how to
3 | // create various custom commands and overwrite
4 | // existing commands.
5 | //
6 | // For more comprehensive examples of custom
7 | // commands please read more here:
8 | // https://on.cypress.io/custom-commands
9 | // ***********************************************
10 | //
11 | //
12 | // -- This is a parent command --
13 | // Cypress.Commands.add("login", (email, password) => { ... })
14 | //
15 | //
16 | // -- This is a child command --
17 | // Cypress.Commands.add("drag", { prevSubject: 'element'}, (subject, options) => { ... })
18 | //
19 | //
20 | // -- This is a dual command --
21 | // Cypress.Commands.add("dismiss", { prevSubject: 'optional'}, (subject, options) => { ... })
22 | //
23 | //
24 | // -- This will overwrite an existing command --
25 | // Cypress.Commands.overwrite("visit", (originalFn, url, options) => { ... })
26 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Copyright 2020 David Balatero
2 |
3 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4 |
5 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6 |
7 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
8 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "cypress-plugin-stripe-elements",
3 | "version": "1.0.2",
4 | "description": "Adds testing helpers for driving Stripe Elements with Cypress.",
5 | "main": "dist/index.js",
6 | "types": [
7 | "index.d.ts"
8 | ],
9 | "files": [
10 | "dist",
11 | "index.d.ts"
12 | ],
13 | "repository": "https://github.com/dbalatero/cypress-plugin-stripe-elements",
14 | "author": "David Balatero",
15 | "license": "MIT",
16 | "keywords": [
17 | "cypress",
18 | "stripe",
19 | "elements",
20 | "testing",
21 | "payments"
22 | ],
23 | "devDependencies": {
24 | "cypress": "^8.4.1",
25 | "express": "^4.17.1",
26 | "start-server-and-test": "^1.14.0",
27 | "typescript": "^4.4.3"
28 | },
29 | "scripts": {
30 | "build": "tsc",
31 | "cy:run": "cypress run --browser chrome --headless",
32 | "prepublishOnly": "yarn build && yarn test",
33 | "start": "node cypress/server/index.js",
34 | "test": "start-server-and-test start http://localhost:$CYPRESS_TEST_APP_PORT cy:run"
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/src/index.ts:
--------------------------------------------------------------------------------
1 | import { CypressStripeElementsFieldName } from 'cypress-plugin-stripe-elements';
2 |
3 | const getSelectorForField = (name: CypressStripeElementsFieldName): string => {
4 | return `input[data-elements-stable-field-name="${name}"]`;
5 | }
6 |
7 | Cypress.Commands.add('fillElementsInput', (field: CypressStripeElementsFieldName, value: string): void => {
8 | if (Cypress.config('chromeWebSecurity')) {
9 | throw new Error(
10 | "You must set `{ \"chromeWebSecurity\": false }` in `cypress.json`, " +
11 | "or cypress-plugin-stripe-elements cannot access the Stripe Elements " +
12 | "