, , ,

QUnit tests with code coverage

Besides the funny name Blanket.js delivers what it promises: seamless code coverage. Adding it to an existing QUnit test suit is very easy and I’m not going to repeat after their website. But I had two special requirements which complicates matters:

  • My test suits must work on IE8 (that sucks, I know)
  • and run in browser both locally (using the file:// protocol) and remotely.

During development I use Chrome and IE9 (tests are run against IE8 automatically on build server) so the first point boils down to disabling Blanket.js completely for IE8:

The second one is tricky. There are some options to run Blanket.js locally in browser but they are… not so seamless or just insecure (disabling CORS restrictions altogether). Again, the simplest solution is to disable code coverage in that situation. Blanket.js integrates with new versions of QUnit and adds Enable coverage checkbox which is off by default. But I have to use an older version (v1.4.0 – forced by IE8 !#@!!) and then code coverage is always enabled. This little gist solves that problem:

Not related to Blanket.js but I encountered one more gotcha with IE: security zones. Build server refused to run my tests until I forced Local Intranet Zone by adding this line to beginning of each HTML files:

This is an obscure IE feature called Mark of the Web (MOTW).

To sum up: all of this workarounds are caused by IE8. Internet Explorer, please die now!