17

I am running Jasmine tests on Karma (latest, 0.12.14) from IntelliJ IDEA (latest, 13.1.2) on OS X.

IntelliJ just uses Karma plugin that points to my karma installation: /usr/local/lib/node_modules/karma

The problem is that Karma watcher doesn't pick new changes from JS files. When I run tests again, everything is fine. It's not a huge issue (they run pretty fast), but it's annyoing to always run tests twice after you do a change.

Anybody experienced similar issue?

Xorty
  • 18,367
  • 27
  • 104
  • 155
  • Did you ever solve this? I'm running into the same issue. – CorrugatedAir Apr 09 '15 at 12:35
  • I also have same issue. I can verify that the test gets executed on the "pre-change" version of the files. ie: if I have the auto-watch toggle on, and I add a console.log, the tests run automatically (because it detects I made a change), but no console.log. If I then manually re-run the tests, I see the console.log – jlee Feb 03 '17 at 21:33

8 Answers8

7

Add the following property to your karma.conf.js file:

usePolling: true

I put it after the autoWatch flag.

Reference: AutoWatch doesn't work #895

Gordon
  • 4,823
  • 4
  • 38
  • 55
6

Finally got this to work. This is a known issue when using Karma in IntelliJ with build tools like Webpack / Gulp / etc... and that the post-processed files are outside of the files that Karma is directly serving.

The workaround is to manually modify the IntelliJ config in this file: ...\plugins\js-karma\js_reporter\karma-intellij\lib\intellijRunner.js

At or near line #75 in the runWithConfig() method, change the refresh property --> true.

See this comment for details

Had this issue in both IntelliJ and Webstorm and fixed both the same way.

jlee
  • 464
  • 6
  • 9
  • Indeed that did the trick for me on WebStorm 2016.3 (/w autoWatch=false noPolling and "safe write". – Robert May 18 '17 at 13:25
5

In the case of using IntelliJ IDEA, maybe try
Preferences > General > Uncheck "safe write"

  • 1
    This worked in IntelliJ 2019.1.1, though the option has moved to Preferences > Appearance & Behavior > System Settings > Use Safe Write – jonathan.cone May 10 '19 at 22:29
4

I am not sure if question is still actual, but i found a solution (or just a workaround).

I changed this file C:\Users\MyUser\.IntelliJIdea14\config\plugins\js-karma\js_reporter\karma-intellij\lib\intellij.conf.js a little bit here:

config.singleRun = false;
var originalAutoWatch = config.autoWatch;
//config.autoWatch = false; <-- this line
config.autoWatchBatchDelay = 0;

For sure the plugin maintainers had some reason to add this line, but for me this worked fine enough (there were isolated crashes I can't reproduce).

Nathan Tuggy
  • 2,237
  • 27
  • 30
  • 38
  • Works great! I'd also recommend to comment the next line (autoWatchBatchDelay) so that the default of 250ms is kept. This makes karma wait 250ms for other file changes before running the tests again. – ouk Jul 19 '16 at 11:19
  • this did not work for me. after making a change to a file (src file or spec file), the autowatch is triggered, and the tests re-run -- but the change isn't picked up (ie: if I fixed a test, it still says the test failed). However, when I hit re-run tests manually again, then it says the test passed. – jlee Feb 03 '17 at 21:31
2

I am not sure about older versions of intelij but I am using 2016.3 (the latest version at the time of writing this) and it all works OK assuming karma config has autoWatch: true. Having exactly the same problem all I have to do was to switch on Toggle auto-test in intelij and all started working fine without any other change.

Julian
  • 3,678
  • 7
  • 40
  • 72
1

Please check autoWatch property in karma config file set to TRUE.

  • It has been set to true all the time. It actually prints watcher statements to console. – Xorty Apr 29 '14 at 11:01
0

Also if you are using Sublime Text 3 then set "atomic_save": false in your user settings as it also causes issues with watches. see here

screenm0nkey
  • 18,405
  • 17
  • 57
  • 75
0

Macros worked for me. After trying usePolling: true, modifying the intellijRunner.js, and unchecking Safe Write I still had to save or run tests twice to catch the changes.

Made a compound macro to both Save and Run File and Save and Re-Run Test. Then I overwrote each commands' shortcut via Keymap.

How to bind multiple actions to a shortcut

screenshot of macro: Save and Run test at cursor

screenshot of macro: Save and Re-run last test

screenshot of Keymap for macros