refactor tests in 3 categories unit, e2e and electron

This commit is contained in:
Karsten Hassel 2021-09-13 22:28:27 +02:00
parent 60e03777f3
commit 974de179e0
26 changed files with 81 additions and 100 deletions

View File

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

View File

@ -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 @@
"<rootDir>/tests/unit/mocks"
]
},
{
"displayName": "electron",
"testMatch": [
"**/tests/electron/**/*.[jt]s?(x)"
],
"testPathIgnorePatterns": [
"<rootDir>/tests/electron/modules/mocks",
"<rootDir>/tests/electron/global-setup.js",
"<rootDir>/tests/electron/modules/basic-auth.js"
]
},
{
"displayName": "e2e",
"testMatch": [
"**/tests/e2e/**/*.[jt]s?(x)"
],
"testPathIgnorePatterns": [
"<rootDir>/tests/e2e/modules/mocks",
"<rootDir>/tests/e2e/global-setup.js"
]
"moduleNameMapper": {
"logger": "<rootDir>/js/logger.js",
"node_helper": "<rootDir>/js/node_helper.js"
}
}
]
}

View File

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

View File

@ -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) => {

View File

@ -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 () {

View File

@ -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 () {

View File

@ -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 () {

View File

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

View File

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