Cypress

From TerminalSkills/skills · View interactive version

Cypress is an AI agent skill from the GitHub repository TerminalSkills/skills. Assists with end-to-end testing of web applications using Cypress. Use when writing E2E tests, setting up component testing, configuring CI pipelines with parallelization, or building custom test commands. Trigger words: cypress, e2e testing, end-to-end, cypress run, cy.get, integration testing, bro

How to use this skill

Skill file

Cypress

Overview

Cypress is an end-to-end testing framework for web applications that runs tests directly in the browser for fast, reliable feedback. It provides element selection, network interception, component testing, and CI integration with parallelization and video recording. This skill targets Cypress 16 (16.2.0 at the time of writing); notes mark what changed from 13-15.

Instructions

Install and configure

npm install --save-dev cypress
npx cypress open      # first run: pick E2E or Component Testing, the launchpad creates the files
// cypress.config.ts
import { defineConfig } from 'cypress'

export default defineConfig({
  e2e: {
    baseUrl: 'http://localhost:3000',
    specPattern: 'cypress/e2e/**/*.cy.{js,ts}',
    setupNodeEvents(on, config) {
      on('task', {
        // runs in Node: use it for DB seeding instead of cy.exec (removed in 16)
        'db:seed': (name: string) => seedDatabase(name),
      })
      return config
    },
  },
  expose: { apiVersion: 'v2' }, // public values, read with Cypress.expose('apiVersion')
  video: false,                 // default; set true to record cypress run videos
})

Write tests

Component testing

Cypress ships its own mount adapters, so you do not install @cypress/react or @cypress/vue separately (@cypress/react18 is deprecated). React 18/19 with Vite 8+, Webpack or Next.js 15.0.4+ is supported (Vite 5-7 and Next.js 14 were dropped in 16).

// cypress/support/component.ts
import { mount } from 'cypress/react'
import './commands'

declare global {
  namespace Cypress {
    interface Chainable { mount: typeof mount }
  }
}
Cypress.Commands.add('mount', mount)
// cypress.config.ts (component part)
component: { devServer: { framework: 'react', bundler: 'vite' } },

For Vue import mount from cypress/vue; for Angular import it from cypress/angular, which needs Angular 21+ in Cypress 16.

CI

npx cypress run --browser chrome                      # headless, all specs
npx cypress run --component                           # component specs
npx cypress run --record --key "$CYPRESS_RECORD_KEY" --parallel --ci-build-id "$GITHUB_RUN_ID"

--record, --parallel and --ci-build-id need a Cypress Cloud project; without Cloud, split specs across jobs with --spec. Use the official cypress-io/github-action on GitHub Actions to install, cache the binary and start the server.

Examples

Example 1: Write E2E tests for a checkout flow

User request: "Add Cypress tests for our e-commerce checkout process"

// cypress/e2e/checkout.cy.ts
describe('checkout', () => {
  beforeEach(() => {
    cy.intercept('POST', '/api/cart', { statusCode: 201, fixture: 'cart.json' }).as('addToCart')
    cy.intercept('POST', '/api/orders', { statusCode: 201, body: { id: 'ord_1042' } }).as('placeOrder')
    cy.visit('/products/trail-runner-2')
  })

  it('places an order and shows the confirmation', () => {
    cy.get("[data-cy='add-to-cart']").click()
    cy.wait('@addToCart')
    cy.visit('/checkout')
    cy.get("[data-cy='email']").type('maria.lopez@shop-demo.net')
    cy.get("[data-cy='address']").type('18 Harbor Street, Portland')
    cy.get("[data-cy='place-order']").click()
    cy.wait('@placeOrder').its('request.body').should('have.property', 'email')
    cy.url().should('include', '/confirmation/ord_1042')
    cy.contains('Thank you for your order').should('be.visible')
  })
})

Result: npx cypress run --spec cypress/e2e/checkout.cy.ts prints one passing test; a failure writes a screenshot to cypress/screenshots/.

Example 2: Set up component testing for React

User request: "Configure Cypress component testing for our React project"

Actions: run npx cypress open, choose Component Testing (Vite is detected), accept the generated cypress/support/component.ts, then write a spec next to the component.

// src/components/Counter.cy.tsx
import Counter from './Counter'

it('increments on click', () => {
  cy.mount(<Counter initial={2} />)
  cy.get("[data-cy='increment']").click()
  cy.get("[data-cy='value']").should('have.text', '3')
})

Result: npx cypress run --component runs the spec in a real browser, mounting only the component.

Guidelines

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.