Permalink
Browse files

Only pass `next` for async tests, namespace all tests to prevent coll…

…ision with test-name
  • Loading branch information...
1 parent e1c7b11 commit 5b955f1b8da041153a85c0c3ec2e2679151cda81 mde committed Jun 23, 2012
Showing with 28 additions and 17 deletions.
  1. +28 −17 lib/test_task.js
View
@@ -40,7 +40,7 @@ var path = require('path')
@example
var t = new jake.TestTask('bij-js', function () {
this.testName = 'testSpecial';
- this.testFiles.include('test/**/*.js');
+ this.testFiles.include('test/**');
});
*/
@@ -96,9 +96,13 @@ var TestTask = function (name, definition) {
// A wrapped function that passes in the `next` function
// for any tasks that run asynchronously
return function () {
+ var cb;
+ if (a.length) {
+ cb = next;
+ }
jake.logger.log('Running ' + n);
// 'this' will be the task when action is run
- return a.call(this, next);
+ return a.call(this, cb);
};
};
@@ -111,21 +115,28 @@ var TestTask = function (name, definition) {
, action
, isAsync;
- for (var p in exp) {
- name = p;
- action = exp[p];
- // If the test-function is defined with a continuation
- // param, flag the task as async
- isAsync = !!action.length;
- // Add the name of this test to the list of prereqs
- // for the dummy top-level task
- prereqs.push(name);
- // Define the actual task with the name, the wrapped action,
- // and the correc async-flag
- task(name, createAction(name, action), {
- async: isAsync
- });
- }
+ // Create a namespace for each filename, so test-name collisions
+ // won't be a problem
+ namespace(file, function () {
+ // Walk each exported function, and create a task for each
+ for (var p in exp) {
+ name = p;
+ action = exp[p];
+ // If the test-function is defined with a continuation
+ // param, flag the task as async
+ isAsync = !!action.length;
+ // Add the namespace:name of this test to the list of prereqs
+ // for the dummy top-level task
+ prereqs.push(file + ':' + name);
+
+ // Define the actual namespaced task with the name, the
+ // wrapped action, and the correc async-flag
+ task(name, createAction(name, action), {
+ async: isAsync
+ });
+ }
+
+ });
});
// Create the dummy top-level task. When calling a task internally

0 comments on commit 5b955f1

Please sign in to comment.