I use the browserify standalone option in the following gulp tasks to generate an UMD module:
gulp.task("bundle-source", function () {
var b = browserify({
standalone : 'inversify',
entries: __dirname + "/build/source/inversify.js",
debug: true
});
The standalone option wraps the library code with the following code to ensure that it can be loaded as a Node module, an AMD module or a Global:
!function(n) {
if ("object" == typeof exports && "undefined" != typeof module) module.exports = n();
else if ("function" == typeof define && define.amd) define([], n);
else {
var e;
e = "undefined" != typeof window ? window : "undefined" != typeof global ? global : "undefined" != typeof self ? self : this, e.inversify = n()
}
}(function() {
return function n(e, t, i) {
function r(u, p) {
if (!t[u]) {
if (!e[u]) {
var s = "function" == typeof require && require;
if (!p && s) return s(u, !0);
if (o) return o(u, !0);
var c = new Error("Cannot find module '" + u + "'");
throw c.code = "MODULE_NOT_FOUND", c
}
var f = t[u] = {
exports: {}
};
e[u][0].call(f.exports, function(n) {
var t = e[u][1][n];
return r(t ? t : n)
}, f, f.exports, n, e, t, i)
}
return t[u].exports
}
for (var o = "function" == typeof require && require, u = 0; u < i.length; u++) r(i[u]);
return r
}({
// The rest of the library code ...
I'm using istanbul to try to achieve 100% test coverage. My problems is that some parts of the UMD code snippet are not tested. For example, I'm not using AMD so lines like the ones below are never executed:
\\ ...
else if ("function" == typeof define && define.amd) define([], n);
\\ ...
or
\\ ...
if (!e[u]) {
var s = "function" == typeof require && require;
if (!p && s) return s(u, !0);
if (o) return o(u, !0);
var c = new Error("Cannot find module '" + u + "'");
throw c.code = "MODULE_NOT_FOUND", c
}
\\ ...
This is preventing me from achieving 100% test coverage. Do you know how can I get around this problem?
Thanks!