diff --git a/.github/workflows/node-ci.js.yml b/.github/workflows/node-ci.js.yml index 3178607d..3a7391c2 100644 --- a/.github/workflows/node-ci.js.yml +++ b/.github/workflows/node-ci.js.yml @@ -23,7 +23,6 @@ jobs: with: node-version: ${{ matrix.node-version }} - run: | - node -v Xvfb :99 -screen 0 1024x768x16 & export DISPLAY=:99 npm install @@ -32,3 +31,4 @@ jobs: npm run test:css npm run test:unit npm run test:e2e + npm run test:electron diff --git a/package.json b/package.json index 92350f0c..8bda06d8 100644 --- a/package.json +++ b/package.json @@ -12,6 +12,7 @@ "postinstall": "npm run install-fonts && echo \"MagicMirror installation finished successfully! \n\"", "test": "NODE_ENV=test jest -i --forceExit", "test:coverage": "NODE_ENV=test nyc --reporter=lcov --reporter=text jest -i --forceExit", + "test:electron": "NODE_ENV=test jest --selectProjects electron -i --forceExit", "test:e2e": "NODE_ENV=test jest --selectProjects e2e -i --forceExit", "test:unit": "NODE_ENV=test jest --selectProjects unit -i --forceExit", "test:prettier": "prettier . --check", @@ -106,15 +107,26 @@ "/tests/unit/mocks" ] }, + { + "displayName": "electron", + "testMatch": [ + "**/tests/electron/**/*.[jt]s?(x)" + ], + "testPathIgnorePatterns": [ + "/tests/electron/modules/mocks", + "/tests/electron/global-setup.js", + "/tests/electron/modules/basic-auth.js" + ] + }, { "displayName": "e2e", "testMatch": [ "**/tests/e2e/**/*.[jt]s?(x)" ], - "testPathIgnorePatterns": [ - "/tests/e2e/modules/mocks", - "/tests/e2e/global-setup.js" - ] + "moduleNameMapper": { + "logger": "/js/logger.js", + "node_helper": "/js/node_helper.js" + } } ] } diff --git a/tests/e2e/env_spec.js b/tests/e2e/env_spec.js index 706274a2..28a0294b 100644 --- a/tests/e2e/env_spec.js +++ b/tests/e2e/env_spec.js @@ -1,42 +1,15 @@ -const helpers = require("./global-setup"); const fetch = require("node-fetch"); +const app = require("../../js/app.js"); describe("Electron app environment", function () { - helpers.setupTimeout(this); - - let app = null; - beforeAll(function () { - // Set config sample for use in test process.env.MM_CONFIG_FILE = "tests/configs/env.js"; + + app.start(); }); - beforeEach(function () { - return helpers - .startApplication({ - args: ["js/electron.js"] - }) - .then(function (startedApp) { - app = startedApp; - }); - }); - - afterEach(function () { - return helpers.stopApplication(app); - }); - - it("should open a browserwindow", async function () { - await app.client.waitUntilWindowLoaded(); - app.browserWindow.focus(); - expect(await app.client.getWindowCount()).toBe(1); - expect(await app.browserWindow.isMinimized()).toBe(false); - expect(await app.browserWindow.isDevToolsOpened()).toBe(false); - expect(await app.browserWindow.isVisible()).toBe(true); - expect(await app.browserWindow.isFocused()).toBe(true); - const bounds = await app.browserWindow.getBounds(); - expect(bounds.width).toBeGreaterThan(0); - expect(bounds.height).toBeGreaterThan(0); - expect(await app.browserWindow.getTitle()).toBe("MagicMirror²"); + afterAll(function () { + app.stop(); }); it("get request from http://localhost:8080 should return 200", function (done) { diff --git a/tests/e2e/fonts.js b/tests/e2e/fonts.js index b1459294..d8b8e0a7 100644 --- a/tests/e2e/fonts.js +++ b/tests/e2e/fonts.js @@ -1,10 +1,7 @@ -const helpers = require("./global-setup"); const fetch = require("node-fetch"); +const app = require("../../js/app.js"); describe("All font files from roboto.css should be downloadable", function () { - helpers.setupTimeout(this); - - let app; const fontFiles = []; // Statements below filters out all 'url' lines in the CSS file const fileContent = require("fs").readFileSync(__dirname + "/../../fonts/roboto.css", "utf8"); @@ -18,20 +15,13 @@ describe("All font files from roboto.css should be downloadable", function () { } beforeAll(function () { - // Set config sample for use in test process.env.MM_CONFIG_FILE = "tests/configs/without_modules.js"; - return helpers - .startApplication({ - args: ["js/electron.js"] - }) - .then(function (startedApp) { - app = startedApp; - }); + app.start(); }); afterAll(function () { - return helpers.stopApplication(app); + app.stop(); }); test.each(fontFiles)("should return 200 HTTP code for file '%s'", (fontFile, done) => { diff --git a/tests/e2e/ipWhitelist_spec.js b/tests/e2e/ipWhitelist_spec.js index 3406e0e7..99bad61a 100644 --- a/tests/e2e/ipWhitelist_spec.js +++ b/tests/e2e/ipWhitelist_spec.js @@ -1,23 +1,13 @@ -const helpers = require("./global-setup"); const fetch = require("node-fetch"); +const app = require("../../js/app.js"); describe("ipWhitelist directive configuration", function () { - helpers.setupTimeout(this); - - let app = null; - - beforeEach(function () { - return helpers - .startApplication({ - args: ["js/electron.js"] - }) - .then(function (startedApp) { - app = startedApp; - }); + beforeAll(function () { + app.start(); }); - afterEach(function () { - return helpers.stopApplication(app); + afterAll(function () { + app.stop(); }); describe("Set ipWhitelist without access", function () { diff --git a/tests/e2e/port_config.js b/tests/e2e/port_config.js index da489414..7e960992 100644 --- a/tests/e2e/port_config.js +++ b/tests/e2e/port_config.js @@ -1,31 +1,18 @@ -const helpers = require("./global-setup"); const fetch = require("node-fetch"); +const app = require("../../js/app.js"); describe("port directive configuration", function () { - helpers.setupTimeout(this); + beforeAll(function () { + process.env.MM_CONFIG_FILE = "tests/configs/port_8090.js"; - let app = null; - - beforeEach(function () { - return helpers - .startApplication({ - args: ["js/electron.js"] - }) - .then(function (startedApp) { - app = startedApp; - }); + app.start(); }); - afterEach(function () { - return helpers.stopApplication(app); + afterAll(function () { + app.stop(); }); describe("Set port 8090", function () { - beforeAll(function () { - // Set config sample for use in this test - process.env.MM_CONFIG_FILE = "tests/configs/port_8090.js"; - }); - it("should return 200", function (done) { fetch("http://localhost:8090").then((res) => { expect(res.status).toBe(200); @@ -37,8 +24,6 @@ describe("port directive configuration", function () { describe("Set port 8100 on environment variable MM_PORT", function () { beforeAll(function () { process.env.MM_PORT = 8100; - // Set config sample for use in this test - process.env.MM_CONFIG_FILE = "tests/configs/port_8090.js"; }); afterAll(function () { diff --git a/tests/e2e/vendor_spec.js b/tests/e2e/vendor_spec.js index 9fcb9aeb..2b619dd0 100644 --- a/tests/e2e/vendor_spec.js +++ b/tests/e2e/vendor_spec.js @@ -1,24 +1,15 @@ -const helpers = require("./global-setup"); const fetch = require("node-fetch"); +const app = require("../../js/app.js"); describe("Vendors", function () { - helpers.setupTimeout(this); - - let app = null; - beforeAll(function () { process.env.MM_CONFIG_FILE = "tests/configs/env.js"; - return helpers - .startApplication({ - args: ["js/electron.js"] - }) - .then(function (startedApp) { - app = startedApp; - }); + + app.start(); }); afterAll(function () { - return helpers.stopApplication(app); + app.stop(); }); describe("Get list vendors", function () { diff --git a/tests/e2e/dev_console.js b/tests/electron/dev_console.js similarity index 100% rename from tests/e2e/dev_console.js rename to tests/electron/dev_console.js diff --git a/tests/electron/env_spec.js b/tests/electron/env_spec.js new file mode 100644 index 00000000..46efc719 --- /dev/null +++ b/tests/electron/env_spec.js @@ -0,0 +1,40 @@ +const helpers = require("./global-setup"); + +describe("Electron app environment", function () { + helpers.setupTimeout(this); + + let app = null; + + beforeAll(function () { + // Set config sample for use in test + process.env.MM_CONFIG_FILE = "tests/configs/env.js"; + }); + + beforeEach(function () { + return helpers + .startApplication({ + args: ["js/electron.js"] + }) + .then(function (startedApp) { + app = startedApp; + }); + }); + + afterEach(function () { + return helpers.stopApplication(app); + }); + + it("should open a browserwindow", async function () { + await app.client.waitUntilWindowLoaded(); + app.browserWindow.focus(); + expect(await app.client.getWindowCount()).toBe(1); + expect(await app.browserWindow.isMinimized()).toBe(false); + expect(await app.browserWindow.isDevToolsOpened()).toBe(false); + expect(await app.browserWindow.isVisible()).toBe(true); + expect(await app.browserWindow.isFocused()).toBe(true); + const bounds = await app.browserWindow.getBounds(); + expect(bounds.width).toBeGreaterThan(0); + expect(bounds.height).toBeGreaterThan(0); + expect(await app.browserWindow.getTitle()).toBe("MagicMirror²"); + }); +}); diff --git a/tests/e2e/global-setup.js b/tests/electron/global-setup.js similarity index 100% rename from tests/e2e/global-setup.js rename to tests/electron/global-setup.js diff --git a/tests/e2e/modules/alert_spec.js b/tests/electron/modules/alert_spec.js similarity index 100% rename from tests/e2e/modules/alert_spec.js rename to tests/electron/modules/alert_spec.js diff --git a/tests/servers/basic-auth.js b/tests/electron/modules/basic-auth.js similarity index 100% rename from tests/servers/basic-auth.js rename to tests/electron/modules/basic-auth.js diff --git a/tests/e2e/modules/calendar_spec.js b/tests/electron/modules/calendar_spec.js similarity index 98% rename from tests/e2e/modules/calendar_spec.js rename to tests/electron/modules/calendar_spec.js index 980eca58..b6420e83 100644 --- a/tests/e2e/modules/calendar_spec.js +++ b/tests/electron/modules/calendar_spec.js @@ -1,5 +1,5 @@ const helpers = require("../global-setup"); -const serverBasicAuth = require("../../servers/basic-auth.js"); +const serverBasicAuth = require("./basic-auth.js"); describe("Calendar module", function () { helpers.setupTimeout(this); diff --git a/tests/e2e/modules/clock_es_spec.js b/tests/electron/modules/clock_es_spec.js similarity index 100% rename from tests/e2e/modules/clock_es_spec.js rename to tests/electron/modules/clock_es_spec.js diff --git a/tests/e2e/modules/clock_spec.js b/tests/electron/modules/clock_spec.js similarity index 100% rename from tests/e2e/modules/clock_spec.js rename to tests/electron/modules/clock_spec.js diff --git a/tests/e2e/modules/compliments_spec.js b/tests/electron/modules/compliments_spec.js similarity index 100% rename from tests/e2e/modules/compliments_spec.js rename to tests/electron/modules/compliments_spec.js diff --git a/tests/e2e/modules/helloworld_spec.js b/tests/electron/modules/helloworld_spec.js similarity index 100% rename from tests/e2e/modules/helloworld_spec.js rename to tests/electron/modules/helloworld_spec.js diff --git a/tests/e2e/modules/mocks/index.js b/tests/electron/modules/mocks/index.js similarity index 100% rename from tests/e2e/modules/mocks/index.js rename to tests/electron/modules/mocks/index.js diff --git a/tests/e2e/modules/mocks/weather_current.js b/tests/electron/modules/mocks/weather_current.js similarity index 100% rename from tests/e2e/modules/mocks/weather_current.js rename to tests/electron/modules/mocks/weather_current.js diff --git a/tests/e2e/modules/mocks/weather_forecast.js b/tests/electron/modules/mocks/weather_forecast.js similarity index 100% rename from tests/e2e/modules/mocks/weather_forecast.js rename to tests/electron/modules/mocks/weather_forecast.js diff --git a/tests/e2e/modules/newsfeed_spec.js b/tests/electron/modules/newsfeed_spec.js similarity index 100% rename from tests/e2e/modules/newsfeed_spec.js rename to tests/electron/modules/newsfeed_spec.js diff --git a/tests/e2e/modules/weather_spec.js b/tests/electron/modules/weather_spec.js similarity index 100% rename from tests/e2e/modules/weather_spec.js rename to tests/electron/modules/weather_spec.js diff --git a/tests/e2e/modules_display_spec.js b/tests/electron/modules_display_spec.js similarity index 100% rename from tests/e2e/modules_display_spec.js rename to tests/electron/modules_display_spec.js diff --git a/tests/e2e/modules_position_spec.js b/tests/electron/modules_position_spec.js similarity index 100% rename from tests/e2e/modules_position_spec.js rename to tests/electron/modules_position_spec.js diff --git a/tests/e2e/translations_spec.js b/tests/electron/translations_spec.js similarity index 100% rename from tests/e2e/translations_spec.js rename to tests/electron/translations_spec.js diff --git a/tests/e2e/without_modules.js b/tests/electron/without_modules.js similarity index 100% rename from tests/e2e/without_modules.js rename to tests/electron/without_modules.js