Permalink
Browse files

Better API and use FileList for TestTask

  • Loading branch information...
1 parent 071dcee commit d7f9ea17adffa2ad0787c2d9dafae90edb31d938 mde committed Jun 21, 2012
Showing with 19 additions and 17 deletions.
  1. +19 −17 lib/test_task.js
View
@@ -21,31 +21,33 @@ var path = require('path')
, exec = require('child_process').exec
, currDir = process.cwd();
-var TestTask = function (projectName, directory, namespaceName) {
- var ns = namespaceName || 'test';
+var TestTask = function (name, definition) {
+ var self = this;
- desc('Run the tests for ' + projectName);
- task(ns, function () {
- var t = jake.Task[ns + ':run'];
+ this.testName = 'test';
+ this.testFiles = new jake.FileList();
+
+ if (typeof definition == 'function') {
+ definition.call(this);
+ }
+
+ desc('Run the tests for ' + name);
+ task(this.testName, function () {
+ var t = jake.Task[self.testName + ':run'];
t.invoke.apply(t, arguments);
}, {async: true});
- namespace(ns, function () {
+ namespace(self.testName, function () {
task('run', function (pat) {
var p = pat || '.*'
- , re = new RegExp(pat);
- // Grab all the JS files in the specified directory
- // that match any regex passed in
- var jsFiles = jake.readdirR(directory)
- .filter(function (f) {
- return (/\.js$/).test(f);
- })
- .filter(function (f) {
+ , re = new RegExp(pat)
+ , testFiles = self.testFiles.toArray().filter(function (f) {
return (re).test(f);
});
+
// Create a namespace for all the testing tasks to live in
- namespace(ns + 'Exec', function () {
+ namespace(self.testName + 'Exec', function () {
// Each test will be a prereq for the dummy top-level task
var prereqs = []
// Continuation to pass to the async tests, wrapping `continune`
@@ -66,7 +68,7 @@ var TestTask = function (projectName, directory, namespaceName) {
// Pull in each test-file, and iterate over any exported
// test-functions. Register each test-function as a prereq
// task
- jsFiles.forEach(function (file) {
+ testFiles.forEach(function (file) {
var exp = require(path.join(currDir, file))
, name
, action
@@ -93,7 +95,7 @@ var TestTask = function (projectName, directory, namespaceName) {
// with `invoke` that is async (or has async prereqs), have to listen
// for the 'complete' event to know when it's done
task('__top__', prereqs);
- var t = jake.Task[ns + 'Exec:__top__'];
+ var t = jake.Task[self.testName + 'Exec:__top__'];
t.addListener('complete', function () {
jake.logger.log('All tests ran successfully');
complete();

0 comments on commit d7f9ea1

Please sign in to comment.