mirror of
https://github.com/MichMich/MagicMirror.git
synced 2025-06-27 03:39:55 +00:00
refactor tests in 3 categories unit, e2e and electron
This commit is contained in:
parent
60e03777f3
commit
974de179e0
2
.github/workflows/node-ci.js.yml
vendored
2
.github/workflows/node-ci.js.yml
vendored
@ -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
|
||||
|
20
package.json
20
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 @@
|
||||
"<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"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
|
@ -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) {
|
||||
|
@ -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) => {
|
||||
|
@ -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 () {
|
||||
|
@ -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 () {
|
||||
|
@ -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 () {
|
||||
|
40
tests/electron/env_spec.js
Normal file
40
tests/electron/env_spec.js
Normal 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²");
|
||||
});
|
||||
});
|
@ -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);
|
Loading…
x
Reference in New Issue
Block a user