-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkeep-testing.js
executable file
·71 lines (58 loc) · 2.42 KB
/
keep-testing.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
var fs = require("fs");
var color = require("colors");
var Notification = require('node-notifier');
var test = process.argv[2];
if(!test){
console.log("[SCRIPT USAGE]".yellow);
console.log("nodejs keep-testing.js ./util/DomainUtilTest".yellow);
console.log("[Test must be runned without ./test folder]".yellow);
process.exit(0);
}
if(test.match(/test\/.*/)){
test = test.replace(/test\//, './');
}
function header(){
console.log(' ______ __ __ ___ _ __ ______ ______ ____ ______ ______ ______ ______ ______ ______ ____ '.yellow);
console.log(' / ____/ / / / / / | / | / / / ____/ / ____/ / __ \\ / ____/ /_ __/ / ____/ / ____/ /_ __/ / ____/ / __ \\ '.yellow);
console.log(' / / / /_/ / / /| | / |/ / / / __ / __/ / / / / / __/ / / / __/ / / / / / __/ / / / /'.yellow);
console.log('/ /___ / __ / / ___ | / /| / / /_/ / / /___ / /_/ / / /___ / / / /___ / /___ / / / /___ / /_/ / '.yellow);
console.log('\\____/ /_/ /_/ /_/ |_|/_/ |_/ \\____/ /_____/ /_____/ /_____/ /_/ /_____/ \\____/ /_/ /_____/ /_____/ '.yellow);
console.log('');
}
function listener(path){
return function(curr, prev){
header();
console.log('CHANGED FILE:', path.yellow);
var exec = require('child_process').exec;
exec('node ./test/test-runner.js ' + test, function (error, stdout, stderr) {
console.log(stdout);
console.log(stderr);
new Notification().notify({ title: error ? "FAILLLL" : "PASSED" , message: error? "=(" : "=D"});
});
}
}
function addWatcherFile(path){
fs.stat(path, function(er, stats){
if(er){
throw er;
}
if(stats.isDirectory()){
addWatcherDirectory(path);
return;
}
fs.watchFile(path, listener(path));
});
}
function addWatcherDirectory(name){
function readFiles(err, files){
for(var i=0; i < files.length; i++){
var path = name + "/" + files[i];
addWatcherFile(path, files);
}
}
fs.readdir(name, readFiles);
}
addWatcherDirectory("./test");
addWatcherDirectory("./server");
addWatcherFile("./keep-testing.js");
listener(test)();