tests: Only wrap `*.js` files in `describe()`

pull/5050/head
Richard Hansen 2021-05-09 17:23:02 -04:00
parent e1c2c963f0
commit 995e381243
1 changed files with 6 additions and 6 deletions

View File

@ -47,14 +47,14 @@ exports.expressCreateServer = (hookName, args, cb) => {
// 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/specs/:file([\\d\\D]{0,})', (req, res, next) => {
(async () => { (async () => {
const specFilePath = sanitizePath(`specs/${req.params.file}`); const file = sanitizePath(`specs/${req.params.file}`);
const specFileName = path.basename(specFilePath); if (file.endsWith('.js')) {
let content = await fsp.readFile(specFilePath); const content = await fsp.readFile(file);
content = `describe(${JSON.stringify(specFileName)}, function(){${content}});`;
if (!specFilePath.endsWith('index.html')) {
res.setHeader('content-type', 'application/javascript'); res.setHeader('content-type', 'application/javascript');
res.send(`describe(${JSON.stringify(path.basename(file))}, function () {\n${content}\n});`);
} else {
res.sendFile(file);
} }
res.send(content);
})().catch((err) => next(err || new Error(err))); })().catch((err) => next(err || new Error(err)));
}); });