Reputation: 2358
I have two cypress test files, SmokeTest.spec.ts and ProfileTest.spec.ts. I want to run one file at a time in headless mode. I use the following command: npm run cy:run --headless --spec cypress/integration/SmokeTest/SmokeTest.spec.ts
Even though I'm using the --spec parameter, both test files run in headless mode.
I've also tried adding single quotes around the test file path like so: --spec 'cypress/integration/SmokeTest/SmokeTest.spec.ts'
with the same results
Why would it run both tests?
Upvotes: 1
Views: 3033
Reputation:
cy:run
is a script entry in package.json which invokes cypress run
.
{
...
"scripts": {
"cy:run": "cypress run"
To pass additional args to a script you must preceed them with --
(note there are spaces before and after the double dash).
See npm-run-script,
The special option -- is used by getopt to delimit the end of the options. npm will pass all the arguments after the -- directly to your script
You don't need to add additional scripts to package.json.
It's also noted in the Cypress docs
When calling a command using npm run, you need to pass the command’s arguments using the -- string. For example, if you have the following command defined in your package.json
{ "scripts": { "cy:run": "cypress run" } }
…and want to run tests from a single spec file and record the results on the Dashboard, the command should be:
npm run cy:run -- --record --spec "cypress/integration/my-spec.js"
Your particular command line would be
npm run cy:run -- --headless --spec cypress/integration/SmokeTest/SmokeTest.spec.ts
Upvotes: 2
Reputation: 18650
You can use the below command also to run a single spec file -
npx cypress run --spec "cypress/integration/SmokeTest/SmokeTest.spec.ts" --headless --browser chrome
Upvotes: 1
Reputation: 11951
Could you please add the below under scripts in package.json
file.
"scripts": {
"cy:smoketest-only": "cypress run --headless --spec cypress/integration/SmokeTest/SmokeTest.spec.ts --browser electron"
}
or use global patterns:
"scripts": {
"cy:smoketest-only": "cypress run --headless --spec cypress/integration/SmokeTest/**/* --browser electron"
}
and then run the below command from command prompt from the project root folder
npm run cy:smoketest-only
Upvotes: 0