Open delucca opened 5 years ago
cypress run
does not watch for file changes. It's meant to run the tests once, then exit with a proper exit code.
If you want to watch for file changes, you should use cypress open
https://docs.cypress.io/guides/core-concepts/writing-and-organizing-tests.html#Watching-tests
is there a reason cypress run
can't watch for file changes too? I'd love to have automated tests in a terminal, without having to click things
@towc It's not on our roadmap to include file watching during cypress run
. A large part of our current Test Runner product is encouraging use of using Cypress as a way to test drive development of web applications in a browser, where seeing the web application is essential to development.
I would also love the ability to run tests in watch mode on a terminal.
While I appreciate that seeing the tests running in a browser is a key feature in general, for some of us the main value of an automated test suite is precisely to reduce the human/manual factor and not needing to inspect your browser while developing
For those who come to this and want to be able to re-run Cypress on file change, you can use nodemon
to do this:
$ npm install -g nodemon
In your package.json
:
"scripts": {
"cypress": "nodemon -e js,jsx,ts,tsx,css,scss --exec cypress run"
}
Change the extensions after -e
to suit your needs.
Unfortunately nodemon is only a workaround with the side effect of every run terribly slow. I wish cypress had similar watch-ability and test rerun-ability as Jest runner.
Why use nodemon as a workaround when you can just use cypress open? the workaround is already there. although it seems like this behavior is intended anyway. cypress run is a perfect solution for me since I don't want to change anyone else's settings, and I don't want tests to rerun.
Because the requirement is to run in headless mode re-running the tests on file changes - the same way Jest does it.
Now, we cannot use Jest because it does not run an actual browser and relies on jsdom
to mimick DOM environment. Cypress fits the bill because it runs tests on actual browser and I can point it to an older chromium
binary, which is great.
Today I am exploring Cypress as a first-time user to understand if it is useable for our use cases and whether it has good DX (developer experience).
Documentation did not mention any way to watch for file changes and re-run the tests automatically in CLI environment (no X Windows System), hence I googled and ended up on this thread.
I see no reason to enforce or depend on Cypress Open UI app to watch for test file changes if the same can be done via CLI tools. If this type of feature is not on your roadmap yet - that's fine, but I am sure there are many people who would be happy to have this capability.
I would love to have this feature as well; some times I just wish to test without having a browser running (like some API or random Unit Tests), would definitely encourage TDD.
For now, emulating using watch
command (for tests inside cypress/integration
folder):
$ while true; do watch -g ls -l cypress/integration > /dev/null && npx cypress run; sleep 3; done;
Please look - https://github.com/cypress-io/cypress/issues/22410
nodemon
My cypress code is keep looping --> start of the tests I created test data which is saved in the fixtures folder. As cypress detected there is a file change and re-run the tests. How to resolve this issue - ref: https://github.com/cypress-io/cypress/issues/22410
you can just use cypress open
this is not always easily possible, for example when running Cypress in a container and/or in WSL.
cypress run
works pretty nicely otherwise, the user can connect from a local browser to the Chrome remote debugging port and see the tests in action, without having to install anything on the host machine.
so for now it's still not possible to watch files changes from the terminal, is it right? I mean, we don't have this option as part of cypresse imlementation.
https://github.com/cypress-io/cypress-watch-preprocessor this used to work?
To add another reason to do this, Cypress open's ability to take screenshots is broken:
https://github.com/cypress-io/cypress/issues/3324
No two runs in Cypress open give the same screenshots for me, while Cypress run does seem to be repeatable (as far as I've seen).
Also, I want to make changes that should not change the visuals. I don't want to look at them unless something has gone wrong; the UI is very distracting at times.
This would be a nice feature to have, I don't want to keep switching to a browser to see if any of my tests fail, I want a little terminal sitting there in the corner of the screen with cypress doing its thing and showing me a little red will be enough to know I broke something — cypress open
just doesn't cut it.
Another up vote for this feature. We have all our cypress tests mocked through cy.intercept and having a watcher on the test suite that runs in the terminal is ideal for our devs to be able to make changes and get immediate feedback if they've broken a test.
+1 for having this. I'm actually pretty shocked that this standard feature isn't included at this point.
Current behavior:
The command
cypress run
is not watching for file changes. Even if I set it on the cypress.json. If I run only successful tests, I got the following output on terminal:Then, it exits
If any of the tests fails, I got the following:
Desired behavior:
It should be waiting for file changes and re run all tests if there is any change
Steps to reproduce: (app code and test code)
Just run
cypress run
Versions
Cypress version: 3.1.5