I am faced with what, in my opinion, is a condition of the race between Vim save files and Karma re-running the Jasmine tests. Here's a sequence of four test runs that shows a symptom (I truncated extremely long paths in the error log):
$ karma start karma.conf.js --auto-watch [... snip a lot of coding and test running ...] PhantomJS 1.6 (Linux) LOG: 'Running tests at 2013-08-14T08:19:57.252Z' PhantomJS 1.6 (Linux): Executed 4 of 4 SUCCESS (0.307 secs / 0.013 secs) PhantomJS 1.6 (Linux) LOG: 'Running tests at 2013-08-14T08:20:09.866Z' PhantomJS 1.6 (Linux): Executed 4 of 4 SUCCESS (0.288 secs / 0.012 secs) PhantomJS 1.6 (Linux) LOG: 'Running tests at 2013-08-14T08:20:14.366Z' PhantomJS 1.6 (Linux) controller should have a breadcrumb after $routeChangeSuccess FAILED Error: No module: myapp.question at /home/rmunn/.../angular.js:1124 at ensure (/home/rmunn/.../angular.js:1065) at module (/home/rmunn/.../angular.js:1296) at /home/rmunn/.../angular.js:2806 TypeError: 'undefined' is not an object (evaluating 'rootScope.$broadcast') at /home/rmunn/.../unit/controllersSpec.js:35 PhantomJS 1.6 (Linux): Executed 4 of 4 (1 FAILED) (0.312 secs / 0.014 secs) PhantomJS 1.6 (Linux) LOG: 'Running tests at 2013-08-14T08:20:28.588Z' PhantomJS 1.6 (Linux): Executed 4 of 4 SUCCESS (0.287 secs / 0.013 secs)
The only change I made to run these four runs was to add and remove spaces from the question.js file; There were no significant code changes, but launch # 3 failed when runs 1, 2, and 4 were performed.
My Vim is configured to store backup files, and by default, Vim saves backup files by renaming the original file and writing a new one. (Except for certain conditions that are not applicable here). I think I'm running a race condition: Vim renames question.js (or any file I just edited), Karma detects this change and runs tests, and since I have so few tests now, all tests run before as the Linux process manager will return to Vim. After Vim is scheduled again, he writes the new contents of question.js , but by now it is too late for the Jasmine test, which depends on the existing and non-empty question.js .
I could fix this by setting Vim not to store backup files, but I really would not risk it. In the end, I use backup files. So is there a way to tell Karma "when you detect a file change, pause for N milliseconds, and then do unit tests"? Although this decision would be brute force, it would solve this particular race condition. Or, if someone has other smart ideas, I would also like to hear them.
javascript angularjs vim karma-runner jasmine
rmunn
source share