-
Notifications
You must be signed in to change notification settings - Fork 0
/
autotest.js
74 lines (65 loc) · 2.49 KB
/
autotest.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
72
73
74
/**
* Autotester to execute the tests when a file is modified and notify the results to Growl
**/
var watch = require('nodewatch');
var growl = require('growl');
var Path= require('path');
var jasmine = require('jasmine-node');
var sys = require('sys');
growl.binVersion(function(err, version){
if (err) {
sys.puts('You have to install growlnotifier to be able to use autotest');
process.exit(1);
}
watch.add('./spec').add('./spec/spies').add('./lib').onChange(function(file,prev,curr){
sys.puts('File ' + file + ' modified... Executing tests...');
var specFolder = Path.join(process.cwd(), 'spec');
var libFolder = Path.join(process.cwd(), 'lib');
var indexFile = Path.join(process.cwd(), 'index.js');
// Configure jasmine-node
jasmine.dev_mode = 'src';
for (var key in jasmine) {
global[key] = jasmine[key];
}
jasmine.loadHelpersInFolder(specFolder, new RegExp("[-_]helper\\.(js)$"));
jasmine.executeSpecsInFolder(
specFolder,
function(runner, log){
if (runner.results().failedCount == 0) {
growl.notify(
'All tests passed! (' + runner.results().passedCount + '/' + runner.results().totalCount + ')',
{title: 'connFu-dsl Unit Tests', image: 'resources/tests-pass.png'}
);
} else {
// Get the desc of the first failing test
var description = '1';
runner.results().items_.forEach(function(value){
if (value.failedCount !== 0) {
value.items_.forEach(function(val){
if (val.failedCount !== 0) {
description = val.description;
}
});
}
});
growl.notify(
runner.results().failedCount + ' tests failed! (' + runner.results().passedCount + '/' + runner.results().totalCount + ')',
{title: description, image: 'resources/tests-fail.png'}
);
}
// Restart jasmine environment after executing the test suite
var jasmineEnv = jasmine.getEnv();
jasmineEnv.currentRunner_ = new jasmine.Runner(jasmineEnv);
// Remove loaded files from cache
for (var required in require.cache) {
if (required.indexOf(specFolder) === 0 || required.indexOf(libFolder) === 0 || required.indexOf(indexFile) === 0) {
delete require.cache[required];
}
}
},
true, // Verbose mode
true , // Show colors
new RegExp(".spec\\.(js)$", 'i')
);
});
});