forked from htm-community/river-view
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test-river.js
53 lines (44 loc) · 1.3 KB
/
test-river.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
53
var fs = require('fs');
var path = require('path');
var _ = require('lodash');
var async = require('async');
var Mocha = require('mocha');
var riverDir = path.join(__dirname, 'rivers');
var riverName = process.argv[2];
var runners = [];
function clearRiverTestsFromRequireCache() {
var key = _.filter(_.keys(require.cache), function(k) {
return (_.endsWith(k, 'river-tests.js'));
}).shift();
delete require.cache[key];
}
function testRiver(name, cb) {
console.log('Testing river %s', name);
var mocha = new Mocha({noExit: true});
global._RIVER_NAME_ = name;
// Must to this to force reload of the test.
clearRiverTestsFromRequireCache();
mocha.addFile(path.join('test', 'rivers', 'river-tests.js'));
mocha.run(function(failures) {
console.log('Done testing ' + name);
cb && cb(failures);
});
}
if (! riverName) {
_.each(fs.readdirSync(riverDir), function(name) {
if (fs.statSync(path.join(riverDir, name)).isDirectory()) {
runners.push(function(cb) {
testRiver(name, cb);
});
}
});
async.series(runners, function(failures) {
if (failures) {
process.exit(failures);
} else {
process.exit();
}
});
} else {
testRiver(riverName);
}