From 594d27233449979ff0e4107e1e3a312cc1c3f9e7 Mon Sep 17 00:00:00 2001 From: John McLear Date: Sun, 3 Feb 2013 00:14:17 +0000 Subject: [PATCH 1/5] allow plugins to specify frontend test specs --- src/node/hooks/express/tests.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/node/hooks/express/tests.js b/src/node/hooks/express/tests.js index 94cd5fb62..50fef8004 100644 --- a/src/node/hooks/express/tests.js +++ b/src/node/hooks/express/tests.js @@ -5,6 +5,17 @@ var path = require("path") exports.expressCreateServer = function (hook_name, args, cb) { args.app.get('/tests/frontend/specs_list.js', function(req, res){ fs.readdir('tests/frontend/specs', function(err, files){ + + fs.readdir('node_modules', function(err, plugins){ // installed plugins + plugins.forEach(function(plugin){ // for each one + if(fs.existsSync("node_modules/"+plugin+"/tests/frontend/specs")){ // If the folder exists + fs.readdir("node_modules/"+plugin+"/tests/frontend/specs/", function(err, pluginFiles){ + files.push(pluginFiles); + }); + } + }); + }); + if(err){ return res.send(500); } res.send("var specs_list = " + JSON.stringify(files.sort()) + ";\n"); @@ -44,4 +55,4 @@ exports.expressCreateServer = function (hook_name, args, cb) { args.app.get('/tests/frontend', function (req, res) { res.redirect('/tests/frontend/'); }); -} \ No newline at end of file +} From 0ff9f53297d178da52f761b5f5d737264fadb7b1 Mon Sep 17 00:00:00 2001 From: John McLear Date: Sun, 3 Feb 2013 00:18:24 +0000 Subject: [PATCH 2/5] correct path --- src/node/hooks/express/tests.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/node/hooks/express/tests.js b/src/node/hooks/express/tests.js index 50fef8004..9aeaefe6a 100644 --- a/src/node/hooks/express/tests.js +++ b/src/node/hooks/express/tests.js @@ -10,7 +10,7 @@ exports.expressCreateServer = function (hook_name, args, cb) { plugins.forEach(function(plugin){ // for each one if(fs.existsSync("node_modules/"+plugin+"/tests/frontend/specs")){ // If the folder exists fs.readdir("node_modules/"+plugin+"/tests/frontend/specs/", function(err, pluginFiles){ - files.push(pluginFiles); + files.push("/static/plugins/"+plugin+"/tests/frontend/specs/"+pluginFiles); }); } }); From 8b8cf0178521739b0de1e29da5102f97ca93af27 Mon Sep 17 00:00:00 2001 From: John McLear Date: Sun, 3 Feb 2013 13:53:44 +0000 Subject: [PATCH 3/5] put tests in static folder, still have a race condition no biggy --- src/node/hooks/express/tests.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/node/hooks/express/tests.js b/src/node/hooks/express/tests.js index 9aeaefe6a..988c3c0c2 100644 --- a/src/node/hooks/express/tests.js +++ b/src/node/hooks/express/tests.js @@ -8,9 +8,9 @@ exports.expressCreateServer = function (hook_name, args, cb) { fs.readdir('node_modules', function(err, plugins){ // installed plugins plugins.forEach(function(plugin){ // for each one - if(fs.existsSync("node_modules/"+plugin+"/tests/frontend/specs")){ // If the folder exists - fs.readdir("node_modules/"+plugin+"/tests/frontend/specs/", function(err, pluginFiles){ - files.push("/static/plugins/"+plugin+"/tests/frontend/specs/"+pluginFiles); + if(fs.existsSync("node_modules/"+plugin+"/static/tests/frontend/specs")){ // If the folder exists + fs.readdir("node_modules/"+plugin+"/static/tests/frontend/specs/", function(err, pluginFiles){ + files.push("/static/plugins/"+plugin+"/static/tests/frontend/specs/"+pluginFiles); }); } }); From da0b331502a8aac5e9bf12ff0479668f1e605cb2 Mon Sep 17 00:00:00 2001 From: John McLear Date: Mon, 4 Feb 2013 00:00:39 +0000 Subject: [PATCH 4/5] Make async and cleaner --- src/node/hooks/express/tests.js | 56 ++++++++++++++++++++++++--------- 1 file changed, 41 insertions(+), 15 deletions(-) diff --git a/src/node/hooks/express/tests.js b/src/node/hooks/express/tests.js index 988c3c0c2..3157d68ed 100644 --- a/src/node/hooks/express/tests.js +++ b/src/node/hooks/express/tests.js @@ -1,25 +1,26 @@ var path = require("path") , npm = require("npm") - , fs = require("fs"); + , fs = require("fs") + , async = require("async"); exports.expressCreateServer = function (hook_name, args, cb) { args.app.get('/tests/frontend/specs_list.js', function(req, res){ - fs.readdir('tests/frontend/specs', function(err, files){ - fs.readdir('node_modules', function(err, plugins){ // installed plugins - plugins.forEach(function(plugin){ // for each one - if(fs.existsSync("node_modules/"+plugin+"/static/tests/frontend/specs")){ // If the folder exists - fs.readdir("node_modules/"+plugin+"/static/tests/frontend/specs/", function(err, pluginFiles){ - files.push("/static/plugins/"+plugin+"/static/tests/frontend/specs/"+pluginFiles); - }); - } - }); - }); - - if(err){ return res.send(500); } - - res.send("var specs_list = " + JSON.stringify(files.sort()) + ";\n"); + async.parallel({ + coreSpecs: function(callback){ + exports.getCoreTests(callback); + }, + pluginSpecs: function(callback){ + exports.getPluginTests(callback); + } + }, + 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"); }); + }); var url2FilePath = function(url){ @@ -56,3 +57,28 @@ exports.expressCreateServer = function (hook_name, args, cb) { res.redirect('/tests/frontend/'); }); } + +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); + }, + function(err){ + // blow up if something bad happens! + }); + } + }); + 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); } + callback(null, coreSpecs); + }); +} + From de07d5a3e1a470ccb1f8be8ec76744a5e79f56b1 Mon Sep 17 00:00:00 2001 From: John McLear Date: Mon, 4 Feb 2013 00:03:25 +0000 Subject: [PATCH 5/5] make plugin specs finally work --- tests/frontend/runner.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/tests/frontend/runner.js b/tests/frontend/runner.js index 1679664bf..55f0a45bd 100644 --- a/tests/frontend/runner.js +++ b/tests/frontend/runner.js @@ -179,7 +179,11 @@ $(function(){ //inject spec scripts into the dom var $body = $('body'); $.each(specs, function(i, spec){ - $body.append('') + if(spec[0] != "/"){ // if the spec isn't a plugin spec which means the spec file might be in a different subfolder + $body.append('') + }else{ + $body.append('') + } }); //initalize the test helper @@ -196,4 +200,4 @@ $(function(){ mocha.run(); }); -}); \ No newline at end of file +});