MagicMirror/tests/e2e/global-setup.js

36 lines
849 B
JavaScript
Raw Normal View History

2021-09-23 22:52:32 +02:00
const jsdom = require("jsdom");
const config = require("../configs/empty_ipWhiteList");
2021-09-23 22:52:32 +02:00
exports.startApplication = function (configFilename, exec) {
2021-09-16 22:36:18 +02:00
jest.resetModules();
2021-09-25 23:37:37 +02:00
let app = global.app;
if (app) {
app.stop();
}
2021-09-16 22:36:18 +02:00
// Set config sample for use in test
process.env.MM_CONFIG_FILE = configFilename;
if (exec) exec;
2021-09-25 23:37:37 +02:00
app = require("app.js");
2021-09-16 22:36:18 +02:00
app.start();
2021-09-25 23:37:37 +02:00
global.app = app;
2021-09-16 22:36:18 +02:00
return app;
};
exports.stopApplication = function (app) {
if (app) {
app.stop();
}
};
exports.getDocument = function (callback, ms) {
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;
setTimeout(() => {
callback();
}, ms);
};
});
};