NPM Scripts for Cypress
- Radek Stolarczyk
- Mar 2
- 2 min read
Updated: Mar 21

Typing full Cypress CLI commands every time gets old fast.
Instead of this:
npx cypress run --spec "cypress/e2e/firstTest.cy.js"npx cypress run --spec "cypress/e2e/firstTest.cy.js" --browser firefoxCreate reusable NPM scripts once — then just run:
npm run cypress:smoke-firefoxCleaner. Faster. Better for CI.
Why Use NPM Scripts?
Avoid repeating long terminal commands
Standardize execution across the team
Simplify CI/CD pipelines
Centralize configuration in one place (package.json)
Instead of remembering flags and paths, everything lives under scripts.
Where to Add Them
Inside package.json → scripts section.
Example:
How to Run Them
Single Script
npm run cypress:smoke-firefoxor
npm run cypress:smoke-chromeSequential Execution (One After Another)
npm run cypress:smoke-firefox && npm run cypress:smoke-chromeOr use the combined script:
npm run cypress:smoke-all&& ensures the second script runs only after the first finishes successfully.
Parallel Execution
If you want both browsers running at the same time:
Linux / Mac
Use single &
npm run cypress:smoke-firefox & npm run cypress:smoke-chromeWindows
Install:
npm install npm-run-all --save-devThen run:
npx npm-run-all cypress:smoke-firefox cypress:smoke-chromeSyntax Notes
Use single quotes ' ' inside package.json commands to avoid escaping issues.
Scripts must be separated by commas.
Script names are completely custom — choose clear names like:
cypress:smoke
cypress:regression
cypress:chrome
cypress:ci
Advanced Use Cases
NPM scripts are not limited to Cypress.
They can run:
Application builds
API calls (curl)
Linting
Docker commands
Database migrations
Full test pipelines
Example CI-friendly script:
"test:ci": "npm run build && npm run cypress:smoke-chrome"Now your CI pipeline just runs:
npm run test:ciInstead of copying huge command strings into pipeline YAML.
Why This Matters in Real Projects
In larger teams:
DevOps runs one simple command
QA doesn’t remember flags
Build servers use consistent commands
Terminal mistakes are reduced
It’s a small change with big productivity impact.