prepare to async: trivial reformatting

This change is only cosmetic. Its aim is do make it easier to understand the
async changes that are going to be merged later on. It was extracted from the
original work from Ray Bellis.

To verify that nothing has changed, you can run the following command on each
file touched by this commit:
  npm install uglify-es
  diff --unified <(uglify-js --beautify bracketize <BEFORE.js>) <(uglify-js --beautify bracketize <AFTER.js>)



This is a complete script that does the same automatically (works from a
mercurial clone):

```bash
#!/usr/bin/env bash

set -eu

REVISION=<THIS_REVISION>

PARENT_REV=$(hg identify --rev "${REVISION}" --template '{p1rev}')
FILE_LIST=$(hg status --no-status --change ${REVISION})
UGLIFYJS="node_modules/uglify-es/bin/uglifyjs"

for FILE_NAME in ${FILE_LIST[@]}; do
  echo "Checking ${FILE_NAME}"
  diff --unified \
    <("${UGLIFYJS}" --beautify bracketize <(hg cat --rev "${PARENT_REV}" "${FILE_NAME}")) \
    <("${UGLIFYJS}" --beautify bracketize <(hg cat --rev "${REVISION}"   "${FILE_NAME}"))
done
```
This commit is contained in:
muxator 2019-02-08 23:20:57 +01:00
parent cc23bd18a4
commit 9497ee734f
33 changed files with 2706 additions and 2943 deletions

View file

@ -4,37 +4,35 @@ var path = require("path")
, async = require("async");
exports.expressCreateServer = function (hook_name, args, cb) {
args.app.get('/tests/frontend/specs_list.js', function(req, res){
args.app.get('/tests/frontend/specs_list.js', function(req, res) {
async.parallel({
coreSpecs: function(callback){
coreSpecs: function(callback) {
exports.getCoreTests(callback);
},
pluginSpecs: function(callback){
pluginSpecs: function(callback) {
exports.getPluginTests(callback);
}
},
function(err, results){
function(err, results) {
var files = results.coreSpecs; // push the core specs to a file object
files = files.concat(results.pluginSpecs); // add the plugin Specs to the core specs
console.debug("Sent browser the following test specs:", files.sort());
res.send("var specs_list = " + JSON.stringify(files.sort()) + ";\n");
});
});
// path.join seems to normalize by default, but we'll just be explicit
var rootTestFolder = path.normalize(path.join(npm.root, "../tests/frontend/"));
var url2FilePath = function(url){
var url2FilePath = function(url) {
var subPath = url.substr("/tests/frontend".length);
if (subPath == ""){
if (subPath == "") {
subPath = "index.html"
}
subPath = subPath.split("?")[0];
var 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");
@ -46,13 +44,13 @@ exports.expressCreateServer = function (hook_name, args, cb) {
var specFilePath = url2FilePath(req.url);
var specFileName = path.basename(specFilePath);
fs.readFile(specFilePath, function(err, content){
if(err){ return res.send(500); }
fs.readFile(specFilePath, function(err, content) {
if (err) { return res.send(500); }
content = "describe(" + JSON.stringify(specFileName) + ", function(){ " + content + " });";
res.send(content);
});
});
});
args.app.get('/tests/frontend/*', function (req, res) {
@ -62,19 +60,21 @@ exports.expressCreateServer = function (hook_name, args, cb) {
args.app.get('/tests/frontend', function (req, res) {
res.redirect('/tests/frontend/');
});
});
}
exports.getPluginTests = function(callback){
exports.getPluginTests = function(callback) {
var pluginSpecs = [];
var plugins = fs.readdirSync('node_modules');
plugins.forEach(function(plugin){
if(fs.existsSync("node_modules/"+plugin+"/static/tests/frontend/specs")){ // if plugins exists
var specFiles = fs.readdirSync("node_modules/"+plugin+"/static/tests/frontend/specs/");
async.forEach(specFiles, function(spec){ // for each specFile push it to pluginSpecs
pluginSpecs.push("/static/plugins/"+plugin+"/static/tests/frontend/specs/" + spec);
plugins.forEach(function(plugin) {
if (fs.existsSync("node_modules/" + plugin + "/static/tests/frontend/specs")) {
// if plugins exists
var specFiles = fs.readdirSync("node_modules/" + plugin + "/static/tests/frontend/specs/");
async.forEach(specFiles, function(spec) {
// for each specFile push it to pluginSpecs
pluginSpecs.push("/static/plugins/" + plugin + "/static/tests/frontend/specs/" + spec);
},
function(err){
function(err) {
// blow up if something bad happens!
});
}
@ -82,10 +82,11 @@ exports.getPluginTests = function(callback){
callback(null, pluginSpecs);
}
exports.getCoreTests = function(callback){
fs.readdir('tests/frontend/specs', function(err, coreSpecs){ // get the core test specs
if(err){ return res.send(500); }
exports.getCoreTests = function(callback) {
// get the core test specs
fs.readdir('tests/frontend/specs', function(err, coreSpecs) {
if (err) { return res.send(500); }
callback(null, coreSpecs);
});
}