mirror of
https://github.com/MichMich/MagicMirror.git
synced 2025-06-27 11:50:00 +00:00
fix logger.js, move jsdom in startApplication
This commit is contained in:
parent
0ef6f89d44
commit
a1c7f20990
15
js/logger.js
15
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) {
|
||||
|
@ -130,7 +130,8 @@
|
||||
"<rootDir>/js/"
|
||||
],
|
||||
"testPathIgnorePatterns": [
|
||||
"<rootDir>/tests/e2e/global-setup.js"
|
||||
"<rootDir>/tests/e2e/global-setup.js",
|
||||
"<rootDir>/tests/e2e/mock-console.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();
|
||||
};
|
||||
});
|
||||
};
|
||||
|
@ -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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user