cypress run watchForFileChanges not working

Created on 7 Mar 2019  ยท  5Comments  ยท  Source: cypress-io/cypress

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! [email protected] cy:run: `cypress run`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the [email protected] 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

wontfix question

Most helpful comment

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

All 5 comments

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.

Was this page helpful?
0 / 5 - 0 ratings