forked from karma-runner/karma
-
Notifications
You must be signed in to change notification settings - Fork 0
/
browser_collection.js
110 lines (87 loc) · 2.78 KB
/
browser_collection.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
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
'use strict'
const Result = require('./browser_result')
class BrowserCollection {
constructor (emitter, browsers) {
this.browsers = browsers || []
this.emitter = emitter
}
add (browser) {
this.browsers.push(browser)
this.emitter.emit('browsers_change', this)
}
remove (browser) {
const index = this.browsers.indexOf(browser)
if (index === -1) {
return false
}
this.browsers.splice(index, 1)
this.emitter.emit('browsers_change', this)
return true
}
getById (browserId) {
return this.browsers.find((browser) => browser.id === browserId) || null
}
areAllReady (nonReadyList) {
nonReadyList = nonReadyList || []
this.browsers.forEach((browser) => {
if (!browser.isConnected()) {
nonReadyList.push(browser)
}
})
return nonReadyList.length === 0
}
serialize () {
return this.browsers.map((browser) => browser.serialize())
}
calculateExitCode (results, singleRunBrowserNotCaptured, failOnEmptyTestSuite, failOnFailingTestSuite) {
if (results.disconnected || singleRunBrowserNotCaptured) {
return 1
}
if (results.success + results.failed === 0 && !failOnEmptyTestSuite) {
return 0
}
if (results.error) {
return 1
}
if (failOnFailingTestSuite === false) {
// Tests executed without infrastructure error, exit with 0 independent of test status.
return 0
}
return results.failed ? 1 : 0
}
getResults (singleRunBrowserNotCaptured, failOnEmptyTestSuite, failOnFailingTestSuite) {
const results = this.browsers.reduce((previous, current) => {
previous.success += current.lastResult.success
previous.failed += current.lastResult.failed
previous.error = previous.error || current.lastResult.error
previous.disconnected = previous.disconnected || current.lastResult.disconnected
return previous
}, {success: 0, failed: 0, error: false, disconnected: false, exitCode: 0})
// compute exit status code
results.exitCode = this.calculateExitCode(results, singleRunBrowserNotCaptured, failOnEmptyTestSuite, failOnFailingTestSuite)
return results
}
// TODO(vojta): can we remove this? (we clear the results per browser in onBrowserStart)
clearResults () {
this.browsers.forEach((browser) => {
browser.lastResult = new Result()
})
}
clone () {
return new BrowserCollection(this.emitter, this.browsers.slice())
}
// Array APIs
map (callback, context) {
return this.browsers.map(callback, context)
}
forEach (callback, context) {
return this.browsers.forEach(callback, context)
}
get length () {
return this.browsers.length
}
}
BrowserCollection.factory = function (emitter) {
return new BrowserCollection(emitter)
}
module.exports = BrowserCollection