From d69345bb4e9050761d0bfb1532ae0e073af0c844 Mon Sep 17 00:00:00 2001 From: Richard Hansen Date: Sun, 9 May 2021 16:50:59 -0400 Subject: [PATCH] tests: Use map+reduce to improve readability --- src/node/hooks/express/tests.js | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/src/node/hooks/express/tests.js b/src/node/hooks/express/tests.js index 0dc2bb8ec..111c1643f 100644 --- a/src/node/hooks/express/tests.js +++ b/src/node/hooks/express/tests.js @@ -57,19 +57,14 @@ const getPluginTests = async (callback) => { const moduleDir = 'node_modules/'; const specPath = '/static/tests/frontend/specs/'; const staticDir = '/static/plugins/'; - - const pluginSpecs = []; - const plugins = await fsp.readdir(moduleDir); - await Promise.all(plugins.map(async (plugin) => { + const specLists = await Promise.all(plugins.map(async (plugin) => { const specDir = moduleDir + plugin + specPath; - if (!fs.existsSync(specDir)) return; + if (!fs.existsSync(specDir)) return []; const specFiles = await fsp.readdir(specDir); - for (const spec of specFiles) { - pluginSpecs.push(staticDir + plugin + specPath + spec); - } + return specFiles.map((spec) => staticDir + plugin + specPath + spec); })); - return pluginSpecs; + return [].concat(...specLists); }; const getCoreTests = async () => await fsp.readdir('src/tests/frontend/specs');