Cypress: --spec won't find a file in the current directory

Created on 2 Aug 2018  路  13Comments  路  Source: cypress-io/cypress

Current behavior:

$ ll createOrder.spec.js                             
-rw-r--r--  1 jcol53  staff   3.5K Aug  1 16:41 createOrder.spec.js

OK the test file exists in the current dir.

$ $(npm bin)/cypress run --spec 'createOrder.spec.js'
Can't run because no spec files were found.

We searched for any files matching this glob pattern:

createOrder.spec.js

But it doesn't run the test in the file.

Desired behavior:

It runs the tests in the file specified.

Steps to reproduce:

Create a spec file in a subfolder of the main project, like etc/createOrder.

Run the spec file with the steps above.

Versions

$ $(npm bin)/cypress --version                                
Cypress package version: 3.0.3
Cypress binary version: 3.0.3
$ node --version
v8.11.3

Most helpful comment

Docs could use some improvement on that feature then.

All 13 comments

Can you run with DEBUG=cypress:* $(npm bin)/cypress run --spec 'createOrder.spec.js'

That will output a huge stream of logs that tells us what cwd is set to.

Cypress should automatically normalize all of the spec paths against cwd.

OK here's the log file:
temp.log

There is a workaround, add this to cypress.json:

"integrationFolder": ".",
  "testFiles": "**.spec.js"

The --spec flag will look for files relative to the integrationFolder, which is cypress by default, so honestly I believe your workaround is a perfect solution if you intend to keep your test files within the main project root. 馃憤

Docs could use some improvement on that feature then.

I'm running in to a similar issue where cypress is unable to locate spec files from --spec. I have a spec file in my project cypress/unit/component.spec.js and I am attempting to run it like so

$(npm bin)/cypress run --spec 'cypress/unit/*'

DEBUG gives the following output:

cypress:server:run found '0' specs using spec pattern '/Users/jdperez/Projects/react-base/app/cypress/unit/*': [] +1ms

Same thing when attempting to call the file directly:

DEBUG=cypress* $(npm bin)/cypress run --spec 'cypress/unit/component.spec.js'
cypress:server:run found '0' specs using spec pattern '/Users/jdperez/Projects/react-base/app/cypress/unit/component.spec.js': [] +0ms

I've tried a bunch of different patterns all with the same result. Any help is greatly appreciated.

@jperezlatimes Have you defined a integrationFolder within your configuration?

I'm also hitting this issue, with a twist...I can run a list of 15 spec files, but when I reduce the list to 1 or 2 then it fails to find the files...the exact same files specified in the same way except one is in a large list and the other is in a short list.

I've tried setting the integrationFolders in cypress.json:

  "integrationFolder": "cypress/integration",

Obviously I am using the default integration folder, with subfolders underneath it.

I also tried your debug suggestion but I'm working in windows and I have no clue how to get that to work. Tired many variations on it.

Here is what does work:

npm run cypress -- run --spec 'cypress/integration/CreateModels/AllEntityTypes.js,cypress/integration/CreateModels/DisqualifyingEntities.js,cypress/integration/CreateModels/WaitVsNoWaitActions.js,cypress/integration/CreateModels/WhatsYourName.js,cypress/integration/CreateModels/TagAndFrog.js,cypress/integration/CreateModels/Travel.js,cypress/integration/EditAndBranching/VerifyEditTrainingControlsAndLabels.js,cypress/integration/EditAndBranching/Branching.js,cypress/integration/EditAndBranching/TagAndFrog.js,cypress/integration/EditAndBranching/TwoConsecutiveUserInputErrorHandling.js,cypress/integration/EditAndBranching/WaitNonWaitErrorHandling.js,**cypress/integration/Log/WhatsYourName.js,cypress/integration/Train/DisqualifyingEntities.js**,cypress/integration/Train/WaitVsNoWaitActions.js,cypress/integration/Train/WhatsYourName.js,cypress/integration/Train/MyNameIs.js,cypress/integration/Train/TagAndFrog.js'

This is what does NOT work:

npm run cypress -- run --spec 'cypress/integration/Log/WhatsYourName.js,cypress/integration/Train/DisqualifyingEntities.js'

@SDESkowronski What is the script within your package.json that maps to cypress here? Just want to make sure exactly what you're running before making a suggestion.

from pakage.json:
"cypress": "cypress",

@SDESkowronski I don't see why this would not work with 1, 2 spec files over 15. Please open a new issue with info about your environment and reproducible example as this issue has been closed.

Thanks Jennifer, while trying to create a minimum repro I tried switching the quotes I was using from single to double and the double quotes worked. I am running on Windows. Issue resolved for me, but it's weird that the single quote worked for 15 files but not 1 or 2.

OK here's the log file:
temp.log

There is a workaround, add this to cypress.json:

"integrationFolder": ".",
  "testFiles": "**.spec.js"

@jcollum @jennifer-shehane

I have tried this. cwd changed to project directory (not cypress anymore)
And still cannot find spec file.
Even cannot find from ./cypress/integration dir

So neither this works : cypress run --spec "src/app/ui-components/ui-button/__test/index.spec.js"
nor this: cypress run "cypress/integration/"

OK here's the log file:
temp.log
There is a workaround, add this to cypress.json:

"integrationFolder": ".",
  "testFiles": "**.spec.js"

@jcollum @jennifer-shehane

I have tried this. cwd changed to project directory (not cypress anymore)
And still cannot find spec file.
Even cannot find from ./cypress/integration dir

So neither this works : cypress run --spec "src/app/ui-components/ui-button/__test/index.spec.js"
nor this: cypress run "cypress/integration/"

Ok I solved this by removing "testFiles": "**.spec.js"
Or even if we don't specify those things in .json file, then we can use --config in command line which works fine too. cypress run --config integrationFolder=. --spec=

I hope this will be helpful to others!

Was this page helpful?
0 / 5 - 0 ratings