diff --git a/js/logger.js b/js/logger.js index 16e310e8..7434ccd2 100644 --- a/js/logger.js +++ b/js/logger.js @@ -24,7 +24,16 @@ } })(this, function (config) { let logLevel; - if ((typeof exports === "object" && process.env.JEST_WORKER_ID === undefined) || typeof exports !== "object") { + let enableLog; + if (typeof exports === "object") { + // in nodejs and not running with jest + enableLog = (process.env.JEST_WORKER_ID === undefined); + } else { + // in browser and not running with jsdom + enableLog = (typeof window === 'object' && window.name === 'nodejs'); + }; + + if (enableLog) { logLevel = { debug: Function.prototype.bind.call(console.debug, console), log: Function.prototype.bind.call(console.log, console), @@ -35,8 +44,8 @@ groupCollapsed: Function.prototype.bind.call(console.groupCollapsed, console), groupEnd: Function.prototype.bind.call(console.groupEnd, console), time: Function.prototype.bind.call(console.time, console), - timeEnd: Function.prototype.bind.call(console.timeEnd, console) - // timeStamp: Function.prototype.bind.call(console.timeStamp, console) + timeEnd: Function.prototype.bind.call(console.timeEnd, console), + timeStamp: Function.prototype.bind.call(console.timeStamp, console) }; logLevel.setLogLevel = function (newLevel) { diff --git a/package.json b/package.json index 601fe53b..01d7ee42 100644 --- a/package.json +++ b/package.json @@ -130,7 +130,8 @@ "/js/" ], "testPathIgnorePatterns": [ - "/tests/e2e/global-setup.js" + "/tests/e2e/global-setup.js", + "/tests/e2e/mock-console.js" ] } ] diff --git a/tests/e2e/global-setup.js b/tests/e2e/global-setup.js index a8b0278f..415e946d 100644 --- a/tests/e2e/global-setup.js +++ b/tests/e2e/global-setup.js @@ -1,6 +1,7 @@ const jsdom = require("jsdom"); +const config = require("../configs/empty_ipWhiteList"); -exports.startApplication = function (configFilename, exec) { +exports.startApplication = function (configFilename, exec, callback) { jest.resetModules(); // Set config sample for use in test process.env.MM_CONFIG_FILE = configFilename; @@ -8,6 +9,16 @@ exports.startApplication = function (configFilename, exec) { const app = require("app.js"); app.start(); + if (callback) { + const url = "http://" + (config.address || "localhost") + ":" + (config.port || "8080"); + jsdom.JSDOM.fromURL(url, { resources: "usable", runScripts: "dangerously" }).then((dom) => { + dom.window.onload = function () { + global.document = dom.window.document; + callback(); + }; + }); + }; + return app; }; @@ -16,12 +27,3 @@ exports.stopApplication = function (app) { app.stop(); } }; - -exports.getDocument = function (url, callback) { - jsdom.JSDOM.fromURL(url, { resources: "usable", runScripts: "dangerously" }).then((dom) => { - dom.window.onload = function () { - global.document = dom.window.document; - callback(); - }; - }); -}; diff --git a/tests/e2e/modules_display_spec.js b/tests/e2e/modules_display_spec.js index 865748cd..5e07ae19 100644 --- a/tests/e2e/modules_display_spec.js +++ b/tests/e2e/modules_display_spec.js @@ -3,8 +3,7 @@ let app = null; describe("Display of modules", function () { beforeAll(function (done) { - app = helpers.startApplication("tests/configs/modules/display.js"); - helpers.getDocument("http://localhost:8080", done); + app = helpers.startApplication("tests/configs/modules/display.js", null, done); }); afterAll(function () { helpers.stopApplication(app);