Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
willischu opened this issue Jan 24, 2018 · 26 comments
Assignees
Labels
cli type: unexpected behavior User expected result, but got another

Comments

@willischu
Copy link

willischu commented Jan 24, 2018

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
@jennifer-shehane
Copy link
Member

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

@jennifer-shehane jennifer-shehane added the type: unexpected behavior User expected result, but got another label Jan 25, 2018
@bahmutov
Copy link
Contributor

bahmutov commented Jan 25, 2018 via email

@willischu
Copy link
Author

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

@jennifer-shehane
Copy link
Member

@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

@jennifer-shehane
Copy link
Member

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.

@AaronRohrbacher
Copy link

AaronRohrbacher commented Aug 8, 2018

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?

@AaronRohrbacher
Copy link

AaronRohrbacher commented Aug 8, 2018

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

@jennifer-shehane
Copy link
Member

jennifer-shehane commented Aug 8, 2018

@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.

@AaronRohrbacher
Copy link

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

@angelariggs
Copy link

angelariggs commented Aug 23, 2018

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

@bahmutov
Copy link
Contributor

bahmutov commented Aug 23, 2018 via email

@angelariggs
Copy link

@bahmutov Aha! Thank you so much!

@AaronRohrbacher
Copy link

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!

@nadim1975
Copy link

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

@willischu
Copy link
Author

willischu commented Nov 19, 2018

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

@nadim1975
Copy link

nadim1975 commented Nov 20, 2018

@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 :(

@willischu
Copy link
Author

@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

@nadim1975
Copy link

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.

@willischu
Copy link
Author

@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

@nadim1975
Copy link

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

@willischu
Copy link
Author

willischu commented Nov 20, 2018

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

@nadim1975
Copy link

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

@willischu
Copy link
Author

@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"

@nadim1975
Copy link

@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

@ousmaneNdiaye
Copy link

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

@jennifer-shehane
Copy link
Member

@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...

@cypress-io cypress-io locked as resolved and limited conversation to collaborators Apr 24, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
cli type: unexpected behavior User expected result, but got another
Projects
None yet
Development

No branches or pull requests

7 participants