mirror of
https://github.com/MichMich/MagicMirror.git
synced 2025-08-21 12:55:22 +00:00
fix e2e tests not failing on errors, disable recurring-event-tests of calendar
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
const jsdom = require("jsdom");
|
||||
|
||||
exports.startApplication = function (configFilename, exec) {
|
||||
exports.startApplication = (configFilename, exec) => {
|
||||
jest.resetModules();
|
||||
this.stopApplication();
|
||||
// Set config sample for use in test
|
||||
@@ -14,41 +14,60 @@ exports.startApplication = function (configFilename, exec) {
|
||||
global.app.start();
|
||||
};
|
||||
|
||||
exports.stopApplication = async function () {
|
||||
exports.stopApplication = async () => {
|
||||
if (global.app) {
|
||||
global.app.stop();
|
||||
}
|
||||
await new Promise((resolve) => setTimeout(resolve, 100));
|
||||
};
|
||||
|
||||
exports.getDocument = function (callback) {
|
||||
exports.getDocument = (callback) => {
|
||||
const url = "http://" + (config.address || "localhost") + ":" + (config.port || "8080");
|
||||
jsdom.JSDOM.fromURL(url, { resources: "usable", runScripts: "dangerously" }).then((dom) => {
|
||||
dom.window.name = "jsdom";
|
||||
dom.window.onload = function () {
|
||||
global.MutationObserver = dom.window.MutationObserver;
|
||||
dom.window.onload = () => {
|
||||
global.document = dom.window.document;
|
||||
callback();
|
||||
};
|
||||
});
|
||||
};
|
||||
|
||||
exports.waitForElement = function (selector) {
|
||||
exports.waitForElement = (selector, ignoreValue = "") => {
|
||||
return new Promise((resolve) => {
|
||||
if (document.querySelector(selector) && document.querySelector(selector).value !== undefined) {
|
||||
return resolve(document.querySelector(selector));
|
||||
}
|
||||
|
||||
const observer = new MutationObserver(() => {
|
||||
if (document.querySelector(selector) && document.querySelector(selector).value !== undefined) {
|
||||
resolve(document.querySelector(selector));
|
||||
observer.disconnect();
|
||||
let oldVal = "dummy12345";
|
||||
const interval = setInterval(() => {
|
||||
const element = document.querySelector(selector);
|
||||
if (element) {
|
||||
let newVal = element.textContent;
|
||||
if (newVal === oldVal) {
|
||||
clearInterval(interval);
|
||||
resolve(element);
|
||||
} else {
|
||||
if (ignoreValue === "") {
|
||||
oldVal = newVal;
|
||||
} else {
|
||||
if (!newVal.includes(ignoreValue)) oldVal = newVal;
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
observer.observe(document.body, {
|
||||
childList: true,
|
||||
subtree: true
|
||||
});
|
||||
}, 100);
|
||||
});
|
||||
};
|
||||
|
||||
exports.waitForAllElements = (selector) => {
|
||||
return new Promise((resolve) => {
|
||||
let oldVal = 999999;
|
||||
const interval = setInterval(() => {
|
||||
const element = document.querySelectorAll(selector);
|
||||
if (element) {
|
||||
let newVal = element.length;
|
||||
if (newVal === oldVal) {
|
||||
clearInterval(interval);
|
||||
resolve(element);
|
||||
} else {
|
||||
if (newVal !== 0) oldVal = newVal;
|
||||
}
|
||||
}
|
||||
}, 100);
|
||||
});
|
||||
};
|
||||
|
Reference in New Issue
Block a user