Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ _This release is scheduled to be released on 2023-01-01._

### Updated

- updated e2e tests (moved `done()` in helper functions) and use es6 syntax in all tests

### Fixed

## [2.21.0] - 2022-10-01
Expand Down
2 changes: 1 addition & 1 deletion tests/configs/default.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* By Rodrigo Ramírez Norambuena https://rodrigoramirez.com
* MIT Licensed.
*/
exports.configFactory = function (options) {
exports.configFactory = (options) => {
return Object.assign(
{
electronOptions: {
Expand Down
2 changes: 1 addition & 1 deletion tests/configs/modules/positions.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
let config = {
modules:
// Using exotic content. This is why don't accept go to JSON configuration file
(function () {
(() => {
let 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"];
let modules = Array();
for (let idx in positions) {
Expand Down
10 changes: 3 additions & 7 deletions tests/e2e/env_spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
const fetch = require("fetch");
const helpers = require("./global-setup");

describe("App environment", () => {
Expand All @@ -11,22 +10,19 @@ describe("App environment", () => {
});

it("get request from http://localhost:8080 should return 200", (done) => {
fetch("http://localhost:8080").then((res) => {
done();
helpers.fetch(done, "http://localhost:8080").then((res) => {
expect(res.status).toBe(200);
});
});

it("get request from http://localhost:8080/nothing should return 404", (done) => {
fetch("http://localhost:8080/nothing").then((res) => {
done();
helpers.fetch(done, "http://localhost:8080/nothing").then((res) => {
expect(res.status).toBe(404);
});
});

it("should show the title MagicMirror²", (done) => {
helpers.waitForElement("title").then((elem) => {
done();
helpers.waitForElement(done, "title").then((elem) => {
expect(elem).not.toBe(null);
expect(elem.textContent).toBe("MagicMirror²");
});
Expand Down
10 changes: 4 additions & 6 deletions tests/e2e/fonts.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
const fetch = require("fetch");
const helpers = require("./global-setup");

describe("All font files from roboto.css should be downloadable", function () {
describe("All font files from roboto.css should be downloadable", () => {
const fontFiles = [];
// Statements below filters out all 'url' lines in the CSS file
const fileContent = require("fs").readFileSync(__dirname + "/../../fonts/roboto.css", "utf8");
Expand All @@ -14,18 +13,17 @@ describe("All font files from roboto.css should be downloadable", function () {
match = regex.exec(fileContent);
}

beforeAll(function () {
beforeAll(() => {
helpers.startApplication("tests/configs/without_modules.js");
});
afterAll(async function () {
afterAll(async () => {
await helpers.stopApplication();
});

test.each(fontFiles)("should return 200 HTTP code for file '%s'", (fontFile, done) => {
const fontUrl = "http://localhost:8080/fonts/" + fontFile;
fetch(fontUrl).then((res) => {
helpers.fetch(done, fontUrl).then((res) => {
expect(res.status).toBe(200);
done();
});
});
});
16 changes: 14 additions & 2 deletions tests/e2e/global-setup.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const jsdom = require("jsdom");
const corefetch = require("fetch");

exports.startApplication = (configFilename, exec) => {
jest.resetModules();
Expand Down Expand Up @@ -32,7 +33,7 @@ exports.getDocument = (callback) => {
});
};

exports.waitForElement = (selector, ignoreValue = "") => {
exports.waitForElement = (done, selector, ignoreValue = "") => {
return new Promise((resolve) => {
let oldVal = "dummy12345";
const interval = setInterval(() => {
Expand All @@ -42,6 +43,7 @@ exports.waitForElement = (selector, ignoreValue = "") => {
if (newVal === oldVal) {
clearInterval(interval);
resolve(element);
if (done) done();
} else {
if (ignoreValue === "") {
oldVal = newVal;
Expand All @@ -54,7 +56,7 @@ exports.waitForElement = (selector, ignoreValue = "") => {
});
};

exports.waitForAllElements = (selector) => {
exports.waitForAllElements = (done, selector) => {
return new Promise((resolve) => {
let oldVal = 999999;
const interval = setInterval(() => {
Expand All @@ -64,10 +66,20 @@ exports.waitForAllElements = (selector) => {
if (newVal === oldVal) {
clearInterval(interval);
resolve(element);
if (done) done();
} else {
if (newVal !== 0) oldVal = newVal;
}
}
}, 100);
});
};

exports.fetch = (done, url) => {
return new Promise((resolve) => {
corefetch(url).then((res) => {
done();
resolve(res);
});
});
};
25 changes: 11 additions & 14 deletions tests/e2e/ipWhitelist_spec.js
Original file line number Diff line number Diff line change
@@ -1,35 +1,32 @@
const fetch = require("fetch");
const helpers = require("./global-setup");

describe("ipWhitelist directive configuration", function () {
describe("Set ipWhitelist without access", function () {
beforeAll(function () {
describe("ipWhitelist directive configuration", () => {
describe("Set ipWhitelist without access", () => {
beforeAll(() => {
helpers.startApplication("tests/configs/noIpWhiteList.js");
});
afterAll(async function () {
afterAll(async () => {
await helpers.stopApplication();
});

it("should return 403", function (done) {
fetch("http://localhost:8080").then((res) => {
it("should return 403", (done) => {
helpers.fetch(done, "http://localhost:8080").then((res) => {
expect(res.status).toBe(403);
done();
});
});
});

describe("Set ipWhitelist []", function () {
beforeAll(function () {
describe("Set ipWhitelist []", () => {
beforeAll(() => {
helpers.startApplication("tests/configs/empty_ipWhiteList.js");
});
afterAll(async function () {
afterAll(async () => {
await helpers.stopApplication();
});

it("should return 200", function (done) {
fetch("http://localhost:8080").then((res) => {
it("should return 200", (done) => {
helpers.fetch(done, "http://localhost:8080").then((res) => {
expect(res.status).toBe(200);
done();
});
});
});
Expand Down
4 changes: 2 additions & 2 deletions tests/e2e/mock-console.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
*
* @param {string} err The error message.
*/
function mockError(err) {
const mockError = (err) => {
if (err.includes("ECONNREFUSED") || err.includes("ECONNRESET") || err.includes("socket hang up") || err.includes("exports is not defined") || err.includes("write EPIPE")) {
jest.fn();
} else {
console.dir(err);
}
}
};

global.console = {
log: jest.fn(),
Expand Down
3 changes: 1 addition & 2 deletions tests/e2e/modules/alert_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ describe("Alert module", () => {
});

it("should show the welcome message", (done) => {
helpers.waitForElement(".ns-box .ns-box-inner .light.bright.small").then((elem) => {
done();
helpers.waitForElement(done, ".ns-box .ns-box-inner .light.bright.small").then((elem) => {
expect(elem).not.toBe(null);
expect(elem.textContent).toContain("Welcome, start was successful!");
});
Expand Down
6 changes: 3 additions & 3 deletions tests/e2e/modules/basic-auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ for (let directory of directories) {

let server;

exports.listen = function () {
server = app.listen.apply(app, arguments);
exports.listen = (...args) => {
server = app.listen.apply(app, args);
};

exports.close = function (callback) {
exports.close = (callback) => {
server.close(callback);
};
6 changes: 2 additions & 4 deletions tests/e2e/modules/calendar_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ describe("Calendar module", () => {
* @param {string} not reverse result
*/
const testElementLength = (done, element, result, not) => {
helpers.waitForAllElements(element).then((elem) => {
done();
helpers.waitForAllElements(done, element).then((elem) => {
expect(elem).not.toBe(null);
if (not === "not") {
expect(elem.length).not.toBe(result);
Expand All @@ -21,8 +20,7 @@ describe("Calendar module", () => {
};

const testTextContain = (done, element, text) => {
helpers.waitForElement(element, "undefinedLoading").then((elem) => {
done();
helpers.waitForElement(done, element, "undefinedLoading").then((elem) => {
expect(elem).not.toBe(null);
expect(elem.textContent).toContain(text);
});
Expand Down
3 changes: 1 addition & 2 deletions tests/e2e/modules/clock_es_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ describe("Clock set to spanish language module", () => {
});

const testMatch = (done, element, regex) => {
helpers.waitForElement(element).then((elem) => {
done();
helpers.waitForElement(done, element).then((elem) => {
expect(elem).not.toBe(null);
expect(elem.textContent).toMatch(regex);
});
Expand Down
9 changes: 3 additions & 6 deletions tests/e2e/modules/clock_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ describe("Clock module", () => {
});

const testMatch = (done, element, regex) => {
Comment thread
khassel marked this conversation as resolved.
Outdated
helpers.waitForElement(element).then((elem) => {
done();
helpers.waitForElement(done, element).then((elem) => {
expect(elem).not.toBe(null);
expect(elem.textContent).toMatch(regex);
});
Expand Down Expand Up @@ -99,8 +98,7 @@ describe("Clock module", () => {
it("should show the week with the correct number of week of year", (done) => {
const currentWeekNumber = moment().week();
const weekToShow = "Week " + currentWeekNumber;
helpers.waitForElement(".clock .week").then((elem) => {
done();
helpers.waitForElement(done, ".clock .week").then((elem) => {
expect(elem).not.toBe(null);
expect(elem.textContent).toBe(weekToShow);
});
Expand All @@ -114,8 +112,7 @@ describe("Clock module", () => {
});

it("should show the analog clock face", (done) => {
helpers.waitForElement(".clockCircle").then((elem) => {
done();
helpers.waitForElement(done, ".clockCircle").then((elem) => {
expect(elem).not.toBe(null);
});
});
Expand Down
5 changes: 2 additions & 3 deletions tests/e2e/modules/compliments_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@ const helpers = require("../global-setup");
* @param {Array} complimentsArray The array of compliments.
*/
const doTest = (done, complimentsArray) => {
helpers.waitForElement(".compliments").then((elem) => {
helpers.waitForElement(null, ".compliments").then((elem) => {
expect(elem).not.toBe(null);
helpers.waitForElement(".module-content").then((elem) => {
done();
helpers.waitForElement(done, ".module-content").then((elem) => {
expect(elem).not.toBe(null);
expect(complimentsArray).toContain(elem.textContent);
});
Expand Down
6 changes: 2 additions & 4 deletions tests/e2e/modules/helloworld_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ describe("Test helloworld module", () => {
});

it("Test message helloworld module", (done) => {
helpers.waitForElement(".helloworld").then((elem) => {
done();
helpers.waitForElement(done, ".helloworld").then((elem) => {
expect(elem).not.toBe(null);
expect(elem.textContent).toContain("Test HelloWorld Module");
});
Expand All @@ -27,8 +26,7 @@ describe("Test helloworld module", () => {
});

it("Test message helloworld module", (done) => {
helpers.waitForElement(".helloworld").then((elem) => {
done();
helpers.waitForElement(done, ".helloworld").then((elem) => {
expect(elem).not.toBe(null);
expect(elem.textContent).toContain("Hello World!");
});
Expand Down
4 changes: 2 additions & 2 deletions tests/e2e/modules/mocks/weather_current.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const _ = require("lodash");
* @param {object} extendedData extra data to add to the default mock data
* @returns {string} mocked current weather data
*/
function generateWeather(extendedData = {}) {
const generateWeather = (extendedData = {}) => {
return JSON.stringify(
_.merge(
{},
Expand Down Expand Up @@ -59,6 +59,6 @@ function generateWeather(extendedData = {}) {
extendedData
)
);
}
};

module.exports = generateWeather;
4 changes: 2 additions & 2 deletions tests/e2e/modules/mocks/weather_forecast.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const _ = require("lodash");
* @param {object} extendedData extra data to add to the default mock data
* @returns {string} mocked forecast weather data
*/
function generateWeatherForecast(extendedData = {}) {
const generateWeatherForecast = (extendedData = {}) => {
return JSON.stringify(
_.merge(
{},
Expand Down Expand Up @@ -110,6 +110,6 @@ function generateWeatherForecast(extendedData = {}) {
extendedData
)
);
}
};

module.exports = generateWeatherForecast;
Loading