Course contentsShow
← React
Lesson 2173 of 2,39648. End-to-End TestingFree lesson

Cypress Setup and Project Structure

Installing Cypress, understanding the folder structure (integration, fixtures, support), and configuring cypress.json.

Cypress Setup and Project Structure

What you'll learn: How to install Cypress, navigate its opinionated folder structure, and configure the essential cypress.json file.

Installing Cypress

Cypress is an alternative E2E testing framework to Playwright (which you just learned). Installing it is straightforward:

npm install --save-dev cypress

Then open Cypress for the first time:

npx cypress open

This command creates the entire folder structure automatically—think of it as Cypress "unpacking" itself into your project.

Understanding the Folder Structure

Cypress creates several key directories:

  • cypress/integration/ (or cypress/e2e/ in v10+): This is where your test files live. Each .spec.js file is a suite of tests. Think of this as the "test scripts library."

  • cypress/fixtures/: JSON files containing mock data you'll reuse across tests. It's like a "fake database" for predictable test scenarios—similar to MSW handlers, but file-based.

  • cypress/support/: Contains global configuration and custom commands. The commands.js file lets you create reusable actions (like cy.login()), while index.js runs before every test file.

Configuring cypress.json

The cypress.json file (root of your project) controls Cypress behavior:

{
  "baseUrl": "http://localhost:3000",
  "viewportWidth": 1280,
  "viewportHeight": 720,
  "video": false
}

Setting baseUrl means you can write cy.visit('/dashboard') instead of full URLs. Viewport settings ensure consistent test conditions across machines.

Key Takeaway: Cypress auto-generates an opinionated folder structure on first run—integration holds tests, fixtures stores mock data, support contains helpers, and cypress.json configures global test behavior.