mirror of
https://github.com/ether/etherpad-lite.git
synced 2025-04-21 07:56:16 -04:00
tests: Recurse under frontend spec dir
This commit is contained in:
parent
5d54c1657a
commit
d8eb79428f
1 changed files with 26 additions and 11 deletions
|
@ -6,6 +6,29 @@ const plugins = require('../../../static/js/pluginfw/plugin_defs');
|
||||||
const sanitizePathname = require('../../utils/sanitizePathname');
|
const sanitizePathname = require('../../utils/sanitizePathname');
|
||||||
const settings = require('../../utils/Settings');
|
const settings = require('../../utils/Settings');
|
||||||
|
|
||||||
|
// Returns all *.js files under specDir (recursively) as relative paths to specDir, using '/'
|
||||||
|
// instead of path.sep to separate pathname components.
|
||||||
|
const findSpecs = async (specDir) => {
|
||||||
|
let dirents;
|
||||||
|
try {
|
||||||
|
dirents = await fsp.readdir(specDir, {withFileTypes: true});
|
||||||
|
} catch (err) {
|
||||||
|
if (['ENOENT', 'ENOTDIR'].includes(err.code)) return [];
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
|
const specs = [];
|
||||||
|
await Promise.all(dirents.map(async (dirent) => {
|
||||||
|
if (dirent.isDirectory()) {
|
||||||
|
const subdirSpecs = await findSpecs(path.join(specDir, dirent.name));
|
||||||
|
specs.push(...subdirSpecs.map((spec) => `${dirent.name}/${spec}`));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!dirent.name.endsWith('.js')) return;
|
||||||
|
specs.push(dirent.name);
|
||||||
|
}));
|
||||||
|
return specs;
|
||||||
|
};
|
||||||
|
|
||||||
exports.expressCreateServer = (hookName, args, cb) => {
|
exports.expressCreateServer = (hookName, args, cb) => {
|
||||||
args.app.get('/tests/frontend/frontendTestSpecs.js', async (req, res) => {
|
args.app.get('/tests/frontend/frontendTestSpecs.js', async (req, res) => {
|
||||||
const [coreTests, pluginTests] = await Promise.all([getCoreTests(), getPluginTests()]);
|
const [coreTests, pluginTests] = await Promise.all([getCoreTests(), getPluginTests()]);
|
||||||
|
@ -13,9 +36,6 @@ exports.expressCreateServer = (hookName, args, cb) => {
|
||||||
// merge the two sets of results
|
// merge the two sets of results
|
||||||
let files = [].concat(coreTests, pluginTests).sort();
|
let files = [].concat(coreTests, pluginTests).sort();
|
||||||
|
|
||||||
// Keep only *.js files
|
|
||||||
files = files.filter((f) => f.endsWith('.js'));
|
|
||||||
|
|
||||||
// remove admin tests if the setting to enable them isn't in settings.json
|
// remove admin tests if the setting to enable them isn't in settings.json
|
||||||
if (!settings.enableAdminUITests) {
|
if (!settings.enableAdminUITests) {
|
||||||
files = files.filter((file) => file.indexOf('admin') !== 0);
|
files = files.filter((file) => file.indexOf('admin') !== 0);
|
||||||
|
@ -62,15 +82,10 @@ const getPluginTests = async (callback) => {
|
||||||
const specLists = await Promise.all(Object.entries(plugins.plugins).map(async ([plugin, def]) => {
|
const specLists = await Promise.all(Object.entries(plugins.plugins).map(async ([plugin, def]) => {
|
||||||
if (plugin === 'ep_etherpad-lite') return [];
|
if (plugin === 'ep_etherpad-lite') return [];
|
||||||
const {package: {path: pluginPath}} = def;
|
const {package: {path: pluginPath}} = def;
|
||||||
try {
|
const specs = await findSpecs(path.join(pluginPath, specPath));
|
||||||
const specs = await fsp.readdir(path.join(pluginPath, specPath));
|
return specs.map((spec) => `/static/plugins/${plugin}/${specPath}/${spec}`);
|
||||||
return specs.map((spec) => `/static/plugins/${plugin}/${specPath}/${spec}`);
|
|
||||||
} catch (err) {
|
|
||||||
if (['ENOENT', 'ENOTDIR'].includes(err.code)) return [];
|
|
||||||
throw err;
|
|
||||||
}
|
|
||||||
}));
|
}));
|
||||||
return [].concat(...specLists);
|
return [].concat(...specLists);
|
||||||
};
|
};
|
||||||
|
|
||||||
const getCoreTests = async () => await fsp.readdir('src/tests/frontend/specs');
|
const getCoreTests = async () => await findSpecs('src/tests/frontend/specs');
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue