diff --git a/src/node/hooks/express/tests.js b/src/node/hooks/express/tests.js index 94cd5fb62..3157d68ed 100644 --- a/src/node/hooks/express/tests.js +++ b/src/node/hooks/express/tests.js @@ -1,14 +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){ - 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){ @@ -44,4 +56,29 @@ 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 +} + +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); + }); +} + 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 +});