tests: Switch to promisified `readFile`

pull/5050/head
Richard Hansen 2021-05-09 16:36:47 -04:00
parent 6cf27a7133
commit 998e77ec25
1 changed files with 6 additions and 9 deletions

View File

@ -46,20 +46,17 @@ exports.expressCreateServer = (hookName, args, cb) => {
return filePath; return filePath;
}; };
args.app.get('/tests/frontend/specs/*', (req, res) => { args.app.get('/tests/frontend/specs/*', (req, res, next) => {
(async () => {
const specFilePath = url2FilePath(req.url); const specFilePath = url2FilePath(req.url);
const specFileName = path.basename(specFilePath); const specFileName = path.basename(specFilePath);
let content = await fsp.readFile(specFilePath);
fs.readFile(specFilePath, (err, content) => {
if (err) { return res.send(500); }
content = `describe(${JSON.stringify(specFileName)}, function(){${content}});`; content = `describe(${JSON.stringify(specFileName)}, function(){${content}});`;
if (!specFilePath.endsWith('index.html')) { if (!specFilePath.endsWith('index.html')) {
res.setHeader('content-type', 'application/javascript'); res.setHeader('content-type', 'application/javascript');
} }
res.send(content); res.send(content);
}); })().catch((err) => next(err || new Error(err)));
}); });
args.app.get('/tests/frontend/*', (req, res) => { args.app.get('/tests/frontend/*', (req, res) => {