Created
September 13, 2012 16:41
-
-
Save IvanTorresEdge/3715654 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var walk = require('./walk'); | |
| var TEST_DIRECTORY = process.cwd() + '/public/test/app'; | |
| var renderView = function (res, filenames) { | |
| var conf = { filenames: filenames }; | |
| view = process.cwd() + '/assets/test/runner.hbs'; | |
| res.render(view, conf); | |
| }; | |
| var render = function (req, res) { | |
| if (typeof req.hasOwnProperty('files')) { | |
| filenames = req.params.files.split(','); | |
| filenames = filenames.map(function (path) { | |
| return '/test/app/' + path + ".js"; | |
| }); | |
| return renderView(res, filenames); | |
| } else { | |
| walk(TEST_DIRECTORY, function(err, filenames) { | |
| if (err) throw err; | |
| return renderView(res, filenames); | |
| }); | |
| } | |
| }; | |
| exports.render = render; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var walk = require('./walk'); | |
| var TEST_DIRECTORY = process.cwd() + "/assets/test/app/"; | |
| var render_given_paths = function (res, paths) { | |
| res.render(process.cwd() + "/assets/test/runner.hbs", { | |
| testpaths: paths.map(function (path) { | |
| return path; | |
| }) | |
| }); | |
| }; | |
| var get_all_test_paths = function (callback) { | |
| walk(TEST_DIRECTORY, function(err, results) { | |
| var path, regexp, result, _i, _len; | |
| if (err) throw err; | |
| var paths = []; | |
| for (_i = 0, _len = results.length; _i < _len; _i++) { | |
| result = results[_i]; | |
| path = result.replace(/assets\//, ''); | |
| regexp = /\.\/(.*)\.[coffee|js]/; | |
| matches = path.match(regexp); | |
| if (!matches) { | |
| break; | |
| } | |
| path = matches[1].replace('//', '/'); //For some reason second slash being added | |
| paths.push("/" + path + ".js"); | |
| } | |
| callback(paths); | |
| }); | |
| }; | |
| var render_all_tests = function (res) { | |
| get_all_test_paths(function(paths) { | |
| return render_given_paths(res, paths); | |
| }); | |
| }; | |
| var render_some_tests = function (res, files) { | |
| var paths = files.replace(/^\s+|\s+$/g, "").split(','); | |
| paths = paths.map( | |
| function (path) { return '/test/app/' + path + ".js"; } | |
| ); | |
| return render_given_paths(res, paths); | |
| }; | |
| exports.render_tests = function (req, res) { | |
| var paths; | |
| if (typeof req.params['files'] !== 'undefined') { | |
| return render_some_tests(res, req.params['files']); | |
| } else { | |
| return render_all_tests(res); | |
| } | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment