UNPKG

1.59 kBJavaScriptView Raw
1/**
2 * Run nodeunit test.
3 * @memberof module:apeman-dev-commons-testing/lib
4 * @function runNodeunit
5 * @param {string|string[]} pattern - File names
6 * @param {object} [options] - Optional settings.
7 * @param {function} [callback] - Callback when done.
8 */
9
10"use strict";
11
12var argx = require('argx'),
13 h = require('./_helper'),
14 glob = require('glob'),
15 async = require('async');
16
17/** @lends runNodeunit */
18function 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
57function _concatPatterns(patterns, callback) {
58 async.concat([].concat(patterns || []), glob, callback);
59}
60
61
62module.exports = runNodeunit;
\No newline at end of file