diff --git a/bin/cli.js b/bin/cli.js index 4fdab51a..e5159772 100755 --- a/bin/cli.js +++ b/bin/cli.js @@ -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]; } diff --git a/lib/test_task.js b/lib/test_task.js new file mode 100644 index 00000000..2d26a0a6 --- /dev/null +++ b/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; +