UNPKG

1.37 kBJavaScriptView Raw
1/**
2 * @file Run apeman-task-contrib-nodeunit
3 */
4
5"use strict";
6
7var async = require('async'),
8 glob = require('glob'),
9 argx = require('argx'),
10 objnest = require('objnest');
11
12/** @lends apemanTaskContribNodeunit */
13function apemanTaskContribNodeunit(context, patterns, options, callback) {
14 var args = argx(arguments);
15 context = args.shift('object') || {};
16 callback = args.pop('function') || argx.noop;
17 options = objnest.expand(args.pop('object') || {});
18 patterns = args.remain();
19
20 var nodeunit = require('nodeunit');
21
22 var hasReporters = Object.keys(nodeunit.reporters).length > 0;
23 if (!hasReporters) {
24 callback(null);
25 return;
26 }
27 var reporterName = (options.reporter || 'default'),
28 reporter = nodeunit.reporters[reporterName];
29 if (!reporter) {
30 callback(new Error('Unknown reporter: ' + reporterName));
31 return;
32 }
33
34 async.waterfall([
35 function (callback) {
36 _concatPatterns(patterns, callback);
37 },
38 function (filenames, callback) {
39 var options = require('./nodeunit_options.json');
40 reporter.run(filenames, options, callback);
41 }
42 ], callback);
43
44}
45
46function _concatPatterns(patterns, callback) {
47 async.concat([].concat(patterns || []), glob, callback);
48}
49
50
51module.exports = apemanTaskContribNodeunit;