tests: Switch to promisified `readFile`
parent
6cf27a7133
commit
998e77ec25
|
@ -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) => {
|
||||||
const specFilePath = url2FilePath(req.url);
|
(async () => {
|
||||||
const specFileName = path.basename(specFilePath);
|
const specFilePath = url2FilePath(req.url);
|
||||||
|
const specFileName = path.basename(specFilePath);
|
||||||
fs.readFile(specFilePath, (err, content) => {
|
let content = await fsp.readFile(specFilePath);
|
||||||
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) => {
|
||||||
|
|
Loading…
Reference in New Issue