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

watchForFileChanges during cypress run and rerun tests #3665

Open
delucca opened this issue Mar 7, 2019 · 15 comments
Open

watchForFileChanges during cypress run and rerun tests #3665

delucca opened this issue Mar 7, 2019 · 15 comments
Labels
E2E Issue related to end-to-end testing type: feature New feature that does not currently exist

Comments

@delucca
Copy link

delucca commented Mar 7, 2019

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:

> cypress run

===================

  (Run Starting)

  ┌───────────────────────┐
  │ Cypress:    3.1.5                                                    │
  │ Browser:    Electron 59 (headless)                        │
  │ Specs:      1 found (Loader.test.js)                        │
  └───────────────────────┘


─────────
                                                                                                    
  Running: Loader.test.js...                                                               (1 of 1) 


  BIG DESKTOPS: Loader
    ✓ It should be a fullscreen loader with a purple background (963ms)


  1 passing (1s)


  (Results)

  ┌─────────────┐
  │ Tests:        1                        │
  │ Passing:      1                      │
  │ Failing:      0                        │
  │ Pending:      0                      │
  │ Skipped:      0                      │
  │ Screenshots:  0                   │
  │ Video:        true                    │
  │ Duration:     1 second          │
  │ Spec Ran:     Loader.test.js │
  └─────────────┘


  (Video)

  - Started processing:   Compressing to 32 CRF
  - Finished processing:  /home/odelucca/Servers/yurah/v2/frontends/admin/cypress/videos/Loader.test.js.mp4 (0 seconds)


======================

  (Run Finished)


      Spec                                                Tests  Passing  Failing  Pending  Skipped 
  ┌────────────────────────────────┐
  │ ✔ Loader.test.js                            00:01        1        1        -        -        - │
  └────────────────────────────────┘
    All specs passed!                           00:01        1        1        -        -        -  

➜  admin git:(develop) ✗ 

Then, it exits

If any of the tests fails, I got the following:

> cypress run


====================

  (Run Starting)

  ┌──────────────────────────────┐
  │ Cypress:    3.1.5                                                                              │
  │ Browser:    Electron 59 (headless)                                                  │
  │ Specs:      1 found (Loader.test.js)                                                  │
  └──────────────────────────────┘


