change getDocument, delay needed, now 2 tests moved

This commit is contained in:
Karsten Hassel 2021-09-24 23:39:12 +02:00
parent a1c7f20990
commit c0ce52abe3
8 changed files with 57 additions and 96 deletions

View File

@ -27,11 +27,11 @@
let enableLog;
if (typeof exports === "object") {
// in nodejs and not running with jest
enableLog = (process.env.JEST_WORKER_ID === undefined);
enableLog = process.env.JEST_WORKER_ID === undefined;
} else {
// in browser and not running with jsdom
enableLog = (typeof window === 'object' && window.name === 'nodejs');
};
enableLog = typeof window === "object" && window.name === "nodejs";
}
if (enableLog) {
logLevel = {

View File

@ -3,7 +3,13 @@
* By Rodrigo Ramírez Norambuena https://rodrigoramirez.com
* MIT Licensed.
*/
let config = require(process.cwd() + "/tests/configs/default.js").configFactory({
let config = {
port: 8080,
ipWhitelist: ["127.0.0.1", "::ffff:127.0.0.1", "::1"],
language: "en",
timeFormat: 24,
units: "metric",
modules:
// Using exotic content. This is why don't accept go to JSON configuration file
(function () {
@ -20,7 +26,7 @@ let config = require(process.cwd() + "/tests/configs/default.js").configFactory(
}
return modules;
})()
});
};
/*************** DO NOT EDIT THE LINE BELOW ***************/
if (typeof module !== "undefined") {

View File

@ -1,7 +1,7 @@
const jsdom = require("jsdom");
const config = require("../configs/empty_ipWhiteList");
exports.startApplication = function (configFilename, exec, callback) {
exports.startApplication = function (configFilename, exec) {
jest.resetModules();
// Set config sample for use in test
process.env.MM_CONFIG_FILE = configFilename;
@ -9,16 +9,6 @@ exports.startApplication = function (configFilename, exec, callback) {
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;
};
@ -27,3 +17,15 @@ exports.stopApplication = function (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);
};
});
};

View File

@ -1,5 +1,10 @@
/**
* Suppresses errors concerning web server already shut down.
*
* @param {string} err The error message.
*/
function myError(err) {
if (err.includes("ECONNREFUSED")) {
if (err.includes("ECONNREFUSED") || err.includes("ECONNRESET") || err.includes("socket hang up")) {
jest.fn();
} else {
console.dir(err);

View File

@ -3,21 +3,22 @@ let app = null;
describe("Display of modules", function () {
beforeAll(function (done) {
app = helpers.startApplication("tests/configs/modules/display.js", null, done);
app = helpers.startApplication("tests/configs/modules/display.js");
helpers.getDocument(done);
});
afterAll(function () {
helpers.stopApplication(app);
});
it("should show the test header", function () {
elem = document.querySelector("#module_0_helloworld .module-header");
const elem = document.querySelector("#module_0_helloworld .module-header");
expect(elem).not.toBe(null);
// textContent gibt hier lowercase zurück, das uppercase wird durch css realisiert, was daher nicht in textContent landet
expect(elem.textContent).toBe("test_header");
});
it("should show no header if no header text is specified", function () {
elem = document.querySelector("#module_1_helloworld .module-header");
const elem = document.querySelector("#module_1_helloworld .module-header");
expect(elem).not.toBe(null);
expect(elem.textContent).toBe("undefined");
});

View File

@ -0,0 +1,23 @@
const helpers = require("./global-setup");
let app = null;
describe("Position of modules", function () {
beforeAll(function (done) {
app = helpers.startApplication("tests/configs/modules/positions.js");
helpers.getDocument(done, 1000);
});
afterAll(function () {
helpers.stopApplication(app);
});
const positions = ["top_bar", "top_left", "top_center", "top_right", "upper_third", "middle_center", "lower_third", "bottom_left", "bottom_center", "bottom_right", "bottom_bar", "fullscreen_above", "fullscreen_below"];
for (const position of positions) {
const className = position.replace("_", ".");
it("should show text in " + position, function () {
const elem = document.querySelector("." + className);
expect(elem).not.toBe(null);
expect(elem.textContent).toContain("Text in " + position);
});
}
});

View File

@ -1,38 +0,0 @@
const helpers = require("./global-setup");
describe("Display of modules", function () {
helpers.setupTimeout(this);
let app = null;
beforeEach(function () {
return helpers
.startApplication({
args: ["js/electron.js"]
})
.then(function (startedApp) {
app = startedApp;
});
});
afterEach(function () {
return helpers.stopApplication(app);
});
describe("Using helloworld", function () {
beforeAll(function () {
// Set config sample for use in test
process.env.MM_CONFIG_FILE = "tests/configs/modules/display.js";
});
it("should show the test header", async () => {
const elem = await app.client.$("#module_0_helloworld .module-header", 10000);
return expect(await elem.getText("#module_0_helloworld .module-header")).toBe("TEST_HEADER");
});
it("should show no header if no header text is specified", async () => {
const elem = await app.client.$("#module_1_helloworld .module-header", 10000);
return expect(await elem.getText("#module_1_helloworld .module-header")).toBe("");
});
});
});

View File

@ -1,38 +0,0 @@
const helpers = require("./global-setup");
describe("Position of modules", function () {
helpers.setupTimeout(this);
let app = null;
describe("Using helloworld", function () {
afterAll(function () {
return helpers.stopApplication(app);
});
beforeAll(function () {
// Set config sample for use in test
process.env.MM_CONFIG_FILE = "tests/configs/modules/positions.js";
return helpers
.startApplication({
args: ["js/electron.js"]
})
.then(function (startedApp) {
app = startedApp;
});
});
const positions = ["top_bar", "top_left", "top_center", "top_right", "upper_third", "middle_center", "lower_third", "bottom_left", "bottom_center", "bottom_right", "bottom_bar", "fullscreen_above", "fullscreen_below"];
for (const position of positions) {
const className = position.replace("_", ".");
it("should show text in " + position, function () {
return app.client.$("." + className).then((result) => {
return result.getText("." + className).then((text) => {
return expect(text).toContain("Text in " + position);
});
});
});
}
});
});