Created by Ricky Chien
For better software quality, we need to write tests
Coverage tool can give us a statistics report after testing
Blanket.js - JavaScript test coverage tool
Nowadays, web is going to become more complicated
Browser can take more jobs than server
Before
After
Browser instrumentation / Server instrumentation
Sometimes we need to interact with a real server
In browser instrumentation
Firefox OS email app should be covered 21 modules
Make it possible to cover dynamic lazy loading scripts
Analyze web loading approachs
<script src="path-to/script.js"></script>
var xhr = new XMLHttpRequest();
xhr.open('GET', 'path-to/script.js'); // Assign script url
xhr.onload = function (script) {
eval(script); // Execute script
};
xhr.send();
document.write('');
appendChild / insertBefore / replaceChild
var script = document.createElement("script");
script.src = url; // Assign script url
document.head.appendChild(script);
parentNode.insertBefore(script, node);
parentNode.replaceChild(script, oldNode);
Famous module loader library such as RequireJS using syntax :
require(["path-to/script.js"], function() {
// This function is called after path-to/script.js has loaded.
});
Overwrite native appendChild / insertBefore / replaceChild
var originalAppendChild = Element.prototype.appendChild;
Element.prototype.appendChild = function(newElement) {
// Do our hack here
return originalAppendChild.apply(this, args); // invoke native method
};
Overwrite native open method in XHR object
var originalXHROpen = XMLHttpRequest.prototype.open;
XMLHttpRequest.prototype.open = function(method, url) {
// Do our hack here
return originalXHROpen.apply(this, args); // invoke native method
};
We demonstrated the zero coverage issue
Analyzed source instrumentation mechanism and dynamic lazy loading schemes
Proposed a solution to overwrite native Web APIs to detect dynamic lazy loading
Solution was succssful and safe that even integrated into FFOS testing framework
New feature has proposed to Blanket