This repository was archived by the owner on Sep 21, 2022. It is now read-only.
Repository navigation
Expand file tree
/
Copy pathindex.js
More file actions
116 lines (97 loc) Β· 3.54 KB
/
Copy pathindex.js
File metadata and controls
116 lines (97 loc) Β· 3.54 KB
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
'use strict';
var _ = require('lodash'),
q = require('q'),
inherit = require('inherit'),
Runner = require('./runner'),
TestSessionRunner = require('./test-session-runner'),
FailCollector = require('../fail-collector'),
Coverage = require('../coverage'),
RunnerEvents = require('../constants/runner-events'),
PrivateEvents = require('./private-events');
var TestsRunner = inherit(Runner, {
__constructor: function(config, stateProcessor) {
this.config = config;
this._stateProcessor = stateProcessor;
this._failCollector = new FailCollector(config);
this.coverage = this.config.isCoverageEnabled() && new Coverage(config);
this.passthroughEvent(this._failCollector, RunnerEvents.RETRY);
},
setTestBrowsers: function(browsers) {
this._testBrowsers = browsers;
},
/**
* @param {Suite[]} suites
* @returns {*}
*/
run: function(suites) {
var _this = this;
return q.fcall(function() {
_this.emit(RunnerEvents.BEGIN, {
config: _this.config,
totalStates: _.reduce(suites, function(result, suite) {
return result + suite.states.length;
}, 0),
browserIds: _this.config.getBrowserIds()
});
}).then(function() {
return _this._prepare();
})
.then(function() {
return _this._runTestSession(suites);
})
.then(function() {
return _this.coverage && _this.coverage.processStats();
})
.fin(function() {
_this.emit(RunnerEvents.END);
});
},
_runTestSession: function(suites) {
var sessionRunner = TestSessionRunner.create(this.config, this._testBrowsers);
this.passthroughEvent(sessionRunner, [
RunnerEvents.BEGIN_SESSION,
RunnerEvents.END_SESSION,
RunnerEvents.START_BROWSER,
RunnerEvents.STOP_BROWSER,
RunnerEvents.INFO,
RunnerEvents.BEGIN_SUITE,
RunnerEvents.END_SUITE,
RunnerEvents.SKIP_STATE,
RunnerEvents.BEGIN_STATE,
RunnerEvents.END_STATE,
RunnerEvents.WARNING
]);
sessionRunner.on(RunnerEvents.ERROR, this._handleError.bind(this));
sessionRunner.on(PrivateEvents.CRITICAL_ERROR
543E
, this._handleCriticalError.bind(this));
sessionRunner.on(PrivateEvents.STATE_RESULT, this._handleStateResult.bind(this));
var _this = this;
return sessionRunner.run(suites, this._stateProcessor)
.then(function() {
return _this._failCollector.retry(_this._runTestSession.bind(_this));
});
},
_prepare: function() {
return this._stateProcessor.prepare(this);
},
_handleStateResult: function(result) {
if (this.coverage) {
this.coverage.addStatsForBrowser(result.coverage, result.browserId);
}
if (!this._failCollector.tryToSubmitStateResult(result)) {
this.emit(this._stateProcessor.jobDoneEvent, result);
}
},
_handleError: function(error) {
if (!this._failCollector.tryToSubmitError(error)) {
this.emit(RunnerEvents.ERROR, error);
}
},
_handleCriticalError: function(critical) {
if (!this._failCollector.tryToSubmitError(critical)) {
this.emit(RunnerEvents.ERROR, critical);
return q.reject(critical);
}
return q.resolve();
}
});
module.exports = TestsRunner;