From ecb6ec3adfd8ef46018c0a78542c90fa7d6618d5 Mon Sep 17 00:00:00 2001 From: Yuri Kuznetsov Date: Wed, 14 Jun 2023 12:05:13 +0300 Subject: [PATCH] fix frontend tests, error on loader loader second time --- .../Espo/Resources/metadata/app/jsLibs.json | 4 - client/src/loader.js | 4 + frontend/test/init.js | 86 +++++++++++++++++++ frontend/test/jasmine-browser.json | 5 +- frontend/test/loader-init-libs.js | 69 --------------- 5 files changed, 92 insertions(+), 76 deletions(-) create mode 100644 frontend/test/init.js delete mode 100644 frontend/test/loader-init-libs.js diff --git a/application/Espo/Resources/metadata/app/jsLibs.json b/application/Espo/Resources/metadata/app/jsLibs.json index 5755a36116..2ec45610bb 100644 --- a/application/Espo/Resources/metadata/app/jsLibs.json +++ b/application/Espo/Resources/metadata/app/jsLibs.json @@ -46,10 +46,6 @@ "exportsAs": "Flotr", "sourceMap": true }, - "Base64": { - "exportsTo": "window", - "exportsAs": "Base64" - }, "espo-funnel-chart": { "path": "client/lib/espo-funnel-chart.js", "exportsTo": "window", diff --git a/client/src/loader.js b/client/src/loader.js index 1033446f84..20c357518e 100644 --- a/client/src/loader.js +++ b/client/src/loader.js @@ -34,6 +34,10 @@ root.Espo = {}; } + if (root.Espo.loader) { + throw new Error("Loader was already loaded."); + } + /** * A callback with resolved dependencies passed as parameters. * Should return a value to define a module. diff --git a/frontend/test/init.js b/frontend/test/init.js new file mode 100644 index 0000000000..9bceebdf8b --- /dev/null +++ b/frontend/test/init.js @@ -0,0 +1,86 @@ +/************************************************************************ + * This file is part of EspoCRM. + * + * EspoCRM - Open Source CRM application. + * Copyright (C) 2014-2023 Yurii Kuznietsov, Taras Machyshyn, Oleksii Avramenko + * Website: https://www.espocrm.com + * + * EspoCRM is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * EspoCRM is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with EspoCRM. If not, see http://www.gnu.org/licenses/. + * + * The interactive user interfaces in modified source and object code versions + * of this program must display Appropriate Legal Notices, as required under + * Section 5 of the GNU General Public License version 3. + * + * In accordance with Section 7(b) of the GNU General Public License version 3, + * these Appropriate Legal Notices must retain the display of the "EspoCRM" word. + ************************************************************************/ + +let scriptEl = document.createElement('script'); + +scriptEl.setAttribute('type', 'application/json'); +scriptEl.setAttribute('data-name', 'loader-params'); +scriptEl.textContent = JSON.stringify({ + basePath: '../../', + libsConfig: { + "espo": { + "exportsTo": "window", + "exportsAs": "Espo" + }, + "jquery": { + "expose": true, + "exposeAs": "$", + "amdId": "jquery" + }, + "backbone": { + "exportsTo": "window", + "exportsAs": "Backbone" + }, + "bullbone": { + "expose": true, + "exposeAs": "Bull", + "amdId": "bullbone" + }, + "handlebars": { + "expose": true, + "exposeAs": "Handlebars" + }, + "underscore": { + "expose": true, + "exposeAs": "_", + "amdId": "underscore" + }, + "marked": {}, + "dompurify": { + "expose": true, + "exposeAs": "DOMPurify" + }, + "base64": { + "exportsTo": "window", + "exportsAs": "Base64" + }, + "moment": { + "exportsTo": "window", + "exportsAs": "moment" + } + }, + aliasMap: { + "jquery": "lib!jquery", + "bullbone": "lib!bullbone", + "underscore": "lib!underscore", + "cronstrue": "lib!cronstrue", + "exif-js": "lib!exif" + } +}); + +document.head.appendChild(scriptEl); diff --git a/frontend/test/jasmine-browser.json b/frontend/test/jasmine-browser.json index e42fd90ce0..dd8059a277 100644 --- a/frontend/test/jasmine-browser.json +++ b/frontend/test/jasmine-browser.json @@ -1,9 +1,8 @@ { "srcDir": ".", "srcFiles": [ - "client/lib/espo-libs.min.js", - "client/lib/transpiled/src/loader.js", - "frontend/test/loader-init-libs.js", + "frontend/test/init.js", + "client/lib/espo.min.js", "client/lib/transpiled/src/exceptions.js", "client/lib/transpiled/src/utils.js", "client/lib/transpiled/src/ajax.js", diff --git a/frontend/test/loader-init-libs.js b/frontend/test/loader-init-libs.js deleted file mode 100644 index d06c0abd6c..0000000000 --- a/frontend/test/loader-init-libs.js +++ /dev/null @@ -1,69 +0,0 @@ -/************************************************************************ - * This file is part of EspoCRM. - * - * EspoCRM - Open Source CRM application. - * Copyright (C) 2014-2023 Yurii Kuznietsov, Taras Machyshyn, Oleksii Avramenko - * Website: https://www.espocrm.com - * - * EspoCRM is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * EspoCRM is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with EspoCRM. If not, see http://www.gnu.org/licenses/. - * - * The interactive user interfaces in modified source and object code versions - * of this program must display Appropriate Legal Notices, as required under - * Section 5 of the GNU General Public License version 3. - * - * In accordance with Section 7(b) of the GNU General Public License version 3, - * these Appropriate Legal Notices must retain the display of the "EspoCRM" word. - ************************************************************************/ - -Espo.loader.addLibsConfig({ - "espo": { - "exportsTo": "window", - "exportsAs": "Espo" - }, - "jquery": { - "expose": true, - "exposeAs": "$", - "amdId": "jquery" - }, - "backbone": { - "exportsTo": "window", - "exportsAs": "Backbone" - }, - "bullbone": { - "expose": true, - "exposeAs": "Bull", - "amdId": "bullbone" - }, - "handlebars": { - "expose": true, - "exposeAs": "Handlebars" - }, - "underscore": { - "expose": true, - "exposeAs": "_", - "amdId": "underscore" - }, - "marked": {}, - "dompurify": { - "expose": true, - "exposeAs": "DOMPurify" - }, - "base64": { - "exportsTo": "window", - "exportsAs": "Base64" - }, - "moment": { - "expose": true - } -});