lundi 5 octobre 2015

Reload required module with Karma, Jasmine and karma-browserify

I'm working on a fairly big project and we used to use Jest for our unit tests. We decided to migrate towards Karma + Jasmine because Jest, despite having some pros, was too slow for our needs and was sometimes crashing our continuous integration server, being more demanding in ressources than its counterparts.

The big advantage of Jest was that it was recreating an isolated environment for each test. It was possible to require a module in the beforeEach hook and then the code of the module was ran once again. Another advantage was the automatic mocking of all modules. With Karma and Jasmine, you sometimes need to track down side effects to minimize undesired behaviours.

As for Karma and Jasmine, it is way faster in comparison and the files watching feature allows us to do efficient TDD AND the other dev teams are happy we are not crashing our CI server anymore.

Back to my issue...

I'd like to know if it is possible to "clear require cache" before each test is ran. I know how browserify works and how requires are done, but I'd be glad to know how some of you succeeded getting around this problem. The way it actually works, a new test could break an older test because it modifies the environment, which is really bad.

I tried wireify, but it doesn't seem to play well with watchify (which is used by karma-browserify) and modified modules aren't reloaded properly since all wireify'ed modules have a different reference in memory, and that prevents us to use autoWatch and to proper TDD.

Aucun commentaire:

Enregistrer un commentaire