From 995e381243304a217f2f013ea90e091870943304 Mon Sep 17 00:00:00 2001 From: Richard Hansen Date: Sun, 9 May 2021 17:23:02 -0400 Subject: [PATCH] tests: Only wrap `*.js` files in `describe()` --- src/node/hooks/express/tests.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/node/hooks/express/tests.js b/src/node/hooks/express/tests.js index 7c2795af2..9e1e02873 100644 --- a/src/node/hooks/express/tests.js +++ b/src/node/hooks/express/tests.js @@ -47,14 +47,14 @@ exports.expressCreateServer = (hookName, args, cb) => { // version used with Express v4.x) interprets '.' and '*' differently than regexp. args.app.get('/tests/frontend/specs/:file([\\d\\D]{0,})', (req, res, next) => { (async () => { - const specFilePath = sanitizePath(`specs/${req.params.file}`); - const specFileName = path.basename(specFilePath); - let content = await fsp.readFile(specFilePath); - content = `describe(${JSON.stringify(specFileName)}, function(){${content}});`; - if (!specFilePath.endsWith('index.html')) { + const file = sanitizePath(`specs/${req.params.file}`); + if (file.endsWith('.js')) { + const content = await fsp.readFile(file); 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))); });