Blanket.js, QUnit and IE8 (Please Die Now)
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:
<!--[if gt IE 8]><!-->
<script type="text/javascript" src="blanket.js"></script>
<!--<![endif]-->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:
Index: blanket.js
===================================================================
--- blanket.js (wersja 21811)
+++ blanket.js (wersja 21812)
@@ -4442,7 +4442,10 @@
}).length === 1;
});
}else{
- selectedScripts = toArray.call(document.querySelectorAll("script[data-cover]"));
+ // orientman: disable if run locally
+ if (window.location.protocol !== "file:") {
+ selectedScripts = toArray.call(document.querySelectorAll("script[data-cover]"));
+ }
}
scriptNames = selectedScripts.map(function(s){
return _blanket.utils.qualifyURL(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:
<!-- saved from url=(0016)http://localhost -->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!
Comments (1)
Comments are from the original WordPress blog. New comments are not supported.
[...] The time has come to retire NQUnit. NQUnit runs QUnit tests inside .NET by using WatiN. That means it can be used with any test runner supporting NUnit (e.g. TestDriven.NET or – since VS2012 – built-in + adapter). If you use CI server to run NUnit you got JavaScript tests nicely integrated for free (well, almost). [...]