This repository was archived by the owner on Sep 21, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.js
More file actions
57 lines (48 loc) · 1.33 KB
/
test.js
File metadata and controls
57 lines (48 loc) · 1.33 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
/**
* The idea is, that every test file is just executed and might throw errors at will.
*/
var fs = require('fs');
console.log('Starting test suite');
var testFiles = getAllTestFiles('tests/');
console.log('Testing with those files:')
console.log(testFiles);
var passed = 0; // lol counters.. callbacks don't work that way
var errors = 0;
console.log();
// call all test functions
for(var i = 0; i < testFiles.length; i++) {
fs.readFile(__dirname + '/' + testFiles[i], function (err, data) {
if (err) throw err;
var tests = []
eval(data.toString());
for(var j = 0; j < tests.length; j++) {
try {
tests[j]();
passed++;
} catch(e) {
console.log("[FAILED] " + e);
errors++;
}
}
});
}
/**
* This function is intended to collect files that contain test functions.
* It should point to the topmost directory containing test files.
*
* Adjust this method if you want e.g. just files with a suffix like 'Test.js'
*/
function getAllTestFiles(parent) {
var entries = fs.readdirSync(parent);
var files = [];
for(var i = 0; i < entries.length; i++) {
var entry = fs.statSync(parent + entries[i])
if(entry.isFile()) {
files.push(parent + entries[i]);
}
if(entry.isDirectory()) {
files = files.concat(getAllTestFiles(parent + entries[i] + '/'));
}
}
return files;
}