🍃 Leaf

Cypress

Installation

npm i -D cypress

More at Installing Cypress (docs.cypress.io).

Usage

# Use with npx (no installation required)
npx cypress <command> [option]
# Or... use with complete path
./node_modules/.bin/cypress <command> [option]
# Or... use with shortcut
$(npm bin)/cypress <command> [option]
# Or... use with npm scripts
npm run <npm-script> -- [option]
// package.json e.g.:
{
  "scripts": {
    "cy:run": "cypress run [option]",
    "cy:open": "cypress open [option]",
    "cy:info": "cypress info [option]"
  }
}

Commands:

Options (run and open):

More at:

More at TypeScript (docs.cypress.io).

Configuration

Legacy configuration file name is cypress, version 10+ uses cypress.config. Valid configuration file extensions are js|ts|mjs|cjs|json.

// cypress.config.ts e.g.:
import { defineConfig } from 'cypress';

export default defineConfig({
  port: 8080,
  viewportHeight: 1920,
  viewportWidth: 1080,
  waitForAnimations: false,
  e2e: {
    supportFile: 'cypress/support/e2e.{ts,tsx}',
    specPattern: 'cypress/e2e/**/*.cy.{ts,tsx}
  },
  component: {
    devServer: '',
    viewportHeight: 500, // Can override global options
    viewportWidth: 500
  },
  // ...
});

More at:

Using TypeScript

1- If not already, install TypeScript:

npm i -D typescript

2- Setup a TypeScript configuration file inside the cypress folder:

// tsconfig.json e.g.:
{
  "compilerOptions": {
    "target": "es6",
    "lib": ["es6", "dom"],
    "types": ["cypress", "node"]
  },
  "include": ["**/*.ts"]
}