From 98cd652f4b44279fc830239a35a3b4cd998f1d8a Mon Sep 17 00:00:00 2001 From: Piotr Gawron <piotr.gawron@uni.lu> Date: Mon, 5 Aug 2019 09:58:26 +0200 Subject: [PATCH] remove global libraries from mocha-config --- frontend-js/package-lock.json | 8 ++--- frontend-js/package.json | 6 ++-- frontend-js/src/main/js/GuiConnector.js | 6 ++++ frontend-js/src/test/js/GuiConnector-test.js | 1 + frontend-js/src/test/js/mocha-config.js | 32 +++++--------------- 5 files changed, 21 insertions(+), 32 deletions(-) diff --git a/frontend-js/package-lock.json b/frontend-js/package-lock.json index 4309619823..6d352a0e38 100644 --- a/frontend-js/package-lock.json +++ b/frontend-js/package-lock.json @@ -2726,10 +2726,10 @@ "resolved": "https://registry.npmjs.org/jquery/-/jquery-3.2.1.tgz", "integrity": "sha1-XE2d5lKvbNCncBVKYxu6ErAVx4c=" }, - "jquery-ui-dist": { - "version": "1.12.1", - "resolved": "https://registry.npmjs.org/jquery-ui-dist/-/jquery-ui-dist-1.12.1.tgz", - "integrity": "sha1-XAgV08xvkP9fqvWyaKbiO0ypBPo=", + "jquery-ui": { + "version": "1.10.5", + "resolved": "https://registry.npmjs.org/jquery-ui/-/jquery-ui-1.10.5.tgz", + "integrity": "sha1-gmrtPdH4jTKudddN9IZD3EMaWBU=", "dev": true }, "js-tokens": { diff --git a/frontend-js/package.json b/frontend-js/package.json index 5c5d33709f..c02c54a5e3 100644 --- a/frontend-js/package.json +++ b/frontend-js/package.json @@ -24,13 +24,10 @@ "browserify": "^13.1.1", "chai": "^3.5.0", "clean-css-cli": "^4.2.1", - "datatables.net": "^1.10.19", "del": "^3.0.0", "exorcist": "^0.4.0", "file-url": "^2.0.0", "istanbul": "0.4.5", - "jquery": "3.2.1", - "jquery-ui-dist": "1.12.1", "jsdom": "11.7.0", "jshint": "^2.9.6", "log4js-in-memory-appender": "^0.1.2", @@ -43,11 +40,14 @@ }, "dependencies": { "csv-stringify": "^4.0.0", + "datatables.net": "^1.10.19", "datatables.net-rowreorder": "^1.2.5", "dual-listbox": "1.0.7", "file-saver": "^1.3.8", "http-status-codes": "^1.3.0", "is-url": "^1.2.4", + "jquery": "3.2.1", + "jquery-ui": "1.10.5", "jstree": "^3.3.5", "jszip": "^3.1.5", "log4js": "4.1.0", diff --git a/frontend-js/src/main/js/GuiConnector.js b/frontend-js/src/main/js/GuiConnector.js index edea2cb370..90968a42ac 100644 --- a/frontend-js/src/main/js/GuiConnector.js +++ b/frontend-js/src/main/js/GuiConnector.js @@ -9,6 +9,12 @@ var ObjectWithListeners = require('./ObjectWithListeners'); var SecurityError = require('./SecurityError'); var ValidationError = require('./ValidationError'); +var $ = require('jquery'); +var jQuery = $; +var dt = require('datatables.net')(); +var dtReorder = require('datatables.net-rowreorder')(); +require('jquery-ui/dialog'); + /** * This static global object contains set of functions that returns/set data in * the Gui (html). diff --git a/frontend-js/src/test/js/GuiConnector-test.js b/frontend-js/src/test/js/GuiConnector-test.js index ff313d564a..af5980a3bb 100644 --- a/frontend-js/src/test/js/GuiConnector-test.js +++ b/frontend-js/src/test/js/GuiConnector-test.js @@ -1,6 +1,7 @@ "use strict"; require("./mocha-config"); +var $ = require('jquery'); var GuiConnector = require('../../main/js/GuiConnector'); var SecurityError = require('../../main/js/SecurityError'); diff --git a/frontend-js/src/test/js/mocha-config.js b/frontend-js/src/test/js/mocha-config.js index 325595eddc..398054c4a0 100644 --- a/frontend-js/src/test/js/mocha-config.js +++ b/frontend-js/src/test/js/mocha-config.js @@ -2,6 +2,9 @@ var Promise = require("bluebird"); +mockEnvironment(); + +var $ = require('jquery'); var Helper = require('./helper'); @@ -9,18 +12,11 @@ var GuiConnector = require('./GuiConnector-mock'); var path = require('path'); -global.window = undefined; // ----------------------------- var logger = require('./logger'); -function mockBootstrap() { - $.fn.typeahead = function () { - logger.debug("Mock typeahead function call"); - }; -} - -before(function () { +function mockEnvironment() { require('../../main/js/Functions').loadScript = function () { global.MathJax = { Hub: { @@ -53,10 +49,6 @@ before(function () { global.document.elementFromPoint = function () { }; - global.$ = require('jquery'); - global.jQuery = $; - global.window.$ = $; - // additions to jsdom implementations: global.Option = window.Option; global.Blob = window.Blob; @@ -172,25 +164,15 @@ before(function () { }; // --- - require('jquery-ui-dist/jquery-ui.js'); - - require("bootstrap"); - - require('datatables.net')(window, $); - require('datatables.net-rowreorder')(window, $); - require('spectrum-colorpicker'); global.tinycolor = window.tinycolor; - require('jstree'); global.google = require('./google-map-mock'); global.ServerConnector = require('./ServerConnector-mock'); Promise.longStackTraces(); +} - mockBootstrap(); - -}); beforeEach(function () { Helper.prototype.setUrl.call(this, "http://test/"); @@ -228,7 +210,7 @@ afterEach(function () { var content = document.body.innerHTML; document.body.innerHTML = ""; this.test.error(new Error("Test didn't left clean document. Found: " + content)); - } else if ($._data(window, "events").resize) { + } else if ($._data(window, "events") && $._data(window, "events").resize) { var events = $._data(window, "events").resize; logger.warn(events); $(window).off("resize"); @@ -236,7 +218,7 @@ afterEach(function () { } } else { //when failed don't forget to clean events - if ($._data(window, "events").resize) { + if ($._data(window, "events") && $._data(window, "events").resize) { logger.warn("Clearing events: " + $._data(window, "events").resize); $(window).off("resize"); } -- GitLab