From 998e77ec25d8037638253c637be5635ff2248c57 Mon Sep 17 00:00:00 2001 From: Richard Hansen Date: Sun, 9 May 2021 16:36:47 -0400 Subject: [PATCH] tests: Switch to promisified `readFile` --- src/node/hooks/express/tests.js | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/src/node/hooks/express/tests.js b/src/node/hooks/express/tests.js index e5fc24c7c..e8e3108b9 100644 --- a/src/node/hooks/express/tests.js +++ b/src/node/hooks/express/tests.js @@ -46,20 +46,17 @@ exports.expressCreateServer = (hookName, args, cb) => { return filePath; }; - args.app.get('/tests/frontend/specs/*', (req, res) => { - const specFilePath = url2FilePath(req.url); - const specFileName = path.basename(specFilePath); - - fs.readFile(specFilePath, (err, content) => { - if (err) { return res.send(500); } - + args.app.get('/tests/frontend/specs/*', (req, res, next) => { + (async () => { + const specFilePath = url2FilePath(req.url); + const specFileName = path.basename(specFilePath); + let content = await fsp.readFile(specFilePath); content = `describe(${JSON.stringify(specFileName)}, function(){${content}});`; - if (!specFilePath.endsWith('index.html')) { res.setHeader('content-type', 'application/javascript'); } res.send(content); - }); + })().catch((err) => next(err || new Error(err))); }); args.app.get('/tests/frontend/*', (req, res) => {