-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.js
52 lines (44 loc) · 1.13 KB
/
index.js
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
var through2 = require('through2'),
nodeunit = require('nodeunit'),
baseReporterOpts = require('nodeunit/bin/nodeunit.json');
var extend;
extend = function (a, b) {
a = a || {};
if (b) {
Object.keys(b).forEach(function (k) {
a[k] = b[k];
});
}
return a;
};
module.exports = function (options) {
var files = [],
cache = {},
config, reporterOpts, reporter;
config = extend({
reporter: 'default'
}, options);
reporterOpts = extend(extend({}, baseReporterOpts), config.reporterOptions);
reporter = nodeunit.reporters[config.reporter];
if (!reporter) {
reporter = require(config.reporter);
}
// Save a copy of the require cache before testing
Object.keys(require.cache).forEach(function (k) {
cache[k] = true;
});
return through2.obj(function (file, enc, done) {
files.push(file.path);
done();
}, function (done) {
reporter.run(files, reporterOpts, function (err) {
// Delete any modules that were added to the require cache
Object.keys(require.cache).filter(function (k) {
return !cache[k];
}).forEach(function (k) {
delete require.cache[k];
});
done(err);
});
});
};