Registry / testing / cypress

cypress

JSON →
library15.14.0jsnpmunverified

Cypress is a comprehensive front-end testing framework designed for the modern web, enabling end-to-end, integration, and component testing. Unlike traditional WebDriver-based solutions, Cypress executes tests directly within the browser, providing a unique interactive experience with real-time command logs, time-travel debugging, and automatic reloads. Its architecture allows for direct manipulation of the browser, network requests, and DOM, leading to more reliable and faster tests. The current stable version is 15.14.0. Cypress maintains a relatively fast release cadence, with minor versions often released every few weeks to introduce new features, bug fixes, and performance improvements, while major versions (e.g., v10, v12) introduce more significant breaking changes and architectural shifts. Key differentiators include its bundled nature (no external WebDriver), interactive test runner, built-in assertion library (Chai), and powerful mocking capabilities for network requests.

npm install cypress
INSTALL
IMPORT
SIG · CYPRESS
C
cypress
testingjavascriptv15.14.0
Install
—
Import
—
Disk
—
Pass rate
0/ 6
Env Coverage0 / 6
glibc
18–22
musl
18–22
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18–226 runs
build_error
glibc
node 18–226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

cy
✓ /// <reference types="cypress" /> // OR add "cypress" to types array in tsconfig.json // cy is a global object provided by Cypress runtime
✗ import { cy } from 'cypress';
`cy` is a global object injected by the Cypress test runner into the browser context. It is not typically imported as a module. For TypeScript, add `cypress` to your `tsconfig.json`'s `types` array or use a triple-slash directive.
Cypress
✓ /// <reference types="cypress" /> // OR add "cypress" to types array in tsconfig.json // Cypress is a global object provided by Cypress runtime
✗ import { Cypress } from 'cypress';
Similar to `cy`, the `Cypress` global object provides configuration, utility functions, and access to other Cypress APIs. It's also globally available in the test runner context.
mount
✓ import { mount } from '@cypress/react'; // or '@cypress/vue', etc.
✗ import { mount } from 'cypress';
`mount` is used for component testing and is provided by specific framework adaptors (e.g., `@cypress/react`, `@cypress/vue`), not directly from the main `cypress` package. Ensure you install the correct adaptor package.

Demonstrates a basic end-to-end test verifying page title, interacting with DOM elements, asserting their state, and mocking an API request using `cy.intercept`.

