forked from rase-/node-XMLHttpRequest
-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathrun-test.js
50 lines (40 loc) · 1.25 KB
/
run-test.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
var ignored_files = [
"run-test.js", // this file
"server.js"
];
var spawnSync = require("child_process").spawnSync;
var fs = require("fs");
var path = require("path");
// global flag to check if some of test fails, and will store location of failed test file
var fail_path = false;
// function to read and conduct test case
var run_test = function (file) {
if (fail_path) return;
// logging
console.log("Running:", file);
// spawn a nodejs process
var proc = spawnSync("node", [file]);
if (proc.status === 0) {
console.log(proc.stdout.toString());
console.log("--> PASSED");
}
else {
fail_path = file;
console.log("--> TEST FAILED - CAUGHT ERROR:", proc.stderr.toString());
}
}
var check_dir = function (dirPath) {
if (fail_path) return;
var files = fs.readdirSync(dirPath);
for (var file of files) {
// return early in case something fails
if (fail_path) return;
var full_path = path.join(dirPath, file);
if (fs.statSync(full_path).isDirectory()) check_dir(full_path);
else if (path.extname(file) === ".js" && !ignored_files.includes(full_path)) run_test(full_path);
}
}
// start test
check_dir("./");
if (fail_path) throw new Error("Test failed at file: " + fail_path);
console.log("ALL TESTS PASSED.");