Skip to content

Commit

Permalink
First stab at a built-in for running tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mde committed Jun 19, 2012
1 parent 03814ea commit 50973b2
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 0 deletions.
1 change: 1 addition & 0 deletions bin/cli.js
Expand Up @@ -59,6 +59,7 @@ if (!program.preemptiveOption()) {
jake.FileList = require(libPath + '/file_list').FileList;
jake.PackageTask = require(libPath + '/package_task').PackageTask;
jake.NpmPublishTask = require(libPath + '/npm_publish_task').NpmPublishTask;
jake.TestTask = require(libPath + '/test_task').TestTask;

// Enhance env with any env vars passed in
for (var p in envVars) { process.env[p] = envVars[p]; }
Expand Down
71 changes: 71 additions & 0 deletions lib/test_task.js
@@ -0,0 +1,71 @@
/*
* Jake JavaScript build tool
* Copyright 2112 Matthew Eernisse (mde@fleegix.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

var path = require('path')
, fs = require('fs')
, exec = require('child_process').exec
, currDir = process.cwd();

var TestTask = function (directory) {

this.directory = directory;

namespace('test', function () {


task('run', function () {
var jsFiles = jake.readdirR(directory).filter(function (f) {
return /\.js$/.test(f);
});
namespace('testExec', function () {
var prereqs = []
, next = function () {
complete();
}
, createAction = function (a) {
return a(next);
};

jsFiles.forEach(function (file) {
var exp = require(path.join(currDir, file))
, name
, action;
for (var p in exp) {
name = p;
action = exp[p];
prereqs.push(name);
task(name, createAction(action), {
async: !!action.length
});
}
});

task('__top__', prereqs);
jake.Task['testExec:__top__'].invoke();
});
});
});




};

jake.TestTask = TestTask;
exports.TestTask = TestTask;

0 comments on commit 50973b2

Please sign in to comment.