mirror of
https://github.com/ether/etherpad-lite.git
synced 2025-04-21 16:06:16 -04:00
tests: Combine frontend test file handlers
This commit is contained in:
parent
995e381243
commit
ade17490e0
1 changed files with 3 additions and 8 deletions
|
@ -45,10 +45,10 @@ exports.expressCreateServer = (hookName, args, cb) => {
|
||||||
// The regexp /[\d\D]{0,}/ is equivalent to the regexp /.*/. The Express route path used here
|
// The regexp /[\d\D]{0,}/ is equivalent to the regexp /.*/. The Express route path used here
|
||||||
// uses the more verbose /[\d\D]{0,}/ pattern instead of /.*/ because path-to-regexp v0.1.7 (the
|
// uses the more verbose /[\d\D]{0,}/ pattern instead of /.*/ because path-to-regexp v0.1.7 (the
|
||||||
// version used with Express v4.x) interprets '.' and '*' differently than regexp.
|
// version used with Express v4.x) interprets '.' and '*' differently than regexp.
|
||||||
args.app.get('/tests/frontend/specs/:file([\\d\\D]{0,})', (req, res, next) => {
|
args.app.get('/tests/frontend/:file([\\d\\D]{0,})', (req, res, next) => {
|
||||||
(async () => {
|
(async () => {
|
||||||
const file = sanitizePath(`specs/${req.params.file}`);
|
const file = sanitizePath(req.params.file);
|
||||||
if (file.endsWith('.js')) {
|
if (req.params.file.startsWith('specs/') && file.endsWith('.js')) {
|
||||||
const content = await fsp.readFile(file);
|
const content = await fsp.readFile(file);
|
||||||
res.setHeader('content-type', 'application/javascript');
|
res.setHeader('content-type', 'application/javascript');
|
||||||
res.send(`describe(${JSON.stringify(path.basename(file))}, function () {\n${content}\n});`);
|
res.send(`describe(${JSON.stringify(path.basename(file))}, function () {\n${content}\n});`);
|
||||||
|
@ -58,11 +58,6 @@ exports.expressCreateServer = (hookName, args, cb) => {
|
||||||
})().catch((err) => next(err || new Error(err)));
|
})().catch((err) => next(err || new Error(err)));
|
||||||
});
|
});
|
||||||
|
|
||||||
args.app.get('/tests/frontend/:file([\\d\\D]{0,})', (req, res) => {
|
|
||||||
const filePath = sanitizePath(req.params.file);
|
|
||||||
res.sendFile(filePath);
|
|
||||||
});
|
|
||||||
|
|
||||||
args.app.get('/tests/frontend', (req, res) => {
|
args.app.get('/tests/frontend', (req, res) => {
|
||||||
res.redirect('/tests/frontend/index.html');
|
res.redirect('/tests/frontend/index.html');
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue