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
135 lines (112 loc) Β· 4.22 KB
/
Copy pathindex.js
File metadata and controls
135 lines (112 loc) Β· 4.22 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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
'use strict';
var _ = require('lodash'),
q = require('q'),
inherit = require('inherit'),
Runner = require('./runner'),
TestSessionRunner = require('./test-session-runner'),
Tester = require('../capture-processor/tester'),
ScreenShooter = require('../capture-processor/screen-shooter'),
ScreenUpdater = require('../capture-processor/screen-updater'),
FailCollector = require('../fail-collector'),
Coverage = require('../coverage'),
RunnerEvents = require('../constants/runner-events'),
PrivateEvents = require('./private-events');
var TestsRunner = inherit(Runner, {
__constructor: function(config, captureProcessor) {
this.config = config;
this._captureProcessor = captureProcessor;
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, this._handleCriticalError.bind(this));
sessionRunner.on(PrivateEvents.CAPTURE_DATA, this._handleCapture.bind(this));
var _this = this;
return sessionRunner.run(suites).then(function() {
return _this._failCollector.retry(_this._runTestSession.bind(_this));
});
},
_prepare: function() {
return this._captureProcessor.prepare(this);
},
_handleCapture: function(capture) {
if (this.coverage) {
this.coverage.addStatsForBrowser(capture.coverage, capture.browser);
}
var _this = this;
return this._captureProcessor.processCapture(capture).then(function(processed) {
if (!_this._failCollector.tryToSubmitCapture(processed)) {
_this.emit(_this._captureProcessor.getProcessedCaptureEventName(), processed);
}
});
},
_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();
}
}, {
createTester: function(config, options) {
return new TestsRunner(config, new Tester(config, options));
},
createScreenShooter: function(config) {
return new TestsRunner(config, new ScreenShooter(config));
},
createScreenUpdater: function(config, options) {
return new TestsRunner(config, ScreenUpdater.create(config, options));
}
});
module.exports = TestsRunner;