mirror of
https://github.com/ether/etherpad-lite.git
synced 2025-04-21 07:56:16 -04:00
tests: Let Express handle errors when serving frontendTestSpecs.js
Express v4.x doesn't understand Promises so we have to manually catch Promise rejections and pass the error object to `next()`.
This commit is contained in:
parent
e4f011df76
commit
c714ff1014
1 changed files with 26 additions and 24 deletions
|
@ -30,30 +30,32 @@ const findSpecs = async (specDir) => {
|
||||||
};
|
};
|
||||||
|
|
||||||
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', (req, res, next) => {
|
||||||
const modules = [];
|
(async () => {
|
||||||
await Promise.all(Object.entries(plugins.plugins).map(async ([plugin, def]) => {
|
const modules = [];
|
||||||
let {package: {path: pluginPath}} = def;
|
await Promise.all(Object.entries(plugins.plugins).map(async ([plugin, def]) => {
|
||||||
if (!pluginPath.endsWith(path.sep)) pluginPath += path.sep;
|
let {package: {path: pluginPath}} = def;
|
||||||
const specDir = `${plugin === 'ep_etherpad-lite' ? '' : 'static/'}tests/frontend/specs`;
|
if (!pluginPath.endsWith(path.sep)) pluginPath += path.sep;
|
||||||
for (const spec of await findSpecs(path.join(pluginPath, specDir))) {
|
const specDir = `${plugin === 'ep_etherpad-lite' ? '' : 'static/'}tests/frontend/specs`;
|
||||||
if (plugin === 'ep_etherpad-lite' && !settings.enableAdminUITests &&
|
for (const spec of await findSpecs(path.join(pluginPath, specDir))) {
|
||||||
spec.startsWith('admin')) continue;
|
if (plugin === 'ep_etherpad-lite' && !settings.enableAdminUITests &&
|
||||||
modules.push(`${plugin}/${specDir}/${spec.replace(/\.js$/, '')}`);
|
spec.startsWith('admin')) continue;
|
||||||
}
|
modules.push(`${plugin}/${specDir}/${spec.replace(/\.js$/, '')}`);
|
||||||
}));
|
}
|
||||||
// Sort plugin tests before core tests.
|
}));
|
||||||
modules.sort((a, b) => {
|
// Sort plugin tests before core tests.
|
||||||
a = String(a);
|
modules.sort((a, b) => {
|
||||||
b = String(b);
|
a = String(a);
|
||||||
const aCore = a.startsWith('ep_etherpad-lite/');
|
b = String(b);
|
||||||
const bCore = b.startsWith('ep_etherpad-lite/');
|
const aCore = a.startsWith('ep_etherpad-lite/');
|
||||||
if (aCore === bCore) return a.localeCompare(b);
|
const bCore = b.startsWith('ep_etherpad-lite/');
|
||||||
return aCore ? 1 : -1;
|
if (aCore === bCore) return a.localeCompare(b);
|
||||||
});
|
return aCore ? 1 : -1;
|
||||||
console.debug('Sent browser the following test spec modules:', modules);
|
});
|
||||||
res.setHeader('content-type', 'application/javascript');
|
console.debug('Sent browser the following test spec modules:', modules);
|
||||||
res.end(`window.frontendTestSpecs = ${JSON.stringify(modules, null, 2)};\n`);
|
res.setHeader('content-type', 'application/javascript');
|
||||||
|
res.end(`window.frontendTestSpecs = ${JSON.stringify(modules, null, 2)};\n`);
|
||||||
|
})().catch((err) => next(err || new Error(err)));
|
||||||
});
|
});
|
||||||
|
|
||||||
const rootTestFolder = path.join(settings.root, 'src/tests/frontend/');
|
const rootTestFolder = path.join(settings.root, 'src/tests/frontend/');
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue