Verify Cypress installation via npm
Preconditions (2)
✅ Expected Result: Cypress is installed successfully without errors, 'node_modules/cypress' folder exists, and package.json lists Cypress as a dependency
import { expect } from 'chai'; import fs from 'fs'; import path from 'path'; describe('Cypress installation verification', () => { const projectDir = process.cwd(); const nodeModulesCypressPath = path.join(projectDir, 'node_modules', 'cypress'); const packageJsonPath = path.join(projectDir, 'package.json'); it('should have cypress folder inside node_modules', () => { const exists = fs.existsSync(nodeModulesCypressPath); expect(exists).to.be.true; }); it('should list cypress as a dependency in package.json', () => { const packageJsonRaw = fs.readFileSync(packageJsonPath, 'utf-8'); const packageJson = JSON.parse(packageJsonRaw); const dependencies = packageJson.dependencies || {}; expect(dependencies).to.have.property('cypress'); }); });
This test suite checks if Cypress is installed correctly after running npm install cypress.
First, it uses Node.js fs.existsSync to check if the node_modules/cypress folder exists, which means Cypress files are present.
Second, it reads package.json and parses it as JSON to verify that Cypress is listed under dependencies. This confirms npm recorded Cypress as a project dependency.
We use chai assertions for clear pass/fail results. The tests run in the current working directory, assuming the commands were run there.
Now add data-driven testing to verify installation in three different project folders
--save-dev flag installs the package as a development dependency, which is correct for Cypress.npm install cypress --save-dev?package.json.npm install cypress --save-dev, what command do you use to open the Cypress Test Runner?npx cypress open.npm install cypress --save-dev but get an error saying command not found: cypress when typing cypress open. What is the likely fix?cypress open fails.npx cypress open runs the local Cypress binary correctly.npm install cypress --save-dev to add Cypress only for development.npx cypress open to run Cypress without global install.Pass the test and this pattern moves unknown