diff --git a/.github/workflows/node-ci.js.yml b/.github/workflows/node-ci.js.yml index 3a7391c2..258cf83d 100644 --- a/.github/workflows/node-ci.js.yml +++ b/.github/workflows/node-ci.js.yml @@ -26,6 +26,7 @@ jobs: Xvfb :99 -screen 0 1024x768x16 & export DISPLAY=:99 npm install + touch css/custom.css npm run test:prettier npm run test:js npm run test:css diff --git a/tests/e2e/global-setup.js b/tests/e2e/global-setup.js index 1f9bce3b..a8b0278f 100644 --- a/tests/e2e/global-setup.js +++ b/tests/e2e/global-setup.js @@ -1,3 +1,5 @@ +const jsdom = require("jsdom"); + exports.startApplication = function (configFilename, exec) { jest.resetModules(); // Set config sample for use in test @@ -14,3 +16,12 @@ 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/mock-console.js b/tests/e2e/mock-console.js index 8cc246f8..a1ccfa55 100644 --- a/tests/e2e/mock-console.js +++ b/tests/e2e/mock-console.js @@ -1,14 +1,16 @@ function myError(err) { - //console.dir(err); - if (err.includes("ECONNREFUSED")) { jest.fn() } else { console.dir(err) }; -}; + if (err.includes("ECONNREFUSED")) { + jest.fn(); + } else { + console.dir(err); + } +} global.console = { - log: jest.fn(), - dir: console.dir, - error: myError, -// error: console.error, - warn: console.warn, - info: jest.fn(), - debug: console.debug + log: jest.fn(), + dir: console.dir, + error: myError, + warn: console.warn, + info: jest.fn(), + debug: console.debug }; diff --git a/tests/e2e/modules.js b/tests/e2e/modules.js deleted file mode 100644 index 227fd98f..00000000 --- a/tests/e2e/modules.js +++ /dev/null @@ -1,45 +0,0 @@ -const jsdom = require("jsdom"); -// const fetch = require("node-fetch"); -const helpers = require("./global-setup"); -let app = null; - -describe("Display of modules", function () { - beforeAll(function () { - // todo: require is not defined ... - // jest.mock("logger"); - app = helpers.startApplication("tests/configs/modules/display.js"); - // app = helpers.startApplication("config/config.js"); - }); - afterAll(function () { - helpers.stopApplication(app); - }); - - it("should show the test header", function (done) { - jsdom.JSDOM.fromURL("http://localhost:8080", { resources: "usable", runScripts: "dangerously" }).then((dom) => { - // console.log(dom.serialize()); - dom.window.onload = function () { - const doc = dom.window.document; - let elem = doc.querySelector("title"); - expect(elem).not.toBe(null); - expect(elem.textContent).toBe("MagicMirror²"); -/* - const children = doc.body.getElementsByTagName("*"); - for (var i = 0, length = children.length; i < length; i++) { - child = children[i]; - if (child.id !== "") console.dir(child.id); - } -*/ - elem = doc.querySelector("#module_0_helloworld .module-header"); - expect(elem).not.toBe(null); - expect(elem.textContent).toBe("test_header"); - //result ist leider lowercase wegen fehlendem css, siehe https://stackoverflow.com/questions/10318330/how-do-you-add-stylesheets-to-jsdom - elem = doc.querySelector("#module_1_helloworld .module-header"); - expect(elem).not.toBe(null); - expect(elem.textContent).toBe("undefined"); - - //dom.window.close(); - done(); - }; - }); - }); -}); diff --git a/tests/e2e/modules_display_spec.js b/tests/e2e/modules_display_spec.js new file mode 100644 index 00000000..1264ad5a --- /dev/null +++ b/tests/e2e/modules_display_spec.js @@ -0,0 +1,25 @@ +const helpers = require("./global-setup"); +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); + }); + afterAll(function () { + helpers.stopApplication(app); + }); + + it("should show the test header", function () { + elem = document.querySelector("#module_0_helloworld .module-header"); + expect(elem).not.toBe(null); + expect(elem.textContent).toBe("test_header"); + //result ist leider lowercase wegen fehlendem css, siehe https://stackoverflow.com/questions/10318330/how-do-you-add-stylesheets-to-jsdom + }); + + it("should show no header if no header text is specified", function () { + elem = document.querySelector("#module_1_helloworld .module-header"); + expect(elem).not.toBe(null); + expect(elem.textContent).toBe("undefined"); + }); +});