──────────────────────────────────
                                                                                                    
  Running: Loader.test.js...                                                               (1 of 1) 


  BIG DESKTOPS: Loader
    1) It should be align the loader to center horizontally and vertically


  0 passing (1s)
  1 failing

  1) BIG DESKTOPS: Loader It should be align the loader to center horizontally and vertically:

      AssertionError: expected 845 to equal 450
      + expected - actual

      -845
      +450
      
      at callback (http://localhost:3000/__cypress/runner/cypress_runner.js:54247:20)
      at getRet (http://localhost:3000/__cypress/runner/cypress_runner.js:53986:16)
      at tryCatcher (http://localhost:3000/__cypress/runner/cypress_runner.js:127195:23)
      at Function.Promise.attempt.Promise.try (http://localhost:3000/__cypress/runner/cypress_runner.js:124569:29)
      at thenFn (http://localhost:3000/__cypress/runner/cypress_runner.js:54000:26)
      at yieldItem (http://localhost:3000/__cypress/runner/cypress_runner.js:54253:16)
      at tryCatcher (http://localhost:3000/__cypress/runner/cypress_runner.js:127195:23)
      at Object.gotValue (http://localhost:3000/__cypress/runner/cypress_runner.js:126383:18)
      at Object.gotAccum (http://localhost:3000/__cypress/runner/cypress_runner.js:126372:25)
      at Object.tryCatcher (http://localhost:3000/__cypress/runner/cypress_runner.js:127195:23)
      at Promise._settlePromiseFromHandler (http://localhost:3000/__cypress/runner/cypress_runner.js:125213:31)
      at Promise._settlePromise (http://localhost:3000/__cypress/runner/cypress_runner.js:125270:18)
      at Promise._settlePromiseCtx (http://localhost:3000/__cypress/runner/cypress_runner.js:125307:10)
      at Async._drainQueue (http://localhost:3000/__cypress/runner/cypress_runner.js:122124:12)
      at Async._drainQueues (http://localhost:3000/__cypress/runner/cypress_runner.js:122129:10)
      at Async.drainQueues (http://localhost:3000/__cypress/runner/cypress_runner.js:122003:14)




  (Results)

  ┌─────────────┐
  │ Tests:        1                         │
  │ Passing:      0                       │
  │ Failing:      1                         │
  │ Pending:      0                       │
  │ Skipped:      0                       │
  │ Screenshots:  1                    │
  │ Video:        true                     │
  │ Duration:     1 second           │
  │ Spec Ran:     Loader.test.js  │
  └─────────────┘


  (Screenshots)

  - /home/odelucca/Servers/yurah/v2/frontends/admin/cypress/screenshots/Loader.test.js/BIG DESKTOPS Loader -- It should be align the loader to center horizontally and vertically (failed).png (1280x720)


  (Video)

  - Started processing:   Compressing to 32 CRF
  - Finished processing:  /home/odelucca/Servers/yurah/v2/frontends/admin/cypress/videos/Loader.test.js.mp4 (0 seconds)


======================

  (Run Finished)


      Spec                                                Tests  Passing  Failing  Pending  Skipped 
  ┌────────────────────────────────┐
  │ ✖ Loader.test.js                            00:01        1        -        1        -        - │
  └────────────────────────────────┘
    1 of 1 failed (100%)                        00:01        1        -        1        -        -  

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! admin@0.1.0 cy:run: `cypress run`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the admin@0.1.0 cy:run script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/odelucca/.npm/_logs/2019-03-07T13_50_22_294Z-debug.log
➜  admin git:(develop) ✗ 

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

@kuceb kuceb closed this as completed Mar 7, 2019
@kuceb kuceb reopened this Mar 7, 2019
@kuceb
Copy link
Contributor

kuceb commented Mar 7, 2019

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

@towc
Copy link

towc commented Nov 27, 2019

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

@jennifer-shehane
Copy link
Member

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

@rodrigodiez
Copy link

rodrigodiez commented Feb 23, 2020

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

@jennifer-shehane jennifer-shehane added the stage: wontfix Cypress does not regard this as an issue or will not implement this feature label May 5, 2020
@icorbrey
Copy link

icorbrey commented Jul 29, 2020

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.

@avkonst
Copy link

avkonst commented May 12, 2021

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.

@jennifer-shehane jennifer-shehane added stage: proposal 💡 No work has been done of this issue type: feature New feature that does not currently exist and removed stage: wontfix Cypress does not regard this as an issue or will not implement this feature type: question labels May 13, 2021
@jennifer-shehane jennifer-shehane changed the title cypress run watchForFileChanges not working watchForFileChanges during cypress run and rerun tests May 13, 2021
@jcom000
Copy link

jcom000 commented Jan 28, 2022

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.

@Romasato
Copy link

Romasato commented Mar 9, 2022

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.

@cypress-bot cypress-bot bot added stage: backlog and removed stage: proposal 💡 No work has been done of this issue labels Apr 29, 2022
@EMPAT94
Copy link

EMPAT94 commented May 21, 2022

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; 

@chaitanyarajugithub
Copy link

Please look - #22410

@chaitanyarajugithub
Copy link

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: #22410

@nicolasalt
Copy link

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.

@RicFer01
Copy link

RicFer01 commented Jan 18, 2023

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.

@nagad814
Copy link

@nagash77 nagash77 added the E2E Issue related to end-to-end testing label May 23, 2023
@ThomasRedstone
Copy link

To add another reason to do this, Cypress open's ability to take screenshots is broken:

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
E2E Issue related to end-to-end testing type: feature New feature that does not currently exist
Projects
None yet
Development

No branches or pull requests