question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

restartOnFileChange doesn't work after run completes normally

See original GitHub issue

I just upgraded to 0.13.11 and tried the restartOnFileChange option out for the first time.

An excerpt from my karma.conf.js is:

  autoWatch: true,
  singleRun: false,
  restartOnFileChange: true
}

When I kick off a test run, and then quickly edit/save a watched file; I see that the current run is cancelled and a new run starts, as per the docs.

I can repeat this process any number of times; with the same results each time (current run is cancelled, new run starts).

However, if I let the current run continue all the way through to completion; then make a change to a watched file, a new run will start, but it doesn’t run any tests.

Example console output is below. It shows:

  1. the end of a successful run (Finished in 39.126 secs, 1325 tests completed)
  2. a change detected in the file foo.js
  3. another run triggered, but with 0 tests completed:
Finished in 39.136 secs / 1.009 secs

SUMMARY:
✔ 1325 tests completed
19 10 2015 16:42:45.754:INFO [watcher]: Changed file "foo.js".

Finished in 0.002 secs / 0 secs

SUMMARY:
✔ 0 tests completed

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Reactions:5
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

3reactions
nobuticommented, Aug 24, 2017

Still failing.

2reactions
solo-mdcommented, Jul 5, 2018

Let me put here a comment on how this issue happens.

Step by step what happens (karma 2.0.4) and why the issue appears:

  1. File changes.

  2. lib/server.js line 304 : file_list_modified event is handled

  3. lib/server.js line 306 : the handler checks config.restartOnFileChange (this one is true in our case)

  4. lib/server.js line 307 : Server emits STOP event

  5. lib/server.js line 309 : Server.executor.schedule() -> lib/executor.js line 34: capturedBrowsers.setAllToExecuting() -> lib/browser_collection.js line 36: set browser state to EXECUTING

  6. static/karma.js line 235 : STOP event (emitted in step 4) is handled

  7. static/karma.js line 236 : karma.complete method is called

  8. static/karma.js line 204: karma emits COMPLETE event to the socket

  9. lib/browser.js line 255 : COMPLETE event (emitted in step 8) is handled wtih onComplete function

  10. lib/browser.js line 117 : onComplete method set the browser state to READY

  11. Now the tests are started normally,lib/browser.js onStart method creates a new Result (line 101), and stores the total count of the specs to run…

  12. Each spec is completed and the lib/browser.js has a notification about it in onResult (line 185). But in case if the browser state is READY, the onResult method just ignores that result: see lib/browser.js lines 190-193 comment:

// ignore - probably results from last run (after server disconnecting)
    if (this.isReady()) {
      return
    }

So, once the restartOnFileChange config is set to TRUE, on the second run all the spec results are ignored, and the number of executed specs will be always 0.

Read more comments on GitHub >

github_iconTop Results From Across the Web

node.js - Nodemon not restarting on file change - Stack Overflow
I have tweaked it to the following: "scripts": { "start": "nodemon run prod", "build": "npm-run-all clean transpile", etc... } Still does not ...
Read more >
A Complete Guide to Node.js Process Management with PM2
This in-depth guide runs you through the key features of Node.js process manager ... Start Your Node.js App in Development Mode with PM2....
Read more >
Single Page Doc - PM2
Restarting PM2 with the processes you manage on server boot/reboot is critical. To solve this, just run this command to generate an active...
Read more >
Configuration File - Karma
Description: When Karma is watching the files for changes, it tries to batch multiple changes into a single run so that the test...
Read more >
ts-node - npm
TypeScript execution environment and REPL for node.js, with source map ... Start using ts-node in your project by running `npm i ts-node`.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found