From 67011c0c32f4edcd5929b03eee0b4f419211d081 Mon Sep 17 00:00:00 2001 From: Karsten Hassel Date: Tue, 8 Jun 2021 00:47:40 +0200 Subject: [PATCH] snapshot e2e --- package.json | 7 ++-- tests/e2e/dev_console.js | 51 +++++++++++++-------------- tests/e2e/env_spec.js | 23 ++++++------ tests/e2e/fonts.js | 4 +-- tests/e2e/global-setup.js | 6 ++-- tests/e2e/ipWhistlist_spec.js | 4 +-- tests/e2e/modules/alert_spec.js | 2 +- tests/e2e/modules/calendar_spec.js | 20 +++++------ tests/e2e/modules/clock_es_spec.js | 8 ++--- tests/e2e/modules/clock_spec.js | 12 +++---- tests/e2e/modules/compliments_spec.js | 8 ++--- tests/e2e/modules/helloworld_spec.js | 4 +-- tests/e2e/modules/newsfeed_spec.js | 6 ++-- tests/e2e/modules/weather_spec.js | 18 +++++----- tests/e2e/modules_display_spec.js | 2 +- tests/e2e/modules_position_spec.js | 4 +-- tests/e2e/port_config.js | 6 ++-- tests/e2e/translations_spec.js | 8 ++--- tests/e2e/vendor_spec.js | 4 +-- tests/e2e/without_modules.js | 2 +- 20 files changed, 97 insertions(+), 102 deletions(-) diff --git a/package.json b/package.json index 880fb3ef..0f1fd8f1 100644 --- a/package.json +++ b/package.json @@ -12,7 +12,7 @@ "postinstall": "npm run install-fonts && echo \"MagicMirror installation finished successfully! \n\"", "test": "NODE_ENV=test mocha tests --recursive", "test:coverage": "NODE_ENV=test nyc --reporter=lcov --reporter=text mocha tests --recursive --timeout=3000", - "test:e2e": "NODE_ENV=test mocha tests/e2e --recursive", + "test:e2e": "NODE_ENV=test jest --testMatch **/tests/e2e/**/*", "test:unit": "NODE_ENV=test jest --testMatch **/tests/unit/**/*", "test:prettier": "prettier . --check", "test:js": "eslint js/**/*.js modules/default/**/*.js clientonly/*.js serveronly/*.js translations/*.js vendor/*.js tests/**/*.js config/* --config .eslintrc.json --quiet", @@ -45,8 +45,6 @@ }, "homepage": "https://magicmirror.builders", "devDependencies": { - "chai": "^4.3.4", - "chai-as-promised": "^7.1.1", "eslint-config-prettier": "^8.3.0", "eslint-plugin-jsdoc": "^35.0.0", "eslint-plugin-prettier": "^3.4.0", @@ -95,7 +93,8 @@ "jest": { "moduleNameMapper": { "node_helper": "/js/node_helper.js", - "logger": "/js/logger.js", + // "logger": "/js/logger.js", <-- only for unit tests, not for e2e + // replace require("chai").expect with expect from jest, see e2e/env_spec.js "moment-timezone": "/node_modules/moment-timezone/moment-timezone.js", "moment": "/node_modules/moment/moment.js" } diff --git a/tests/e2e/dev_console.js b/tests/e2e/dev_console.js index e6400bef..fe5b5976 100644 --- a/tests/e2e/dev_console.js +++ b/tests/e2e/dev_console.js @@ -5,22 +5,17 @@ const describe = global.describe; const it = global.it; describe("Development console tests", function () { - // FIXME: This tests fail and crash another tests - // Suspect problem with window focus - return false; - - /* eslint-disable */ helpers.setupTimeout(this); let app = null; - before(function () { + beforeAll(function () { // Set config sample for use in test process.env.MM_CONFIG_FILE = "tests/configs/env.js"; }); describe("Without 'dev' commandline argument", function () { - before(function () { + beforeAll(function () { return helpers .startApplication({ args: ["js/electron.js"] @@ -30,33 +25,35 @@ describe("Development console tests", function () { }); }); - after(function () { + afterAll(function () { return helpers.stopApplication(app); }); - it("should not open dev console when absent", function () { + it("should not open dev console when absent", async function () { + await app.client.waitUntilWindowLoaded(); return expect(app.browserWindow.isDevToolsOpened()).to.eventually.equal(false); }); }); - describe("With 'dev' commandline argument", function () { - before(function () { - return helpers - .startApplication({ - args: ["js/electron.js", "dev"] - }) - .then(function (startedApp) { - app = startedApp; - }); - }); + // describe("With 'dev' commandline argument", function () { + // beforeAll(function () { + // return helpers + // .startApplication({ + // args: ["js/electron.js", "dev"] + // }) + // .then(function (startedApp) { + // app = startedApp; + // }); + // }); - after(function () { - return helpers.stopApplication(app); - }); + // afterAll(function () { + // return helpers.stopApplication(app); + // }); - it("should open dev console when provided", function () { - return expect(app.browserWindow.isDevToolsOpened()).to.eventually.equal(true); - }); - }); - /* eslint-enable */ + // it("should open dev console when provided", async function () { + // expect(await app.client.getWindowCount()).to.equal(2); + // await app.client.waitUntilWindowLoaded(); + // return expect(app.browserWindow.isDevToolsOpened()).to.eventually.equal(true); + // }); + // }); }); diff --git a/tests/e2e/env_spec.js b/tests/e2e/env_spec.js index 1ec4a086..8d9da80d 100644 --- a/tests/e2e/env_spec.js +++ b/tests/e2e/env_spec.js @@ -1,6 +1,5 @@ const helpers = require("./global-setup"); const fetch = require("node-fetch"); -const expect = require("chai").expect; const describe = global.describe; const it = global.it; @@ -12,7 +11,7 @@ describe("Electron app environment", function () { let app = null; - before(function () { + beforeAll(function () { // Set config sample for use in test process.env.MM_CONFIG_FILE = "tests/configs/env.js"; }); @@ -34,27 +33,27 @@ describe("Electron app environment", function () { it("should open a browserwindow", async function () { await app.client.waitUntilWindowLoaded(); app.browserWindow.focus(); - expect(await app.client.getWindowCount()).to.equal(1); - expect(await app.browserWindow.isMinimized()).to.be.false; - expect(await app.browserWindow.isDevToolsOpened()).to.be.false; - expect(await app.browserWindow.isVisible()).to.be.true; - expect(await app.browserWindow.isFocused()).to.be.true; + 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).to.be.above(0); - expect(bounds.height).to.be.above(0); - expect(await app.browserWindow.getTitle()).to.equal("MagicMirror²"); + expect(bounds.width).toBeGreaterThan(0); + expect(bounds.height).toBeGreaterThan(0); + expect(await app.browserWindow.getTitle()).toBe("MagicMirror²"); }); it("get request from http://localhost:8080 should return 200", function (done) { fetch("http://localhost:8080").then((res) => { - expect(res.status).to.equal(200); + expect(res.status).toBe(200); done(); }); }); it("get request from http://localhost:8080/nothing should return 404", function (done) { fetch("http://localhost:8080/nothing").then((res) => { - expect(res.status).to.equal(404); + expect(res.status).toBe(404); done(); }); }); diff --git a/tests/e2e/fonts.js b/tests/e2e/fonts.js index d6d65c0b..8848cfcb 100644 --- a/tests/e2e/fonts.js +++ b/tests/e2e/fonts.js @@ -21,7 +21,7 @@ describe("All font files from roboto.css should be downloadable", function () { match = regex.exec(fileContent); } - before(function () { + beforeAll(function () { // Set config sample for use in test process.env.MM_CONFIG_FILE = "tests/configs/without_modules.js"; @@ -34,7 +34,7 @@ describe("All font files from roboto.css should be downloadable", function () { }); }); - after(function () { + afterAll(function () { return helpers.stopApplication(app); }); diff --git a/tests/e2e/global-setup.js b/tests/e2e/global-setup.js index 801c61e5..0f5ad57e 100644 --- a/tests/e2e/global-setup.js +++ b/tests/e2e/global-setup.js @@ -10,7 +10,7 @@ const chai = require("chai"); const chaiAsPromised = require("chai-as-promised"); const path = require("path"); -global.before(function () { +global.beforeAll(function () { chai.should(); chai.use(chaiAsPromised); }); @@ -26,9 +26,9 @@ exports.getElectronPath = function () { // Set timeout - if this is run within Travis, increase timeout exports.setupTimeout = function (test) { if (process.env.CI) { - test.timeout(30000); + jest.setTimeout(30000); } else { - test.timeout(10000); + jest.setTimeout(10000); } }; diff --git a/tests/e2e/ipWhistlist_spec.js b/tests/e2e/ipWhistlist_spec.js index 1c259f1e..64d7ebe6 100644 --- a/tests/e2e/ipWhistlist_spec.js +++ b/tests/e2e/ipWhistlist_spec.js @@ -27,7 +27,7 @@ describe("ipWhitelist directive configuration", function () { }); describe("Set ipWhitelist without access", function () { - before(function () { + beforeAll(function () { // Set config sample for use in test process.env.MM_CONFIG_FILE = "tests/configs/noIpWhiteList.js"; }); @@ -41,7 +41,7 @@ describe("ipWhitelist directive configuration", function () { }); describe("Set ipWhitelist []", function () { - before(function () { + beforeAll(function () { // Set config sample for use in test process.env.MM_CONFIG_FILE = "tests/configs/empty_ipWhiteList.js"; }); diff --git a/tests/e2e/modules/alert_spec.js b/tests/e2e/modules/alert_spec.js index 515001bf..90322d26 100644 --- a/tests/e2e/modules/alert_spec.js +++ b/tests/e2e/modules/alert_spec.js @@ -25,7 +25,7 @@ describe("Alert module", function () { }); describe("Default configuration", function () { - before(function () { + beforeAll(function () { // Set config sample for use in test process.env.MM_CONFIG_FILE = "tests/configs/modules/alert/default.js"; }); diff --git a/tests/e2e/modules/calendar_spec.js b/tests/e2e/modules/calendar_spec.js index 097ce220..d2c2ece9 100644 --- a/tests/e2e/modules/calendar_spec.js +++ b/tests/e2e/modules/calendar_spec.js @@ -27,7 +27,7 @@ describe("Calendar module", function () { }); describe("Default configuration", function () { - before(function () { + beforeAll(function () { // Set config sample for use in test process.env.MM_CONFIG_FILE = "tests/configs/modules/calendar/default.js"; }); @@ -46,7 +46,7 @@ describe("Calendar module", function () { }); describe("Custom configuration", function () { - before(function () { + beforeAll(function () { // Set config sample for use in test process.env.MM_CONFIG_FILE = "tests/configs/modules/calendar/custom.js"; }); @@ -77,7 +77,7 @@ describe("Calendar module", function () { }); describe("Recurring event", function () { - before(function () { + beforeAll(function () { // Set config sample for use in test process.env.MM_CONFIG_FILE = "tests/configs/modules/calendar/recurring.js"; }); @@ -90,13 +90,13 @@ describe("Calendar module", function () { }); describe("Changed port", function () { - before(function () { + beforeAll(function () { serverBasicAuth.listen(8010); // Set config sample for use in test process.env.MM_CONFIG_FILE = "tests/configs/modules/calendar/changed-port.js"; }); - after(function (done) { + afterAll(function (done) { serverBasicAuth.close(done()); }); @@ -106,7 +106,7 @@ describe("Calendar module", function () { }); describe("Basic auth", function () { - before(function () { + beforeAll(function () { // Set config sample for use in test process.env.MM_CONFIG_FILE = "tests/configs/modules/calendar/basic-auth.js"; }); @@ -117,7 +117,7 @@ describe("Calendar module", function () { }); describe("Basic auth by default", function () { - before(function () { + beforeAll(function () { // Set config sample for use in test process.env.MM_CONFIG_FILE = "tests/configs/modules/calendar/auth-default.js"; }); @@ -128,7 +128,7 @@ describe("Calendar module", function () { }); describe("Basic auth backward compatibility configuration: DEPRECATED", function () { - before(function () { + beforeAll(function () { // Set config sample for use in test process.env.MM_CONFIG_FILE = "tests/configs/modules/calendar/old-basic-auth.js"; }); @@ -139,13 +139,13 @@ describe("Calendar module", function () { }); describe("Fail Basic auth", function () { - before(function () { + beforeAll(function () { serverBasicAuth.listen(8020); // Set config sample for use in test process.env.MM_CONFIG_FILE = "tests/configs/modules/calendar/fail-basic-auth.js"; }); - after(function (done) { + afterAll(function (done) { serverBasicAuth.close(done()); }); diff --git a/tests/e2e/modules/clock_es_spec.js b/tests/e2e/modules/clock_es_spec.js index 5ef491a3..a2622fb6 100644 --- a/tests/e2e/modules/clock_es_spec.js +++ b/tests/e2e/modules/clock_es_spec.js @@ -25,7 +25,7 @@ describe("Clock set to spanish language module", function () { }); describe("with default 24hr clock config", function () { - before(function () { + beforeAll(function () { // Set config sample for use in test process.env.MM_CONFIG_FILE = "tests/configs/modules/clock/es/clock_24hr.js"; }); @@ -44,7 +44,7 @@ describe("Clock set to spanish language module", function () { }); describe("with default 12hr clock config", function () { - before(function () { + beforeAll(function () { // Set config sample for use in test process.env.MM_CONFIG_FILE = "tests/configs/modules/clock/es/clock_12hr.js"; }); @@ -63,7 +63,7 @@ describe("Clock set to spanish language module", function () { }); describe("with showPeriodUpper config enabled", function () { - before(function () { + beforeAll(function () { // Set config sample for use in test process.env.MM_CONFIG_FILE = "tests/configs/modules/clock/es/clock_showPeriodUpper.js"; }); @@ -76,7 +76,7 @@ describe("Clock set to spanish language module", function () { }); describe("with showWeek config enabled", function () { - before(function () { + beforeAll(function () { // Set config sample for use in test process.env.MM_CONFIG_FILE = "tests/configs/modules/clock/es/clock_showWeek.js"; }); diff --git a/tests/e2e/modules/clock_spec.js b/tests/e2e/modules/clock_spec.js index 27536dc2..ff614cf7 100644 --- a/tests/e2e/modules/clock_spec.js +++ b/tests/e2e/modules/clock_spec.js @@ -27,7 +27,7 @@ describe("Clock module", function () { }); describe("with default 24hr clock config", function () { - before(function () { + beforeAll(function () { // Set config sample for use in test process.env.MM_CONFIG_FILE = "tests/configs/modules/clock/clock_24hr.js"; }); @@ -46,7 +46,7 @@ describe("Clock module", function () { }); describe("with default 12hr clock config", function () { - before(function () { + beforeAll(function () { // Set config sample for use in test process.env.MM_CONFIG_FILE = "tests/configs/modules/clock/clock_12hr.js"; }); @@ -65,7 +65,7 @@ describe("Clock module", function () { }); describe("with showPeriodUpper config enabled", function () { - before(function () { + beforeAll(function () { // Set config sample for use in test process.env.MM_CONFIG_FILE = "tests/configs/modules/clock/clock_showPeriodUpper.js"; }); @@ -78,7 +78,7 @@ describe("Clock module", function () { }); describe("with displaySeconds config disabled", function () { - before(function () { + beforeAll(function () { // Set config sample for use in test process.env.MM_CONFIG_FILE = "tests/configs/modules/clock/clock_displaySeconds_false.js"; }); @@ -91,7 +91,7 @@ describe("Clock module", function () { }); describe("with showWeek config enabled", function () { - before(function () { + beforeAll(function () { // Set config sample for use in test process.env.MM_CONFIG_FILE = "tests/configs/modules/clock/clock_showWeek.js"; }); @@ -111,7 +111,7 @@ describe("Clock module", function () { }); describe("with analog clock face enabled", function () { - before(function () { + beforeAll(function () { // Set config sample for use in test process.env.MM_CONFIG_FILE = "tests/configs/modules/clock/clock_analog.js"; }); diff --git a/tests/e2e/modules/compliments_spec.js b/tests/e2e/modules/compliments_spec.js index 1eed2b8d..067bab1c 100644 --- a/tests/e2e/modules/compliments_spec.js +++ b/tests/e2e/modules/compliments_spec.js @@ -26,7 +26,7 @@ describe("Compliments module", function () { }); describe("parts of days", function () { - before(function () { + beforeAll(function () { // Set config sample for use in test process.env.MM_CONFIG_FILE = "tests/configs/modules/compliments/compliments_parts_day.js"; }); @@ -67,7 +67,7 @@ describe("Compliments module", function () { describe("Feature anytime in compliments module", function () { describe("Set anytime and empty compliments for morning, evening and afternoon ", function () { - before(function () { + beforeAll(function () { // Set config sample for use in test process.env.MM_CONFIG_FILE = "tests/configs/modules/compliments/compliments_anytime.js"; }); @@ -81,7 +81,7 @@ describe("Compliments module", function () { }); describe("Only anytime present in configuration compliments", function () { - before(function () { + beforeAll(function () { // Set config sample for use in test process.env.MM_CONFIG_FILE = "tests/configs/modules/compliments/compliments_only_anytime.js"; }); @@ -97,7 +97,7 @@ describe("Compliments module", function () { describe("Feature date in compliments module", function () { describe("Set date and empty compliments for anytime, morning, evening and afternoon", function () { - before(function () { + beforeAll(function () { // Set config sample for use in test process.env.MM_CONFIG_FILE = "tests/configs/modules/compliments/compliments_date.js"; }); diff --git a/tests/e2e/modules/helloworld_spec.js b/tests/e2e/modules/helloworld_spec.js index 6a744e51..a1ea7c44 100644 --- a/tests/e2e/modules/helloworld_spec.js +++ b/tests/e2e/modules/helloworld_spec.js @@ -25,7 +25,7 @@ describe("Test helloworld module", function () { }); describe("helloworld set config text", function () { - before(function () { + beforeAll(function () { // Set config sample for use in test process.env.MM_CONFIG_FILE = "tests/configs/modules/helloworld/helloworld.js"; }); @@ -37,7 +37,7 @@ describe("Test helloworld module", function () { }); describe("helloworld default config text", function () { - before(function () { + beforeAll(function () { // Set config sample for use in test process.env.MM_CONFIG_FILE = "tests/configs/modules/helloworld/helloworld_default.js"; }); diff --git a/tests/e2e/modules/newsfeed_spec.js b/tests/e2e/modules/newsfeed_spec.js index fc8c7122..7ca67a99 100644 --- a/tests/e2e/modules/newsfeed_spec.js +++ b/tests/e2e/modules/newsfeed_spec.js @@ -26,7 +26,7 @@ describe("Newsfeed module", function () { }); describe("Default configuration", function () { - before(function () { + beforeAll(function () { process.env.MM_CONFIG_FILE = "tests/configs/modules/newsfeed/default.js"; }); @@ -46,7 +46,7 @@ describe("Newsfeed module", function () { }); describe("Custom configuration", function () { - before(function () { + beforeAll(function () { process.env.MM_CONFIG_FILE = "tests/configs/modules/newsfeed/prohibited_words.js"; }); @@ -62,7 +62,7 @@ describe("Newsfeed module", function () { }); describe("Invalid configuration", function () { - before(function () { + beforeAll(function () { process.env.MM_CONFIG_FILE = "tests/configs/modules/newsfeed/incorrect_url.js"; }); diff --git a/tests/e2e/modules/weather_spec.js b/tests/e2e/modules/weather_spec.js index 70c88512..dfba259d 100644 --- a/tests/e2e/modules/weather_spec.js +++ b/tests/e2e/modules/weather_spec.js @@ -42,12 +42,12 @@ describe("Weather module", function () { describe("Current weather", function () { let template; - before(function () { + beforeAll(function () { template = fs.readFileSync(path.join(__dirname, "..", "..", "..", "modules", "default", "weather", "current.njk"), "utf8"); }); describe("Default configuration", function () { - before(function () { + beforeAll(function () { process.env.MM_CONFIG_FILE = "tests/configs/modules/weather/currentweather_default.js"; }); @@ -94,7 +94,7 @@ describe("Weather module", function () { }); describe("Compliments Integration", function () { - before(function () { + beforeAll(function () { process.env.MM_CONFIG_FILE = "tests/configs/modules/weather/currentweather_compliments.js"; }); @@ -107,7 +107,7 @@ describe("Weather module", function () { }); describe("Configuration Options", function () { - before(function () { + beforeAll(function () { process.env.MM_CONFIG_FILE = "tests/configs/modules/weather/currentweather_options.js"; }); @@ -144,7 +144,7 @@ describe("Weather module", function () { }); describe("Current weather units", function () { - before(function () { + beforeAll(function () { process.env.MM_CONFIG_FILE = "tests/configs/modules/weather/currentweather_units.js"; }); @@ -185,12 +185,12 @@ describe("Weather module", function () { describe("Weather Forecast", function () { let template; - before(function () { + beforeAll(function () { template = fs.readFileSync(path.join(__dirname, "..", "..", "..", "modules", "default", "weather", "forecast.njk"), "utf8"); }); describe("Default configuration", function () { - before(function () { + beforeAll(function () { process.env.MM_CONFIG_FILE = "tests/configs/modules/weather/forecastweather_default.js"; }); @@ -254,7 +254,7 @@ describe("Weather module", function () { }); describe("Configuration Options", function () { - before(function () { + beforeAll(function () { process.env.MM_CONFIG_FILE = "tests/configs/modules/weather/forecastweather_options.js"; }); @@ -276,7 +276,7 @@ describe("Weather module", function () { }); describe("Forecast weather units", function () { - before(function () { + beforeAll(function () { process.env.MM_CONFIG_FILE = "tests/configs/modules/weather/forecastweather_units.js"; }); diff --git a/tests/e2e/modules_display_spec.js b/tests/e2e/modules_display_spec.js index 5ae06b6f..bea5889a 100644 --- a/tests/e2e/modules_display_spec.js +++ b/tests/e2e/modules_display_spec.js @@ -23,7 +23,7 @@ describe("Display of modules", function () { }); describe("Using helloworld", function () { - before(function () { + beforeAll(function () { // Set config sample for use in test process.env.MM_CONFIG_FILE = "tests/configs/modules/display.js"; }); diff --git a/tests/e2e/modules_position_spec.js b/tests/e2e/modules_position_spec.js index 7e8662be..6378bf2d 100644 --- a/tests/e2e/modules_position_spec.js +++ b/tests/e2e/modules_position_spec.js @@ -9,11 +9,11 @@ describe("Position of modules", function () { let app = null; describe("Using helloworld", function () { - after(function () { + afterAll(function () { return helpers.stopApplication(app); }); - before(function () { + beforeAll(function () { // Set config sample for use in test process.env.MM_CONFIG_FILE = "tests/configs/modules/positions.js"; return helpers diff --git a/tests/e2e/port_config.js b/tests/e2e/port_config.js index e32f577b..da255cd7 100644 --- a/tests/e2e/port_config.js +++ b/tests/e2e/port_config.js @@ -27,7 +27,7 @@ describe("port directive configuration", function () { }); describe("Set port 8090", function () { - before(function () { + beforeAll(function () { // Set config sample for use in this test process.env.MM_CONFIG_FILE = "tests/configs/port_8090.js"; }); @@ -41,13 +41,13 @@ describe("port directive configuration", function () { }); describe("Set port 8100 on environment variable MM_PORT", function () { - before(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"; }); - after(function () { + afterAll(function () { delete process.env.MM_PORT; }); diff --git a/tests/e2e/translations_spec.js b/tests/e2e/translations_spec.js index 5f0d6053..f19d8a6e 100644 --- a/tests/e2e/translations_spec.js +++ b/tests/e2e/translations_spec.js @@ -12,7 +12,7 @@ const sinon = require("sinon"); describe("Translations", function () { let server; - before(function () { + beforeAll(function () { const app = express(); app.use(helmet()); app.use(function (req, res, next) { @@ -24,7 +24,7 @@ describe("Translations", function () { server = app.listen(3000); }); - after(function () { + afterAll(function () { server.close(); }); @@ -157,7 +157,7 @@ describe("Translations", function () { describe("Same keys", function () { let base; - before(function (done) { + beforeAll(function (done) { const dom = new JSDOM( `\ \