forked from apigee-127/swagger-test-templates
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mocha.js
43 lines (34 loc) · 851 Bytes
/
mocha.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
'use strict';
var Mocha = require('mocha');
var fs = require('fs');
var path = require('path');
var mocha = new Mocha();
var testDir = path.join(__dirname, 'test');
var directories = [];
var dir;
function isTest(file) {
return file.substr(-7) === 'test.js';
}
function addTest(file) {
mocha.addFile(path.join(dir, file));
}
fs.readdirSync(testDir).filter(function(file) {
if (fs.statSync(path.join(testDir, file)).isDirectory()) {
directories.push(path.join(testDir, file));
} else if (isTest(file)) {
mocha.addFile(path.join(testDir, file));
}
});
var ndx;
for (ndx in directories) {
if (directories[ndx] !== undefined) {
dir = directories[ndx];
fs.readdirSync(dir).filter(isTest)
.forEach(addTest);
}
}
mocha.run(function(failures) {
process.on('exit', function() {
process.exit(failures);
});
});