import { mount } from '@cypress/react'; // Only needed for component tests, remove for e2e describe('My First Cypress Test', () => { beforeEach(() => { // Ensure the server is running or mock API calls as needed cy.visit('http://localhost:3000'); // Replace with your application's URL }); it('should display the correct title and allow user interaction', () => { cy.title().should('include', 'My App'); cy.get('.todo-input').type('Learn Cypress{enter}'); cy.get('.todo-list li').should('have.length', 1).and('contain', 'Learn Cypress'); cy.get('.todo-list li:first-child .toggle').click(); cy.get('.todo-list li:first-child').should('have.class', 'completed'); cy.contains('Clear completed').click(); cy.get('.todo-list li').should('not.exist'); }); it('should handle API requests (example with intercept)', () => { cy.intercept('GET', '/api/todos', { fixture: 'todos.json' }).as('getTodos'); cy.visit('http://localhost:3000/todos'); cy.wait('@getTodos').its('response.statusCode').should('eq', 200); cy.get('.todo-item').should('have.length', 2); // Assuming todos.json has 2 items }); });
cypress --version
Debug
Known issues
breakingCypress v10 introduced a significant refactor, moving configuration from `cypress.json` to `cypress.config.js` or `cypress.config.ts` and changing how project structure and component testing are set up. `plugins/index.js` was also deprecated in favor of direct config file callbacks.
fix
Migrate your `cypress.json` and `plugins/index.js` to the new `cypress.config.js|ts` format. Refer to the official migration guide for detailed steps. Component testing now requires specific adaptors like `@cypress/react` or `@cypress/vue` configured in `cypress.config.ts`.
affects: >=10.0.0
breakingCypress v12 deprecated support for Node.js 14. Additionally, `cy.origin()` became the recommended approach for testing multi-origin workflows, replacing older workarounds for cross-domain interactions.
fix
Upgrade your Node.js version to 16 or higher (Cypress recommends >=20). For cross-origin testing, refactor tests to use `cy.origin()` for navigating and interacting with different domains within a single test.
affects: >=12.0.0
deprecatedThe `cy.server()` and `cy.route()` commands for network mocking have been deprecated in favor of `cy.intercept()`. `cy.intercept()` offers more powerful, flexible, and reliable control over network requests.
fix
Replace all instances of `cy.server()` and `cy.route()` with `cy.intercept()`. `cy.intercept()` allows for more granular control over request matching, response modification, and better handling of modern fetch APIs and service workers.
affects: >=6.0.0
gotchaCypress commands are asynchronous and chainable, but they do not return promises or resolve immediately. Attempting to mix Cypress commands with standard synchronous JavaScript or native async/await without careful handling can lead to unexpected behavior or tests failing due to race conditions.
fix
Always chain Cypress commands (`.then()`, `.should()`, `.wait()`). Use `.then()` to wrap non-Cypress specific logic or interact with the results of a previous command. Avoid using `async/await` directly with Cypress commands; instead, use `cy.then(async () => { await somePromise(); })` for promises that don't involve Cypress DOM interactions.
affects: >=3.0.0
gotchaCypress commands like `cy.get()` will retry until an element is found or assertions pass within a default timeout. However, an element must be 'actionable' (visible, not disabled, not covered) before interaction commands like `click()` or `type()` will succeed.
fix
Ensure that elements are in an actionable state before interacting with them. Cypress automatically retries for actionability, but if an element remains hidden or disabled, you might need to add explicit assertions like `.should('be.visible')` or `.should('not.be.disabled')` to debug or wait for specific states, or trigger necessary UI actions.
affects: >=3.0.0
Errors
Common errors & fixes
ReferenceError: cy is not defined
The Cypress global types are not correctly loaded in your TypeScript configuration or JavaScript file.
fix
For TypeScript, add `"cypress"` to the `types` array in your `tsconfig.json` (e.g., `"types": ["node", "cypress"]`). For JavaScript, ensure your editor/IDE is configured to recognize globals from Cypress or use a JSDoc `/// <reference types="cypress" />` directive in your test files.
Cypress command timeout of 4000ms exceeded.
A Cypress command (e.g., `cy.get()`, `cy.wait()`, `cy.visit()`) or an assertion took longer than the default timeout to complete or pass.
fix
Investigate why the command is slow. It could be a slow network request, a complex DOM query, or an element that takes time to appear/become interactive. Increase the timeout for specific commands (e.g., `cy.get('.slow-element', { timeout: 10000 })`) or globally in `cypress.config.ts` (e.g., `defaultCommandTimeout: 10000`).
Cypress exited with code 1
This is a generic exit code indicating a test run failure. It usually means one or more tests failed, or there was a configuration error that prevented tests from running.
fix
Examine the Cypress test runner output or CI logs for detailed error messages. Look for failing assertions, unhandled exceptions, or configuration errors printed to the console. The exact cause is usually logged immediately before this exit code.
Cypress commands can only be chained off of `cy`.
Attempting to call a Cypress command (e.g., `get`, `visit`) directly without chaining it from the `cy` object, or trying to chain it from a non-Cypress object.
fix
Ensure all Cypress commands start with `cy.` (e.g., `cy.get('.element')` instead of `get('.element')`). If you're using a result from a previous command, chain it correctly using `.then()`.
Upgrade
Version history
15.14.0latest on npm
Audit
Dependencies
@cypress/webpack-preprocessoroptionalCommonly used for processing test files (e.g., TypeScript, modern JavaScript) before execution in Cypress.
eslint-plugin-cypressoptionalProvides linting rules specific to Cypress best practices and common pitfalls, enhancing code quality in test files.
@cypress/reactoptionalRequired for component testing with React. Similar packages exist for Vue and Angular.
Agent activity
8 hits · last 30 days
node
8
Resources