summaryrefslogtreecommitdiff
path: root/addons/web/static/src/js/testing.js
diff options
context:
space:
mode:
authorXavier Morel <xmo@openerp.com>2014-01-31 16:26:40 +0100
committerXavier Morel <xmo@openerp.com>2014-01-31 16:26:40 +0100
commitae3223907b5d33f95c2215824cce1d5a179f6f29 (patch)
tree5bab808036211c1810611080c32b234fbde2bec4 /addons/web/static/src/js/testing.js
parentb78703c12200facabef2cad3e4fa5ec4eb9d57e3 (diff)
[FIX] modules initialization when testing
broken "adaptation" to single-instance openerp would only initialize the first set of dependencies, any further module would see its test runs without itself or its dependencies being guaranteed to be initialized/installed into the current openerp instance. bzr revid: xmo@openerp.com-20140131152640-coxqulkdb0xupbvq
Diffstat (limited to 'addons/web/static/src/js/testing.js')
-rw-r--r--addons/web/static/src/js/testing.js38
1 files changed, 32 insertions, 6 deletions
diff --git a/addons/web/static/src/js/testing.js b/addons/web/static/src/js/testing.js
index f607b278437..c4f5aeebd60 100644
--- a/addons/web/static/src/js/testing.js
+++ b/addons/web/static/src/js/testing.js
@@ -15,6 +15,37 @@ openerp.testing = {};
list_editable: ['list', 'form', 'data'],
};
+ var initialized = [];
+ /**
+ * openerp.init is a broken-ass piece of shit, makes it impossible to
+ * progressively add modules, using it, retarded openerp_inited flag
+ * means the first tests being run get their dependencies loaded
+ * (basically just base and web), and for *every other module* the tests
+ * run without the dependencies being correctly loaded
+ */
+ function init(modules) {
+ if (!initialized.length) {
+ openerp.init(modules);
+ initialized = openerp._modules.slice();
+ return;
+ }
+ var to_initialize = _.difference(modules, initialized);
+ for (var i = 0; i < to_initialize.length; i++) {
+ var modname = to_initialize[i];
+ var fct = openerp[modname];
+ if (typeof fct === 'function') {
+ var module = openerp[modname] = {};
+ for(var k in fct) {
+ if (!fct.hasOwnProperty(k)) { continue; }
+ module[k] = fct[k];
+ }
+ fct(openerp, module)
+ }
+ initialized.push(modname);
+ openerp._modules.push(modname);
+ }
+ }
+
testing.dependencies = window['oe_all_dependencies'] || [];
testing.current_module = null;
testing.templates = { };
@@ -165,8 +196,6 @@ openerp.testing = {};
});
};
- var openerp_inited = false;
-
var db = window['oe_db_info'];
testing.section = function (name, options, body) {
if (_.isFunction(options)) {
@@ -243,10 +272,7 @@ openerp.testing = {};
QUnit.test(name, function () {
var instance = openerp;
- if (!openerp_inited) {
- openerp.init(module_deps);
- openerp_inited = true;
- }
+ init(module_deps);
instance.session = new instance.web.Session();
instance.session.uid = 42;
if (_.isNumber(opts.asserts)) {