mirror of
https://github.com/ether/etherpad-lite.git
synced 2025-04-21 07:56:16 -04:00
lint: Run eslint --fix
on src/
This commit is contained in:
parent
b8d07a42eb
commit
8e5fd19db2
109 changed files with 9061 additions and 10572 deletions
|
@ -1,13 +1,13 @@
|
|||
var path = require("path")
|
||||
, npm = require("npm")
|
||||
, fs = require("fs")
|
||||
, util = require("util");
|
||||
const path = require('path');
|
||||
const npm = require('npm');
|
||||
const fs = require('fs');
|
||||
const util = require('util');
|
||||
|
||||
exports.expressCreateServer = function (hook_name, args, cb) {
|
||||
args.app.get('/tests/frontend/specs_list.js', async function(req, res) {
|
||||
let [coreTests, pluginTests] = await Promise.all([
|
||||
args.app.get('/tests/frontend/specs_list.js', async (req, res) => {
|
||||
const [coreTests, pluginTests] = await Promise.all([
|
||||
exports.getCoreTests(),
|
||||
exports.getPluginTests()
|
||||
exports.getPluginTests(),
|
||||
]);
|
||||
|
||||
// merge the two sets of results
|
||||
|
@ -16,79 +16,77 @@ exports.expressCreateServer = function (hook_name, args, cb) {
|
|||
// Keep only *.js files
|
||||
files = files.filter((f) => f.endsWith('.js'));
|
||||
|
||||
console.debug("Sent browser the following test specs:", files);
|
||||
console.debug('Sent browser the following test specs:', files);
|
||||
res.setHeader('content-type', 'text/javascript');
|
||||
res.end("var specs_list = " + JSON.stringify(files) + ";\n");
|
||||
res.end(`var specs_list = ${JSON.stringify(files)};\n`);
|
||||
});
|
||||
|
||||
// path.join seems to normalize by default, but we'll just be explicit
|
||||
var rootTestFolder = path.normalize(path.join(npm.root, "../tests/frontend/"));
|
||||
const rootTestFolder = path.normalize(path.join(npm.root, '../tests/frontend/'));
|
||||
|
||||
var url2FilePath = function(url) {
|
||||
var subPath = url.substr("/tests/frontend".length);
|
||||
if (subPath == "") {
|
||||
subPath = "index.html"
|
||||
const url2FilePath = function (url) {
|
||||
let subPath = url.substr('/tests/frontend'.length);
|
||||
if (subPath == '') {
|
||||
subPath = 'index.html';
|
||||
}
|
||||
subPath = subPath.split("?")[0];
|
||||
subPath = subPath.split('?')[0];
|
||||
|
||||
var filePath = path.normalize(path.join(rootTestFolder, subPath));
|
||||
let filePath = path.normalize(path.join(rootTestFolder, subPath));
|
||||
|
||||
// make sure we jail the paths to the test folder, otherwise serve index
|
||||
if (filePath.indexOf(rootTestFolder) !== 0) {
|
||||
filePath = path.join(rootTestFolder, "index.html");
|
||||
filePath = path.join(rootTestFolder, 'index.html');
|
||||
}
|
||||
return filePath;
|
||||
}
|
||||
};
|
||||
|
||||
args.app.get('/tests/frontend/specs/*', function (req, res) {
|
||||
var specFilePath = url2FilePath(req.url);
|
||||
var specFileName = path.basename(specFilePath);
|
||||
args.app.get('/tests/frontend/specs/*', (req, res) => {
|
||||
const specFilePath = url2FilePath(req.url);
|
||||
const specFileName = path.basename(specFilePath);
|
||||
|
||||
fs.readFile(specFilePath, function(err, content) {
|
||||
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} });`;
|
||||
|
||||
res.send(content);
|
||||
});
|
||||
});
|
||||
|
||||
args.app.get('/tests/frontend/*', function (req, res) {
|
||||
var filePath = url2FilePath(req.url);
|
||||
args.app.get('/tests/frontend/*', (req, res) => {
|
||||
const filePath = url2FilePath(req.url);
|
||||
res.sendFile(filePath);
|
||||
});
|
||||
|
||||
args.app.get('/tests/frontend', function (req, res) {
|
||||
args.app.get('/tests/frontend', (req, res) => {
|
||||
res.redirect('/tests/frontend/index.html');
|
||||
});
|
||||
|
||||
return cb();
|
||||
}
|
||||
};
|
||||
|
||||
const readdir = util.promisify(fs.readdir);
|
||||
|
||||
exports.getPluginTests = async function(callback) {
|
||||
const moduleDir = "node_modules/";
|
||||
const specPath = "/static/tests/frontend/specs/";
|
||||
const staticDir = "/static/plugins/";
|
||||
exports.getPluginTests = async function (callback) {
|
||||
const moduleDir = 'node_modules/';
|
||||
const specPath = '/static/tests/frontend/specs/';
|
||||
const staticDir = '/static/plugins/';
|
||||
|
||||
let pluginSpecs = [];
|
||||
const pluginSpecs = [];
|
||||
|
||||
let plugins = await readdir(moduleDir);
|
||||
let promises = plugins
|
||||
.map(plugin => [ plugin, moduleDir + plugin + specPath] )
|
||||
.filter(([plugin, specDir]) => fs.existsSync(specDir)) // check plugin exists
|
||||
.map(([plugin, specDir]) => {
|
||||
return readdir(specDir)
|
||||
.then(specFiles => specFiles.map(spec => {
|
||||
pluginSpecs.push(staticDir + plugin + specPath + spec);
|
||||
}));
|
||||
});
|
||||
const plugins = await readdir(moduleDir);
|
||||
const promises = plugins
|
||||
.map((plugin) => [plugin, moduleDir + plugin + specPath])
|
||||
.filter(([plugin, specDir]) => fs.existsSync(specDir)) // check plugin exists
|
||||
.map(([plugin, specDir]) => readdir(specDir)
|
||||
.then((specFiles) => specFiles.map((spec) => {
|
||||
pluginSpecs.push(staticDir + plugin + specPath + spec);
|
||||
})));
|
||||
|
||||
return Promise.all(promises).then(() => pluginSpecs);
|
||||
}
|
||||
};
|
||||
|
||||
exports.getCoreTests = function() {
|
||||
exports.getCoreTests = function () {
|
||||
// get the core test specs
|
||||
return readdir('tests/frontend/specs');
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue