Cypress: "--spec" option does not run a single spec but runs all specs in ./integrations directory

Created on 24 Jan 2018  ·  26Comments  ·  Source: cypress-io/cypress

Current behavior:

Runs all tests in ./integration/ directory

Desired behavior:

Run single test when using --spec for cypress run command

How to reproduce:

run cypress run --spec cypress/integration/**/*_spec.js

Additional Info (images, stack traces, etc)

screen shot 2018-01-24 at 5 41 34 pm

  • Operating System: Mac OS X
  • Cypress Version: 1.4.1
  • Browser Version: Chrome 63, Electron 53
cli unexpected behavior

Most helpful comment

The code for this is done, but this has yet to be released. We'll update this issue and reference the changelog when it's released.

All 26 comments

The --spec flag does not accept a glob, you currently need to specify the exact path to the 1 spec file you wish to run. Since cypress/integration/**/*_spec.js does not match an exact file name, it will run all of your files.

We could probably throw an error here, to let you know that your spec argument did not match any files before proceeding to just run all of the specs. @bahmutov ?

Keep your eye on this issue where we do intend to support glob arguments to the --spec flag: https://github.com/cypress-io/cypress/issues/416

I think we should throw - when the user specifies single spec with --spec and we cannot find it something is wrong.

Sent from my iPhone

On Jan 25, 2018, at 10:29, Jennifer Shehane notifications@github.com wrote:

The --spec flag does not accept a glob, you currently need to specify the exact path to the 1 spec file you wish to run. Since cypress/integration/*/_spec.js does not match an exact file name, it will run all of your files.

We could probably throw an error here, to let you know that your spec argument did not match any files before proceeding to just run all of the specs. @bahmutov ?

Keep your eye on this issue where we do intend to support glob arguments to the --spec flag: #416


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or mute the thread.

@jennifer-shehane @bahmutov this issue is no longer reproducible. --spec runs a single spec whereas excluding that option runs all tests in directory.

@willischu K, thanks for the update, I'm going to leave this issue open for the purpose of delivering this feature:

  • throw an error in cli if --spec argument did not match any files before proceeding to just run all of the specs

The code for this is done, but this has yet to be released. We'll update this issue and reference the changelog when it's released.

I'm still having trouble here, on Windows. Most likely, it's my learning curve in using Node on Windows!
>npx cypress run --spec 'cypress/integration/rainForest022.js' returns the following error:

Can't run because no spec files were found.

We searched for any files matching this glob pattern:

'cypress\integration\rainForest022.js'

I've also tried the full path names, and about every other combo of paths, to no avail. Possibly any help?

Sorry, I know this isn't StackOverflow... but thought I'd share my solution (indeed, it was me not knowing how to use Windows. I'm sure it's even simpler than this too!):
> .\node_modules\.bin\cypress run --spec C:/Users/metheuser/Desktop/dev/test/cypress/integration/myspec.js

@AaronRohrbacher Cypress should be looking for spec files relative to the integrationFolder defined in your project. It looks as if it is searching in the root though, if this worked for you. This is not intended behavior.

Thanks @jennifer-shehane . I'm using the default integration folder, haven't found a solution easier than above thus far.

I'm looking at the example for the spec parameter, which is cypress run --spec 'cypress/integration/examples/actions.spec.js'. From the root of my project, I'm running npm run cypress:run --spec 'cypress/integration/find-trip-desktop.spec.js', and it's still running all tests in the integration folder. My directory setup is:

     |_ cypress
           |_ integration
                     |_ find-trip-desktop.spec.js
                     |_ find-trip-mobile.spec.js                   
     |_ cypress.json

Cypress version is 3.1.0
Node version is 10.5.0
Npm version is 6.1.0

It is “npm run cypress:run — —spec ...” syntax to pass arguments to npm script

Sent from my iPhone

On Aug 23, 2018, at 18:10, Angela Riggs notifications@github.com wrote:

I'm looking at the example for the spec parameter, which is cypress run --spec 'cypress/integration/examples/actions.spec.js'. From the root of my project, I'm running npm run cypress:run --spec 'cypress/integration/find-trip-desktop.spec.js', and it's still running all tests in the integration folder. My directory setup is:

project
|_ cypress
|_ integration
|_ find-trip-desktop.spec.js
|_ find-trip-mobile.spec.js
|_ cypress.json
Cypress version is 3.1.0
Node version is 10.5.0
Npm version is 6.1.0


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or mute the thread.

@bahmutov Aha! Thank you so much!

For what it's worth, I had been so focused on "it has to be something about Windows," that I didn't realize I had been ignoring my package.json file in the repo. As soon as Cypress was installed correctly, npx cypress run --spec ... worked perfectly!

I am trying to run one script headed so it shows the browser ... instead after running my script(headless!) it continues with running the rest of scripts in the folder

running one script

I am trying to run one script headed so it shows the browser ... instead after running my script(headless!) it continues with running the rest of scripts in the folder

@nadim1975

It is “npm run cypress:run -- --spec ...” syntax to pass arguments to npm script

@willischu
I tried

npm run cypress:run -- --spec cypress/integration/sample_spec.js --headed 

And still get the same behavior

Browser: Electron 59(headless)
Specs: 20 Found

This should be simple and if I am going to strugle with simple command then it is better to drop cypress all together :(

@nadim1975 i ran the exact command you posted but using one of my specs and it ran a single spec, like expected.

screen shot 2018-11-20 at 10 20 45 am

Maybe you have no other specs under the integration folder?
Copy the same spec and give it a different name under the same location then run and see if it execute 2 specs.
Thanks for trying to help.

@nadim1975 executed 2 specs separately. i have 8 specs in the order_workflow folder

screen shot 2018-11-20 at 10 45 36 am
screen shot 2018-11-20 at 10 45 42 am

I dont know what I'm doing wrong 🤔
Can you please post the entire comman you are running ?
Thanks

@nadim1975 npm run cypress:run --headed -- --spec 'cypress/integration/provider_portal/order_workflow/legal_guardian_spec.js'

this thing is driving me crazy ... they should be some setup missing ... I copy paste your exact command and just changed the file name and path and it still running all spec files :(

image

@nadim1975 well it looks like the '--spec' argument isn't even being passed when you run that full command. i'm not sure if it's a Windows thing but on my terminal, the output i get after running that command is cypress run "--spec" "cypress/integration/*_spec.js"

@willischu
Finally it worked ...thank you so much for your help. the problem was running the command from Windows powerShell , instead I used Windows CMD and it worked !

One more challenge: when I run --headed I still don't see any browser launched , I thought with --headed it will run the script on the browser and I can actually see what it does.

after it finish it generates a video recording but the video has nothing

The only way I succeed to run a single test file was using : npx cypress run --specinstead of npm run cypress:run --spec.

@ousmaneNdiaye To pass args to npm scripts, -- is required. See npm docs: https://docs.npmjs.com/cli/run-script So should be npm run cypress:run -- --spec...

Was this page helpful?
0 / 5 - 0 ratings