2016-07-30 17:00:12 +02:00
|
|
|
var namespace = (function () {
|
|
|
|
|
2017-01-08 09:36:18 +01:00
|
|
|
var _ = require('node_modules/underscore/underscore.js');
|
2016-07-30 17:00:12 +02:00
|
|
|
var exports = {};
|
|
|
|
|
|
|
|
var dependencies = [];
|
2016-07-30 19:34:51 +02:00
|
|
|
var requires = [];
|
2016-07-30 17:00:12 +02:00
|
|
|
var old_builtins = {};
|
|
|
|
|
|
|
|
exports.set_global = function (name, val) {
|
|
|
|
global[name] = val;
|
|
|
|
dependencies.push(name);
|
|
|
|
return val;
|
|
|
|
};
|
|
|
|
|
|
|
|
exports.patch_builtin = function (name, val) {
|
|
|
|
old_builtins[name] = global[name];
|
|
|
|
global[name] = val;
|
|
|
|
return val;
|
|
|
|
};
|
|
|
|
|
|
|
|
exports.add_dependencies = function (dct) {
|
|
|
|
_.each(dct, function (fn, name) {
|
|
|
|
var obj = require(fn);
|
2016-07-30 19:34:51 +02:00
|
|
|
requires.push(fn);
|
2016-07-30 17:00:12 +02:00
|
|
|
set_global(name, obj);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
exports.restore = function () {
|
|
|
|
dependencies.forEach(function (name) {
|
|
|
|
delete global[name];
|
|
|
|
});
|
2016-07-30 19:34:51 +02:00
|
|
|
requires.forEach(function (fn) {
|
|
|
|
delete require.cache[require.resolve(fn)];
|
|
|
|
});
|
2016-07-30 17:00:12 +02:00
|
|
|
dependencies = [];
|
|
|
|
_.extend(global, old_builtins);
|
|
|
|
old_builtins = {};
|
|
|
|
};
|
|
|
|
|
2016-07-30 20:01:15 +02:00
|
|
|
exports.stub_out_jquery = function () {
|
|
|
|
set_global('$', function () {
|
|
|
|
return {
|
|
|
|
on: function () {},
|
|
|
|
trigger: function () {},
|
2016-12-03 23:18:44 +01:00
|
|
|
hide: function () {},
|
2016-07-30 20:01:15 +02:00
|
|
|
};
|
|
|
|
});
|
|
|
|
$.fn = {};
|
|
|
|
$.now = function () {};
|
|
|
|
};
|
|
|
|
|
2016-07-30 17:00:12 +02:00
|
|
|
return exports;
|
|
|
|
}());
|
|
|
|
module.exports = namespace;
|