-1

I just installed Cypress and was test running it.

Running npm run cy-run will run all test files which takes quite a lot of time and can become confusing.

Note that I have not added a single test of mine. The tests are the default examples coming from Cypress installation.

When attempting to limit to a single file I found several sources - including this question - that all seem to agree that the following would limit the run to just one single file:

npm run cy-run --spec cypress/integration/2-advanced-examples/viewport.spec.js 

But Cypress does not care and goes on to pick up all tests and run them:

enter image description here

jonrsharpe
  • 115,751
  • 26
  • 228
  • 437
BernardA
  • 1,391
  • 19
  • 48
  • Look at how Cypress is actually being called. You're missing `--`, this is general NPM usage not specific to this. – jonrsharpe Apr 18 '22 at 08:35
  • Hmm, not sure where the `--` is coming from but it works. Please post a proper answer with explanation and I will accept it. – BernardA Apr 18 '22 at 09:09
  • Does this answer your question? [Sending command line arguments to npm script](https://stackoverflow.com/questions/11580961/sending-command-line-arguments-to-npm-script) – jonrsharpe Apr 18 '22 at 09:13
  • I am still confused, but at a much higher level:) – BernardA Apr 18 '22 at 09:17

1 Answers1

0

Instead of trying to run this from the command line, rather just - while writing and running your tests - prefix the only chain to it.

Example, change this:

it("should do stuff", () => ...);

to this:

it.only("should do stuff", () => ...);

You can add this to describe.only as well if you want to run a whole suite - or in your case, file - alone.

Another Option:

If you'd like to only run tests that you've written, you can either just remove all those example files or change describe to xdescribe or it to xit and cypress will skip running those specified tests.

Command Line Solution:

You're missing --, add that in and it should work as per your solution.

It should be written like this:

npm run cy-run -- --spec cypress/integration/2-advanced-examples/viewport.spec.js
Barry Michael Doyle
  • 9,333
  • 30
  • 83
  • 143