From 53720ae8aee7e2ebf75c177564a08ce22516d5d7 Mon Sep 17 00:00:00 2001 From: rejas Date: Thu, 1 Jul 2021 16:37:27 +0200 Subject: [PATCH] Fix some eslint issues in the tests --- tests/e2e/modules/clock_es_spec.js | 2 +- tests/e2e/modules/clock_spec.js | 2 +- .../unit/global_vars/defaults_modules_spec.js | 66 ++++++++--------- tests/unit/global_vars/root_path_spec.js | 70 ++++++++++--------- 4 files changed, 72 insertions(+), 68 deletions(-) diff --git a/tests/e2e/modules/clock_es_spec.js b/tests/e2e/modules/clock_es_spec.js index f97fba2f..4c39a241 100644 --- a/tests/e2e/modules/clock_es_spec.js +++ b/tests/e2e/modules/clock_es_spec.js @@ -5,7 +5,7 @@ describe("Clock set to spanish language module", function () { let app = null; - testMatch = async function (element, regex) { + const testMatch = async function (element, regex) { await app.client.waitUntilWindowLoaded(); const elem = await app.client.$(element); const txt = await elem.getText(element); diff --git a/tests/e2e/modules/clock_spec.js b/tests/e2e/modules/clock_spec.js index c09f44de..473c6f6a 100644 --- a/tests/e2e/modules/clock_spec.js +++ b/tests/e2e/modules/clock_spec.js @@ -6,7 +6,7 @@ describe("Clock module", function () { let app = null; - testMatch = async function (element, regex) { + const testMatch = async function (element, regex) { await app.client.waitUntilWindowLoaded(); const elem = await app.client.$(element); const txt = await elem.getText(element); diff --git a/tests/unit/global_vars/defaults_modules_spec.js b/tests/unit/global_vars/defaults_modules_spec.js index c0a7f0e4..03879a86 100644 --- a/tests/unit/global_vars/defaults_modules_spec.js +++ b/tests/unit/global_vars/defaults_modules_spec.js @@ -4,39 +4,41 @@ const vm = require("vm"); const basedir = path.join(__dirname, "../../.."); -beforeAll(function () { - const fileName = "js/app.js"; - const filePath = path.join(basedir, fileName); - const code = fs.readFileSync(filePath); - - sandbox = { - module: {}, - __dirname: path.dirname(filePath), - global: {}, - process: { - on: function () {}, - env: {} - } - }; - - sandbox.require = function (filename) { - // This modifies the global slightly, - // but supplies vm with essential code - if (filename === "logger") { - return require("../mocks/logger.js"); - } else { - try { - return require(filename); - } catch { - // ignore - } - } - }; - - vm.runInNewContext(code, sandbox, fileName); -}); - describe("Default modules set in modules/default/defaultmodules.js", function () { + let sandbox = null; + + beforeAll(function () { + const fileName = "js/app.js"; + const filePath = path.join(basedir, fileName); + const code = fs.readFileSync(filePath); + + sandbox = { + module: {}, + __dirname: path.dirname(filePath), + global: {}, + process: { + on: function () {}, + env: {} + } + }; + + sandbox.require = function (filename) { + // This modifies the global slightly, + // but supplies vm with essential code + if (filename === "logger") { + return require("../mocks/logger.js"); + } else { + try { + return require(filename); + } catch (ignore) { + // ignore + } + } + }; + + vm.runInNewContext(code, sandbox, fileName); + }); + const expectedDefaultModules = require("../../../modules/default/defaultmodules"); for (const defaultModule of expectedDefaultModules) { diff --git a/tests/unit/global_vars/root_path_spec.js b/tests/unit/global_vars/root_path_spec.js index 591f3ddb..9dfc3f30 100644 --- a/tests/unit/global_vars/root_path_spec.js +++ b/tests/unit/global_vars/root_path_spec.js @@ -2,41 +2,43 @@ const fs = require("fs"); const path = require("path"); const vm = require("vm"); -beforeAll(function () { - const basedir = path.join(__dirname, "../../.."); - - const fileName = "js/app.js"; - const filePath = path.join(basedir, fileName); - const code = fs.readFileSync(filePath); - - sandbox = { - module: {}, - __dirname: path.dirname(filePath), - global: {}, - process: { - on: function () {}, - env: {} - } - }; - - sandbox.require = function (filename) { - // This modifies the global slightly, - // but supplies vm with essential code - if (filename === "logger") { - return require("../mocks/logger.js"); - } else { - try { - return require(filename); - } catch { - // ignore - } - } - }; - - vm.runInNewContext(code, sandbox, fileName); -}); - describe("'global.root_path' set in js/app.js", function () { + let sandbox = null; + + beforeAll(function () { + const basedir = path.join(__dirname, "../../.."); + + const fileName = "js/app.js"; + const filePath = path.join(basedir, fileName); + const code = fs.readFileSync(filePath); + + sandbox = { + module: {}, + __dirname: path.dirname(filePath), + global: {}, + process: { + on: function () {}, + env: {} + } + }; + + sandbox.require = function (filename) { + // This modifies the global slightly, + // but supplies vm with essential code + if (filename === "logger") { + return require("../mocks/logger.js"); + } else { + try { + return require(filename); + } catch (ignore) { + // ignore + } + } + }; + + vm.runInNewContext(code, sandbox, fileName); + }); + const expectedSubPaths = ["modules", "serveronly", "js", "js/app.js", "js/main.js", "js/electron.js", "config"]; expectedSubPaths.forEach((subpath) => {