-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathwatchr.js
67 lines (45 loc) · 1.34 KB
/
watchr.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
var Projstrap = require('projstrap'),
exec = require('child_process').exec,
//Command to run tests (change this to whatever you use)
specHelper = __dirname + '/test/helper.js',
cmd = './node_modules/mocha/bin/mocha --growl -c --reporter Spec ' + specHelper + ' ',
watchr,
suite;
suite = new Projstrap.Suite({
//Path to the root of the project
path: __dirname,
//path to your javascript
libPath: 'lib/',
//path to your spec(s) or tests
specPath: 'test/',
//what your files are named (usually .js)
libSuffix: '.js',
//suffix for tests (usually -spec.js or Spec.js)
specSuffix: '-test.js'
});
//Create new Watchr instance
//Assumes this file is in the root of your project
watchr = new Projstrap.Watchr(__dirname, {
//Poll very frequently
rate: 5
});
//change is fired when file is created, modified or deleted
watchr.on('change', function(event) {
var spec = suite.specFromPath(event.path);
//Skip deletion events
if (event.type == 'deleted') {
return;
}
//Skip changes on files we don't care about
if (!spec.isSpec && !spec.isLib) {
return;
}
console.log('Executing:', cmd + spec.specPath);
exec(cmd + spec.specPath.replace('spec', 'test'), function(err, stdout, stderr) {
if (stderr) {
console.error(stderr);
}
console.log(stdout);
});
});
watchr.start();