From ba812c58b4c80469999f9c188353da4e77cccf2a Mon Sep 17 00:00:00 2001 From: Karsten Hassel Date: Thu, 19 Sep 2024 21:05:58 +0200 Subject: [PATCH] fixes for running tests for MM_MODULES_DIR, ignore `js/positions.js` when linting --- .eslintignore | 3 ++- CHANGELOG.md | 1 + js/app.js | 10 +++++++++- js/loader.js | 10 +++++++++- tests/e2e/modules/newsfeed_spec.js | 4 ++-- 5 files changed, 23 insertions(+), 5 deletions(-) diff --git a/.eslintignore b/.eslintignore index 24f4f1f599..c772c23bc2 100644 --- a/.eslintignore +++ b/.eslintignore @@ -1,2 +1,3 @@ modules/* -!modules/default/ \ No newline at end of file +!modules/default/ +js/positions.js diff --git a/CHANGELOG.md b/CHANGELOG.md index f29a4fd9d4..8e8e8226aa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -39,6 +39,7 @@ _This release is scheduled to be released on 2024-10-01._ - [weather] Fixed issue for respecting unit config on broadcasted notifications - [tests] Fixes calendar test by moving it from e2e to electron with fixed date (#3532) - [calendar] fixed sliceMultiDayEvents getting wrong count and displaying incorrect entries, Europe/Berlin (#3542) +- [tests] ignore `js/positions.js` when linting (this file is created at runtime) ## [2.28.0] - 2024-07-01 diff --git a/js/app.js b/js/app.js index 0bf60a9b0e..8ae002e9f0 100644 --- a/js/app.js +++ b/js/app.js @@ -166,7 +166,15 @@ function App () { let moduleFolder = `${__dirname}/../${env.modulesDir}/${module}`; if (defaultModules.includes(moduleName)) { - moduleFolder = `${__dirname}/../modules/default/${module}`; + const defaultModuleFolder = `${__dirname}/../modules/default/${module}`; + if (process.env.JEST_WORKER_ID === undefined) { + moduleFolder = defaultModuleFolder; + } else { + // running in Jest, allow defaultModules placed under moduleDir for testing + if (env.modulesDir === "modules") { + moduleFolder = defaultModuleFolder; + } + } } const moduleFile = `${moduleFolder}/${module}.js`; diff --git a/js/loader.js b/js/loader.js index acc77d2801..9b42dd8493 100644 --- a/js/loader.js +++ b/js/loader.js @@ -80,7 +80,15 @@ const Loader = (function () { let moduleFolder = `${envVars.modulesDir}/${module}`; if (defaultModules.indexOf(moduleName) !== -1) { - moduleFolder = `modules/default/${module}`; + const defaultModuleFolder = `modules/default/${module}`; + if (window.name !== "jsdom") { + moduleFolder = defaultModuleFolder; + } else { + // running in Jest, allow defaultModules placed under moduleDir for testing + if (envVars.modulesDir === "modules") { + moduleFolder = defaultModuleFolder; + } + } } if (moduleData.disabled === true) { diff --git a/tests/e2e/modules/newsfeed_spec.js b/tests/e2e/modules/newsfeed_spec.js index e3a9c79099..1c3c4d288d 100644 --- a/tests/e2e/modules/newsfeed_spec.js +++ b/tests/e2e/modules/newsfeed_spec.js @@ -82,10 +82,10 @@ describe("Newsfeed module", () => { }); describe("Newsfeed module located in config directory", () => { - beforeAll(async () => { + beforeAll(() => { const baseDir = `${__dirname}/../../..`; if (!fs.existsSync(`${baseDir}/config/newsfeed`)) { - await fs.cp(`${baseDir}/modules/default/newsfeed`, `${baseDir}/config/newsfeed`, { recursive: true }, (err) => err && console.error(err)); + fs.cpSync(`${baseDir}/modules/default/newsfeed`, `${baseDir}/config/newsfeed`, { recursive: true }); } process.env.MM_MODULES_DIR = "config"; });