snapshot e2e

This commit is contained in:
Karsten Hassel 2021-06-08 00:47:40 +02:00
parent 16bbb42b8d
commit 67011c0c32
20 changed files with 97 additions and 102 deletions

View File

@ -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": "<rootDir>/js/node_helper.js",
"logger": "<rootDir>/js/logger.js",
// "logger": "<rootDir>/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": "<rootDir>/node_modules/moment-timezone/moment-timezone.js",
"moment": "<rootDir>/node_modules/moment/moment.js"
}

View File

@ -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);
// });
// });
});

View File

@ -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();
});
});

View File

@ -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);
});

View File

@ -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);
}
};

View File

@ -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";
});

View File

@ -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";
});

View File

@ -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());
});

View File

@ -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";
});

View File

@ -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";
});

View File

@ -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";
});

View File

@ -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";
});

View File

@ -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";
});

View File

@ -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";
});

View File

@ -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";
});

View File

@ -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

View File

@ -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;
});

View File

@ -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(
`<script>var translations = ${JSON.stringify(translations)}; var Log = {log: function(){}};</script>\
<script src="file://${path.join(__dirname, "..", "..", "js", "translator.js")}">`,
@ -181,7 +181,7 @@ describe("Translations", function () {
describe(`Translation keys of ${language}`, function () {
let keys;
before(function (done) {
beforeAll(function (done) {
const dom = new JSDOM(
`<script>var translations = ${JSON.stringify(translations)}; var Log = {log: function(){}};</script>\
<script src="file://${path.join(__dirname, "..", "..", "js", "translator.js")}">`,

View File

@ -12,7 +12,7 @@ describe("Vendors", function () {
let app = null;
before(function () {
beforeAll(function () {
process.env.MM_CONFIG_FILE = "tests/configs/env.js";
return helpers
.startApplication({
@ -23,7 +23,7 @@ describe("Vendors", function () {
});
});
after(function () {
afterAll(function () {
return helpers.stopApplication(app);
});

View File

@ -24,7 +24,7 @@ describe("Check configuration without modules", function () {
return helpers.stopApplication(app);
});
before(function () {
beforeAll(function () {
// Set config sample for use in test
process.env.MM_CONFIG_FILE = "tests/configs/without_modules.js";
});