I am trying to create a basic unit test environment for a simple project, but I am striking a strange obstacle that I could not overcome after several hours of research.
For some reason, I get Error: NETWORK_ERR: XMLHttpRequest Exception 101 , returned directly from EJS trying to load a template using XHR, but only once in a while.
The case is simple, I have a base application that creates an instance of a base view that displays an EJS template. It looks like this:
BackboneView = Backbone.View.extend({ initialize: function() { this.template = new EJS({url: '/app/views/root/root.template.ejs'}); } });
To configure grunt-contrib-jasmine, I have the following snippet in my Grunt file:
jasmine: { cms: { src: "app/**/*.js" options: { specs: "tests/fe/spec/*Spec.js", vendor: [ "vendor/jquery/dist/jquery.js", "vendor/underscore/underscore.js", "vendor/backbone/backbone.js", "vendor/ejs/ejs.js", ], keepRunner : true, outfile : "tests/fe/_SpecRunner.html", host : "http://0.0.0.0:8000" } } }
I can run my test suite most of the time:
$ grunt jasmine Running "jasmine:cms" (jasmine) task Testing jasmine specs via PhantomJS log: came in request!, /app/views/root/root.template.ejs log: 200 log: /app/views/root/root.template.ejs website.header header.test() - test should return 10... log: ✓ test should return 10 1 spec in 0.008s. >> 0 failures Done, without errors.
But from time to time I get a console spitting on me:
$ grunt jasmine Running "jasmine:cms" (jasmine) task Testing jasmine specs via PhantomJS log: came in request!, /app/views/root/root.template.ejs log: ERROR in request, Error: NETWORK_ERR: XMLHttpRequest Exception 101 log: /app/views/root/root.template.ejs >> Error caught from PhantomJS. More info can be found by opening the Spec Runner in a browser. Warning: There is no template at /app/views/root/root.template.ejs Use --force to continue. Aborted due to warnings.
Logs have been added to the appropriate part of the EJS engine to help me debug. It will be:
I can run grunt jasmine 6-7 times in a row and work without problems. Suddenly, the attempt will simply fail, the subsequent attempt will most likely return to normal. Until it breaks again. And all this without me does not touch anywhere!
I really lose hope of solving this problem. Here are a few sources that I experienced that didn't work:
Has anyone got an idea of what might be causing this or a hint of what to do next to try and debug the problem?
PS: I feel that my question is a bit overloaded with a piece of code, please let me know if I can improve the question in any way.