2

I'm using cypress in a project of mine. I have the constraint to keeping all the tests in one single file. To run just one test now I'm editing the source code adding the keyword only to the test I want to run and the I re-run my CLI command. Is it possible to run a single test from command line picking it by name ? I'm doing that in my jest test and I'm wondering if it is possible also for cypress.

lucataglia
  • 728
  • 5
  • 18
  • Did you read e.g. https://docs.cypress.io/guides/guides/command-line#cypress-run-spec-lt-spec-gt? – jonrsharpe Nov 12 '21 at 11:22
  • Does this answer your question? [Cypress: run only one test](https://stackoverflow.com/questions/55054337/cypress-run-only-one-test) – jonrsharpe Nov 12 '21 at 11:23
  • No, I need to run a test without specify the filename. It is a corner case I need to manage. – lucataglia Nov 12 '21 at 11:24
  • I think that @lucataglia here is asking if he can run a test from a group of tests by giving the name to the CLI. IMHO it's not a bad feature, and for sure NOT a bad question! – Ale TheFe Nov 12 '21 at 11:24
  • In general it's helpful to include the context and constraints you're operating with in the question, but fundamentally the Cypress docs (CLI docs above and e.g. https://docs.cypress.io/guides/core-concepts/writing-and-organizing-tests) lay out the options available to you. – jonrsharpe Nov 12 '21 at 11:28
  • You're right, I edited the question adding more context. Thanks for your comments. – lucataglia Nov 12 '21 at 11:34
  • If the answer to my question is "no, with cypress you cant'" we should have that also as response rather that just a comment. – lucataglia Nov 12 '21 at 11:35
  • _"I have the constraint to keeping all the tests in one single file"_ - why? – jonrsharpe Nov 12 '21 at 11:39
  • Because of the deploy pipeline I have. – lucataglia Nov 12 '21 at 11:43
  • What deploy pipeline? Why does _that_ limit you in this way? I'd suggest you do a 5 whys, and [edit] to include the _last_ one. "No" isn't a useful answer, but with enough context it's possible someone could tell you how you _could_ achieve your goal. It would also help to clarify the _problem_ with `.only` (e.g. if it's because it can accidentally be left in the codebase, maybe a linting rule would solve the underlying issue?) – jonrsharpe Nov 12 '21 at 11:47

1 Answers1

3

I think you are looking for this library https://github.com/cypress-io/cypress-grep

$ npx cypress run --env grep=hello
cypress-grep: tests with "hello" in their names
Evgenii Bazhanov
  • 898
  • 1
  • 7
  • 19
  • As of today only supports up to cypress 10.0.0. Would be handy if it worked with versions after (13.x now) instead of 10 or before. – Tim Hallbeck Sep 03 '23 at 05:40