lint: src/node/hooks/express/tests.js

pull/4667/head
John McLear 2021-01-21 21:06:52 +00:00 committed by Richard Hansen
parent 6df3eadecd
commit 2dec36bfd7
1 changed files with 10 additions and 10 deletions

View File

@ -1,9 +1,11 @@
'use strict';
const path = require('path'); const path = require('path');
const npm = require('npm'); const npm = require('npm');
const fs = require('fs'); const fs = require('fs');
const util = require('util'); const util = require('util');
exports.expressCreateServer = function (hook_name, args, cb) { exports.expressCreateServer = (hookName, args, cb) => {
args.app.get('/tests/frontend/specs_list.js', async (req, res) => { args.app.get('/tests/frontend/specs_list.js', async (req, res) => {
const [coreTests, pluginTests] = await Promise.all([ const [coreTests, pluginTests] = await Promise.all([
exports.getCoreTests(), exports.getCoreTests(),
@ -24,9 +26,9 @@ exports.expressCreateServer = function (hook_name, args, cb) {
// path.join seems to normalize by default, but we'll just be explicit // path.join seems to normalize by default, but we'll just be explicit
const rootTestFolder = path.normalize(path.join(npm.root, '../tests/frontend/')); const rootTestFolder = path.normalize(path.join(npm.root, '../tests/frontend/'));
const url2FilePath = function (url) { const url2FilePath = (url) => {
let subPath = url.substr('/tests/frontend'.length); let subPath = url.substr('/tests/frontend'.length);
if (subPath == '') { if (subPath === '') {
subPath = 'index.html'; subPath = 'index.html';
} }
subPath = subPath.split('?')[0]; subPath = subPath.split('?')[0];
@ -49,8 +51,9 @@ exports.expressCreateServer = function (hook_name, args, cb) {
content = `describe(${JSON.stringify(specFileName)}, function(){ ${content} });`; content = `describe(${JSON.stringify(specFileName)}, function(){ ${content} });`;
if(!specFilePath.endsWith('index.html')) res.setHeader('content-type', 'application/javascript'); if (!specFilePath.endsWith('index.html')) {
res.setHeader('content-type', 'application/javascript');
}
res.send(content); res.send(content);
}); });
}); });
@ -69,7 +72,7 @@ exports.expressCreateServer = function (hook_name, args, cb) {
const readdir = util.promisify(fs.readdir); const readdir = util.promisify(fs.readdir);
exports.getPluginTests = async function (callback) { exports.getPluginTests = async (callback) => {
const moduleDir = 'node_modules/'; const moduleDir = 'node_modules/';
const specPath = '/static/tests/frontend/specs/'; const specPath = '/static/tests/frontend/specs/';
const staticDir = '/static/plugins/'; const staticDir = '/static/plugins/';
@ -88,7 +91,4 @@ exports.getPluginTests = async function (callback) {
return Promise.all(promises).then(() => pluginSpecs); return Promise.all(promises).then(() => pluginSpecs);
}; };
exports.getCoreTests = function () { exports.getCoreTests = () => readdir('tests/frontend/specs');
// get the core test specs
return readdir('tests/frontend/specs');
};