forked from webpack-contrib/mocha-loader
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathEnhancedMocha.js
59 lines (51 loc) · 1.18 KB
/
EnhancedMocha.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
var Mocha = require("mocha");
function EnhancedMocha(options) {
Mocha.call(this, options);
}
module.exports = EnhancedMocha;
EnhancedMocha.prototype = Object.create(Mocha.prototype);
EnhancedMocha.prototype.loadFiles = function(fn) {
var self = this;
var suite = this.suite;
suite.suites.length = 0;
suite.tests.length = 0;
try {
var file = this.files[0];
if(module.hot) {
module.hot.accept(file, function() {
if(self.watching) {
if(!self.running)
self.run();
else
self.outdated = true;
}
});
}
suite.emit('pre-require', global, file, self);
suite.emit('require', require(file), file, self);
suite.emit('post-require', global, file, self);
} catch(e) {
suite.addTest(new Mocha.Test("fix test errors", function() {
throw e;
}));
}
if(fn) fn();
}
EnhancedMocha.prototype.watch = function() {
var self = this;
self.outdated = false;
self.running = true;
self.watching = true;
// reinit ui to fix ui bugs
this.ui(this.options.ui);
// run the tests
this.run(function(failures) {
self.running = false;
if(self.outdated)
self.watch();
});
if(module.hot) {
// Don't exit the process
setInterval(function() {}, 100000);
}
};