1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 | "use strict";
|
11 |
|
12 | var argx = require('argx'),
|
13 | h = require('./_helper'),
|
14 | glob = require('glob'),
|
15 | async = require('async');
|
16 |
|
17 |
|
18 | function runNodeunit(pattern, options, callback) {
|
19 | var args = argx(arguments);
|
20 | callback = args.pop('function') || argx.noop;
|
21 | options = args.pop('object');
|
22 | pattern = args.remain().reduce(function (a, b) {
|
23 | return a.concat(b);
|
24 | }, []);
|
25 |
|
26 | var nodeunit = require('nodeunit');
|
27 |
|
28 | var hasReporters = Object.keys(nodeunit.reporters).length > 0;
|
29 | if (!hasReporters) {
|
30 | callback(null);
|
31 | return;
|
32 | }
|
33 | var reporterName = (options.reporter || 'default'),
|
34 | reporter = nodeunit.reporters[reporterName];
|
35 | if (!reporter) {
|
36 | callback(new Error('Unknown reporter: ' + reporterName));
|
37 | return;
|
38 | }
|
39 |
|
40 | h.start();
|
41 |
|
42 | async.waterfall([
|
43 | function (callback) {
|
44 | _concatPatterns(pattern, callback);
|
45 | },
|
46 | function (filenames, callback) {
|
47 | var options = require('./_nodeunit_options.json');
|
48 | reporter.run(filenames, options, callback);
|
49 | }
|
50 | ], function (err) {
|
51 | h.end(err);
|
52 | callback(err);
|
53 | });
|
54 |
|
55 | }
|
56 |
|
57 | function _concatPatterns(patterns, callback) {
|
58 | async.concat([].concat(patterns || []), glob, callback);
|
59 | }
|
60 |
|
61 |
|
62 | module.exports = runNodeunit; |
\ | No newline at end of file |