From a5f7c946cc26abcf8ec4b6c5d4398646c19c6a0f Mon Sep 17 00:00:00 2001 From: Karsten Hassel Date: Sat, 12 Jun 2021 20:03:20 +0200 Subject: [PATCH] jest setup changes, increase setMaxListeners, disable console.log in tests/unit/global_vars --- package.json | 8 ++++---- tests/e2e/global-setup.js | 4 ++++ tests/e2e/vendor_spec.js | 6 ++++-- tests/unit/global_vars/defaults_modules_spec.js | 9 +++++++++ tests/unit/global_vars/root_path_spec.js | 9 +++++++++ 5 files changed, 30 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index 3a41d498..08d2b1b1 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/tests/e2e/global-setup.js b/tests/e2e/global-setup.js index 6bc5ca93..a1e0685b 100644 --- a/tests/e2e/global-setup.js +++ b/tests/e2e/global-setup.js @@ -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; diff --git a/tests/e2e/vendor_spec.js b/tests/e2e/vendor_spec.js index fc154a88..b5289c2f 100644 --- a/tests/e2e/vendor_spec.js +++ b/tests/e2e/vendor_spec.js @@ -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(); }); }); }); diff --git a/tests/unit/global_vars/defaults_modules_spec.js b/tests/unit/global_vars/defaults_modules_spec.js index 08899a2d..1c9137ce 100644 --- a/tests/unit/global_vars/defaults_modules_spec.js +++ b/tests/unit/global_vars/defaults_modules_spec.js @@ -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"); diff --git a/tests/unit/global_vars/root_path_spec.js b/tests/unit/global_vars/root_path_spec.js index 249066dc..8cf8b521 100644 --- a/tests/unit/global_vars/root_path_spec.js +++ b/tests/unit/global_vars/root_path_spec.js @@ -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"];