mirror of
https://github.com/MichMich/MagicMirror.git
synced 2025-06-27 11:50:00 +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:
|
with:
|
||||||
node-version: ${{ matrix.node-version }}
|
node-version: ${{ matrix.node-version }}
|
||||||
- run: |
|
- run: |
|
||||||
node -v
|
|
||||||
Xvfb :99 -screen 0 1024x768x16 &
|
Xvfb :99 -screen 0 1024x768x16 &
|
||||||
export DISPLAY=:99
|
export DISPLAY=:99
|
||||||
npm install
|
npm install
|
||||||
@ -32,3 +31,4 @@ jobs:
|
|||||||
npm run test:css
|
npm run test:css
|
||||||
npm run test:unit
|
npm run test:unit
|
||||||
npm run test:e2e
|
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\"",
|
"postinstall": "npm run install-fonts && echo \"MagicMirror installation finished successfully! \n\"",
|
||||||
"test": "NODE_ENV=test jest -i --forceExit",
|
"test": "NODE_ENV=test jest -i --forceExit",
|
||||||
"test:coverage": "NODE_ENV=test nyc --reporter=lcov --reporter=text 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:e2e": "NODE_ENV=test jest --selectProjects e2e -i --forceExit",
|
||||||
"test:unit": "NODE_ENV=test jest --selectProjects unit -i --forceExit",
|
"test:unit": "NODE_ENV=test jest --selectProjects unit -i --forceExit",
|
||||||
"test:prettier": "prettier . --check",
|
"test:prettier": "prettier . --check",
|
||||||
@ -106,15 +107,26 @@
|
|||||||
"<rootDir>/tests/unit/mocks"
|
"<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",
|
"displayName": "e2e",
|
||||||
"testMatch": [
|
"testMatch": [
|
||||||
"**/tests/e2e/**/*.[jt]s?(x)"
|
"**/tests/e2e/**/*.[jt]s?(x)"
|
||||||
],
|
],
|
||||||
"testPathIgnorePatterns": [
|
"moduleNameMapper": {
|
||||||
"<rootDir>/tests/e2e/modules/mocks",
|
"logger": "<rootDir>/js/logger.js",
|
||||||
"<rootDir>/tests/e2e/global-setup.js"
|
"node_helper": "<rootDir>/js/node_helper.js"
|
||||||
]
|
}
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
@ -1,42 +1,15 @@
|
|||||||
const helpers = require("./global-setup");
|
|
||||||
const fetch = require("node-fetch");
|
const fetch = require("node-fetch");
|
||||||
|
const app = require("../../js/app.js");
|
||||||
|
|
||||||
describe("Electron app environment", function () {
|
describe("Electron app environment", function () {
|
||||||
helpers.setupTimeout(this);
|
|
||||||
|
|
||||||
let app = null;
|
|
||||||
|
|
||||||
beforeAll(function () {
|
beforeAll(function () {
|
||||||
// Set config sample for use in test
|
|
||||||
process.env.MM_CONFIG_FILE = "tests/configs/env.js";
|
process.env.MM_CONFIG_FILE = "tests/configs/env.js";
|
||||||
|
|
||||||
|
app.start();
|
||||||
});
|
});
|
||||||
|
|
||||||
beforeEach(function () {
|
afterAll(function () {
|
||||||
return helpers
|
app.stop();
|
||||||
.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²");
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("get request from http://localhost:8080 should return 200", function (done) {
|
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 fetch = require("node-fetch");
|
||||||
|
const app = require("../../js/app.js");
|
||||||
|
|
||||||
describe("All font files from roboto.css should be downloadable", function () {
|
describe("All font files from roboto.css should be downloadable", function () {
|
||||||
helpers.setupTimeout(this);
|
|
||||||
|
|
||||||
let app;
|
|
||||||
const fontFiles = [];
|
const fontFiles = [];
|
||||||
// Statements below filters out all 'url' lines in the CSS file
|
// Statements below filters out all 'url' lines in the CSS file
|
||||||
const fileContent = require("fs").readFileSync(__dirname + "/../../fonts/roboto.css", "utf8");
|
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 () {
|
beforeAll(function () {
|
||||||
// Set config sample for use in test
|
|
||||||
process.env.MM_CONFIG_FILE = "tests/configs/without_modules.js";
|
process.env.MM_CONFIG_FILE = "tests/configs/without_modules.js";
|
||||||
|
|
||||||
return helpers
|
app.start();
|
||||||
.startApplication({
|
|
||||||
args: ["js/electron.js"]
|
|
||||||
})
|
|
||||||
.then(function (startedApp) {
|
|
||||||
app = startedApp;
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
afterAll(function () {
|
afterAll(function () {
|
||||||
return helpers.stopApplication(app);
|
app.stop();
|
||||||
});
|
});
|
||||||
|
|
||||||
test.each(fontFiles)("should return 200 HTTP code for file '%s'", (fontFile, done) => {
|
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 fetch = require("node-fetch");
|
||||||
|
const app = require("../../js/app.js");
|
||||||
|
|
||||||
describe("ipWhitelist directive configuration", function () {
|
describe("ipWhitelist directive configuration", function () {
|
||||||
helpers.setupTimeout(this);
|
beforeAll(function () {
|
||||||
|
app.start();
|
||||||
let app = null;
|
|
||||||
|
|
||||||
beforeEach(function () {
|
|
||||||
return helpers
|
|
||||||
.startApplication({
|
|
||||||
args: ["js/electron.js"]
|
|
||||||
})
|
|
||||||
.then(function (startedApp) {
|
|
||||||
app = startedApp;
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
afterEach(function () {
|
afterAll(function () {
|
||||||
return helpers.stopApplication(app);
|
app.stop();
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("Set ipWhitelist without access", function () {
|
describe("Set ipWhitelist without access", function () {
|
||||||
|
@ -1,31 +1,18 @@
|
|||||||
const helpers = require("./global-setup");
|
|
||||||
const fetch = require("node-fetch");
|
const fetch = require("node-fetch");
|
||||||
|
const app = require("../../js/app.js");
|
||||||
|
|
||||||
describe("port directive configuration", function () {
|
describe("port directive configuration", function () {
|
||||||
helpers.setupTimeout(this);
|
beforeAll(function () {
|
||||||
|
process.env.MM_CONFIG_FILE = "tests/configs/port_8090.js";
|
||||||
|
|
||||||
let app = null;
|
app.start();
|
||||||
|
|
||||||
beforeEach(function () {
|
|
||||||
return helpers
|
|
||||||
.startApplication({
|
|
||||||
args: ["js/electron.js"]
|
|
||||||
})
|
|
||||||
.then(function (startedApp) {
|
|
||||||
app = startedApp;
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
afterEach(function () {
|
afterAll(function () {
|
||||||
return helpers.stopApplication(app);
|
app.stop();
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("Set port 8090", function () {
|
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) {
|
it("should return 200", function (done) {
|
||||||
fetch("http://localhost:8090").then((res) => {
|
fetch("http://localhost:8090").then((res) => {
|
||||||
expect(res.status).toBe(200);
|
expect(res.status).toBe(200);
|
||||||
@ -37,8 +24,6 @@ describe("port directive configuration", function () {
|
|||||||
describe("Set port 8100 on environment variable MM_PORT", function () {
|
describe("Set port 8100 on environment variable MM_PORT", function () {
|
||||||
beforeAll(function () {
|
beforeAll(function () {
|
||||||
process.env.MM_PORT = 8100;
|
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 () {
|
afterAll(function () {
|
||||||
|
@ -1,24 +1,15 @@
|
|||||||
const helpers = require("./global-setup");
|
|
||||||
const fetch = require("node-fetch");
|
const fetch = require("node-fetch");
|
||||||
|
const app = require("../../js/app.js");
|
||||||
|
|
||||||
describe("Vendors", function () {
|
describe("Vendors", function () {
|
||||||
helpers.setupTimeout(this);
|
|
||||||
|
|
||||||
let app = null;
|
|
||||||
|
|
||||||
beforeAll(function () {
|
beforeAll(function () {
|
||||||
process.env.MM_CONFIG_FILE = "tests/configs/env.js";
|
process.env.MM_CONFIG_FILE = "tests/configs/env.js";
|
||||||
return helpers
|
|
||||||
.startApplication({
|
app.start();
|
||||||
args: ["js/electron.js"]
|
|
||||||
})
|
|
||||||
.then(function (startedApp) {
|
|
||||||
app = startedApp;
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
afterAll(function () {
|
afterAll(function () {
|
||||||
return helpers.stopApplication(app);
|
app.stop();
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("Get list vendors", function () {
|
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 helpers = require("../global-setup");
|
||||||
const serverBasicAuth = require("../../servers/basic-auth.js");
|
const serverBasicAuth = require("./basic-auth.js");
|
||||||
|
|
||||||
describe("Calendar module", function () {
|
describe("Calendar module", function () {
|
||||||
helpers.setupTimeout(this);
|
helpers.setupTimeout(this);
|
Loading…
x
Reference in New Issue
Block a user