jest setup changes, increase setMaxListeners, disable console.log in tests/unit/global_vars

This commit is contained in:
Karsten Hassel 2021-06-12 20:03:20 +02:00
parent 298542b531
commit a5f7c946cc
5 changed files with 30 additions and 6 deletions

View File

@ -10,10 +10,10 @@
"install": "echo \"Installing vendor files ...\n\" && cd vendor && npm install --loglevel=error",
"install-fonts": "echo \"Installing fonts ...\n\" && cd fonts && npm install --loglevel=error",
"postinstall": "npm run install-fonts && echo \"MagicMirror installation finished successfully! \n\"",
"test": "NODE_ENV=test jest -i --silent --forceExit",
"test:coverage": "NODE_ENV=test nyc --reporter=lcov --reporter=text jest -i --silent --forceExit",
"test:e2e": "NODE_ENV=test jest --selectProjects e2e -i --forceExit",
"test:unit": "NODE_ENV=test jest --selectProjects unit --silent --forceExit",
"test": "NODE_ENV=test jest --detectOpenHandles --forceExit",
"test:coverage": "NODE_ENV=test nyc --reporter=lcov --reporter=text jest --detectOpenHandles --forceExit",
"test:e2e": "NODE_ENV=test jest --selectProjects e2e --detectOpenHandles --forceExit",
"test:unit": "NODE_ENV=test jest --selectProjects unit --detectOpenHandles --forceExit",
"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",
"test:css": "stylelint css/main.css modules/default/**/*.css --config .stylelintrc.json",

View File

@ -7,6 +7,7 @@
const Application = require("spectron").Application;
const assert = require("assert");
const path = require("path");
const EventEmitter = require("events");
exports.getElectronPath = function () {
let electronPath = path.join(__dirname, "..", "..", "node_modules", ".bin", "electron");
@ -26,6 +27,9 @@ exports.setupTimeout = function (test) {
};
exports.startApplication = function (options) {
const emitter = new EventEmitter();
emitter.setMaxListeners(100);
options.path = exports.getElectronPath();
if (process.env.CI) {
options.startTimeout = 30000;

View File

@ -27,19 +27,21 @@ describe("Vendors", function () {
describe("Get list vendors", function () {
const vendors = require(__dirname + "/../../vendor/vendor.js");
Object.keys(vendors).forEach((vendor) => {
it(`should return 200 HTTP code for vendor "${vendor}"`, function () {
it(`should return 200 HTTP code for vendor "${vendor}"`, function (done) {
const urlVendor = "http://localhost:8080/vendor/" + vendors[vendor];
fetch(urlVendor).then((res) => {
expect(res.status).toBe(200);
done();
});
});
});
Object.keys(vendors).forEach((vendor) => {
it(`should return 404 HTTP code for vendor https://localhost/"${vendor}"`, function () {
it(`should return 404 HTTP code for vendor https://localhost/"${vendor}"`, function (done) {
const urlVendor = "http://localhost:8080/" + vendors[vendor];
fetch(urlVendor).then((res) => {
expect(res.status).toBe(404);
done();
});
});
});

View File

@ -4,11 +4,16 @@ const vm = require("vm");
const basedir = path.join(__dirname, "../../..");
const mockedWarn = () => {};
const originalWarn = console.log;
beforeAll(function () {
const fileName = "js/app.js";
const filePath = path.join(basedir, fileName);
const code = fs.readFileSync(filePath);
console.log = mockedWarn;
sandbox = {
module: {},
__dirname: path.dirname(filePath),
@ -28,6 +33,10 @@ beforeAll(function () {
vm.runInNewContext(code, sandbox, fileName);
});
afterAll(function () {
console.log = originalWarn;
});
describe("Default modules set in modules/default/defaultmodules.js", function () {
const expectedDefaultModules = require("../../../modules/default/defaultmodules");

View File

@ -2,6 +2,9 @@ const fs = require("fs");
const path = require("path");
const vm = require("vm");
const mockedWarn = () => {};
const originalWarn = console.log;
beforeAll(function () {
const basedir = path.join(__dirname, "../../..");
@ -9,6 +12,8 @@ beforeAll(function () {
const filePath = path.join(basedir, fileName);
const code = fs.readFileSync(filePath);
console.log = mockedWarn;
sandbox = {
module: {},
__dirname: path.dirname(filePath),
@ -28,6 +33,10 @@ beforeAll(function () {
vm.runInNewContext(code, sandbox, fileName);
});
afterAll(function () {
console.log = originalWarn;
});
describe("'global.root_path' set in js/app.js", function () {
const expectedSubPaths = ["modules", "serveronly", "js", "js/app.js", "js/main.js", "js/electron.js", "config"];