1 |
|
2 |
|
3 |
|
4 |
|
5 | "use strict";
|
6 |
|
7 | var async = require('async'),
|
8 | glob = require('glob'),
|
9 | argx = require('argx'),
|
10 | objnest = require('objnest');
|
11 |
|
12 |
|
13 | function 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 |
|
46 | function _concatPatterns(patterns, callback) {
|
47 | async.concat([].concat(patterns || []), glob, callback);
|
48 | }
|
49 |
|
50 |
|
51 | module.exports = apemanTaskContribNodeunit;
|