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
107 lines (87 loc) · 3.38 KB
/
Copy pathindex.js
File metadata and controls
107 lines (87 loc) · 3.38 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
'use strict';
const _ = require('lodash');
const q = require('q');
const Runner = require('./runner');
const TestSessionRunner = require('./test-session-runner');
const FailCollector = require('../fail-collector');
const Coverage = require('../coverage');
const RunnerEvents = require('../constants/runner-events');
const PrivateEvents = require('./private-events');
module.exports = class TestsRunner extends Runner {
constructor(config, stateProcessor) {
super();
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(browsers) {
this._testBrowsers = browsers;
}
/**
* @param {SuiteCollection} SuiteCollection
* @returns {*}
*/
run(suiteCollection) {
const suites = suiteCollection.allSuites();
return q.fcall(() => {
this.emit(RunnerEvents.BEGIN, {
config: this.config,
totalStates: _.reduce(suites, (result, suite) => {
return result + suite.states.length;
}, 0),
browserIds: this.config.getBrowserIds()
});
})
.then(() => this._prepare())
.then(() => this._runTestSession(suiteCollection))
.then(() => this.coverage && this.coverage.processStats())
.fin(() => this.emit(RunnerEvents.END));
}
_runTestSession(suiteCollection) {
const 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, (error) => this._handleError(error));
sessionRunner.on(PrivateEvents.CRITICAL_ERROR, (error) => this._handleCriticalError(error));
sessionRunner.on(PrivateEvents.STATE_RESULT, (result) => this._handleStateResult(result));
const suites = suiteCollection.allSuites();
return sessionRunner.run(suites, this._stateProcessor)
.then(() => this._failCollector.retry((tests) => this._runTestSession(tests), suiteCollection));
}
_prepare() {
return this._stateProcessor.prepare(this);
}
_handleStateResult(result) {
if (this.coverage) {
this.coverage.addStatsForBrowser(result.coverage, result.browserId);
}
if (!this._failCollector.tryToSubmitStateResult(result)) {
this.emit(this._stateProcessor.jobDoneEvent, result);
}
}
_handleError(error) {
if (!this._failCollector.tryToSubmitError(error)) {
this.emit(RunnerEvents.ERROR, error);
}
}
_handleCriticalError(critical) {
if (!this._failCollector.tryToSubmitError(critical)) {
this.emit(RunnerEvents.ERROR, critical);
return q.reject(critical);
}
return q();
}
};