6fd538b0e4e542d9bfeb9807e5acad1183fcdd2e.svn-base
2.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
/*!
* Nodeunit
* Copyright (c) 2010 Caolan McMahon
* MIT Licensed
*/
/**
* Module dependencies
*/
var async = require('../deps/async'),
types = require('./types'),
utils = require('./utils'),
core = require('./core'),
reporters = require('./reporters'),
assert = require('./assert'),
path = require('path')
events = require('events');
/**
* Export sub-modules.
*/
exports.types = types;
exports.utils = utils;
exports.reporters = reporters;
exports.assert = assert;
// backwards compatibility
exports.testrunner = {
run: function () {
console.log(
'WARNING: nodeunit.testrunner is going to be deprecated, please ' +
'use nodeunit.reporters.default instead!'
);
return reporters['default'].run.apply(this, arguments);
}
};
/**
* Export all core functions
*/
for (var k in core) {
exports[k] = core[k];
};
/**
* Load modules from paths array and run all exported tests in series. If a path
* is a directory, load all supported file types inside it as modules. This only
* reads 1 level deep in the directory and does not recurse through
* sub-directories.
*
* @param {Array} paths
* @param {Object} opt
* @api public
*/
exports.runFiles = function (paths, opt) {
var all_assertions = [];
var options = types.options(opt);
var start = new Date().getTime();
if (!paths.length) {
return options.done(types.assertionList(all_assertions));
}
utils.modulePaths(paths, function (err, files) {
if (err) throw err;
async.concatSeries(files, function (file, cb) {
var name = path.basename(file);
exports.runModule(name, require(file), options, cb);
},
function (err, all_assertions) {
var end = new Date().getTime();
exports.done()
options.done(types.assertionList(all_assertions, end - start));
});
});
};
/* Export all prototypes from events.EventEmitter */
var label;
for (label in events.EventEmitter.prototype) {
exports[label] = events.EventEmitter.prototype[label];
}
/* Emit event 'complete' on completion of a test suite. */
exports.complete = function(name, assertions)
{
exports.emit('complete', name, assertions);
};
/* Emit event 'complete' on completion of all tests. */
exports.done = function()
{
exports.emit('done');
};
module.exports = exports;