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/(orcypress/e2e/in v10+): This is where your test files live. Each.spec.jsfile 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. Thecommands.jsfile lets you create reusable actions (likecy.login()), whileindex.jsruns 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.