summaryrefslogtreecommitdiff
path: root/addons/web/static/src/js/core
diff options
context:
space:
mode:
authorAaron Bohy <aab@odoo.com>2020-06-08 11:50:24 +0000
committerAaron Bohy <aab@odoo.com>2020-07-13 12:55:07 +0000
commitaf85bb5e13b9c97d022a721bd782a37d718e4496 (patch)
tree731c1983542ec3fc07b3b70832659d5ad803252d /addons/web/static/src/js/core
parentce3c7d8714c330b8344ffb76245c364045cbf62f (diff)
[IMP] web,*: do not deploy services in tests
*mail,point_of_sale,web_editor,website In the tests, required services are deployed for each test independently. There is no need to have, in additon, all services deployed globally. Worse, it could conflict and lead to unexpected results. This commit ensures services are no longer deployed globally in tests. It turns the module 'web.env' into a declarative module with no side-effect, by moving the service deployment to main.js, which isn't added to the tests page. Task 2287397 closes odoo/odoo#53817 Signed-off-by: Lucas Perais (lpe) <lpe@odoo.com>
Diffstat (limited to 'addons/web/static/src/js/core')
-rw-r--r--addons/web/static/src/js/core/abstract_service.js45
1 files changed, 45 insertions, 0 deletions
diff --git a/addons/web/static/src/js/core/abstract_service.js b/addons/web/static/src/js/core/abstract_service.js
index f9ad859fef2..5157b5b55f4 100644
--- a/addons/web/static/src/js/core/abstract_service.js
+++ b/addons/web/static/src/js/core/abstract_service.js
@@ -2,6 +2,7 @@ odoo.define('web.AbstractService', function (require) {
"use strict";
var Class = require('web.Class');
+const { serviceRegistry } = require("web.core");
var Mixins = require('web.mixins');
var ServicesMixin = require('web.ServicesMixin');
@@ -40,6 +41,50 @@ var AbstractService = Class.extend(Mixins.EventDispatcherMixin, ServicesMixin, {
this.env.bus.trigger('do-action', payload);
}
},
+
+ //--------------------------------------------------------------------------
+ // Static
+ //--------------------------------------------------------------------------
+
+ /**
+ * Deploy services in the env (specializations of AbstractService registered
+ * into the serviceRegistry).
+ *
+ * @static
+ * @param {Object} env
+ */
+ deployServices(env) {
+ const UndeployedServices = Object.assign({}, serviceRegistry.map);
+ function _deployServices() {
+ let done = false;
+ while (!done) {
+ // find a service with no missing dependency
+ const serviceName = Object.keys(UndeployedServices).find(serviceName => {
+ const Service = UndeployedServices[serviceName];
+ return Service.prototype.dependencies.every(depName => {
+ return env.services[depName];
+ });
+ });
+ if (serviceName) {
+ const Service = UndeployedServices[serviceName];
+ const service = new Service(env);
+ env.services[serviceName] = service;
+ delete UndeployedServices[serviceName];
+ service.start();
+ } else {
+ done = true;
+ }
+ }
+ }
+ serviceRegistry.onAdd((serviceName, Service) => {
+ if (serviceName in env.services || serviceName in UndeployedServices) {
+ throw new Error(`Service ${serviceName} is already loaded.`);
+ }
+ UndeployedServices[serviceName] = Service;
+ _deployServices();
+ });
+ _deployServices();
+ }
});
return AbstractService;