This repository has been archived by the owner on Sep 21, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 149
/
Copy pathsuite-monitor.js
63 lines (50 loc) · 1.72 KB
/
suite-monitor.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
'use strict';
var EventEmitter = require('events').EventEmitter,
_ = require('lodash'),
inherit = require('inherit'),
Events = require('./constants/events');
const SuiteMonitor = module.exports = inherit(EventEmitter, {
__constructor: function() {
this.awaiting = {};
this.complete = new WeakMap();
},
suiteFinished: function(suite, browser) {
if (suite.children.length === 0) {
this._markAsCompleted(suite, browser);
this.emit(Events.END_SUITE, {suite: suite, browserId: browser});
} else {
if (!this.awaiting[browser]) {
this.awaiting[browser] = [];
}
this.awaiting[browser].push(suite);
}
this._processAwaitingSuites(browser);
},
_processAwaitingSuites: function(browser) {
var suites = this.awaiting[browser],
complete = [];
if (!suites) {
return;
}
_.forEachRight(suites, function(suite, i) {
if (_.every(suite.children, this._isCompletedInBrowser.bind(this, browser))) {
this._markAsCompleted(suite, browser);
this.emit(Events.END_SUITE, {suite: suite, browserId: browser});
complete.push(i);
}
}.bind(this));
_.pullAt(suites, complete);
},
_markAsCompleted: function(suite, browser) {
var browsers = this.complete.get(suite) || {};
browsers[browser] = true;
this.complete.set(suite, browsers);
},
_isCompletedInBrowser: function(browser, suite) {
return this.complete.has(suite) && this.complete.get(suite)[browser];
}
}, {
create: function() {
return new SuiteMonitor();
}
});