source: trip-planner-front/node_modules/karma/lib/browser_collection.js@ 6a3a178

Last change on this file since 6a3a178 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 2.6 KB
Line 
1'use strict'
2
3const BrowserResult = require('./browser_result')
4const helper = require('./helper')
5
6class BrowserCollection {
7 constructor (emitter, browsers = []) {
8 this.browsers = browsers
9 this.emitter = emitter
10 }
11
12 add (browser) {
13 this.browsers.push(browser)
14 this.emitter.emit('browsers_change', this)
15 }
16
17 remove (browser) {
18 if (helper.arrayRemove(this.browsers, browser)) {
19 this.emitter.emit('browsers_change', this)
20 return true
21 }
22 return false
23 }
24
25 getById (browserId) {
26 return this.browsers.find((browser) => browser.id === browserId) || null
27 }
28
29 getNonReady () {
30 return this.browsers.filter((browser) => !browser.isConnected())
31 }
32
33 areAllReady () {
34 return this.browsers.every((browser) => browser.isConnected())
35 }
36
37 serialize () {
38 return this.browsers.map((browser) => browser.serialize())
39 }
40
41 calculateExitCode (results, singleRunBrowserNotCaptured, config) {
42 config = config || {}
43 if (results.disconnected || singleRunBrowserNotCaptured) {
44 return 1
45 }
46 if (results.skipped && config.failOnSkippedTests) {
47 return 1
48 }
49 if (results.success + results.failed === 0 && !!config.failOnEmptyTestSuite) {
50 return 1
51 }
52 if (results.error) {
53 return 1
54 }
55 if (config.failOnFailingTestSuite === false) {
56 return 0 // Tests executed without infrastructure error, exit with 0 independent of test status.
57 }
58 return results.failed ? 1 : 0
59 }
60
61 getResults (singleRunBrowserNotCaptured, config) {
62 const results = { success: 0, failed: 0, skipped: 0, error: false, disconnected: false, exitCode: 0 }
63 this.browsers.forEach((browser) => {
64 results.success += browser.lastResult.success
65 results.failed += browser.lastResult.failed
66 results.skipped += browser.lastResult.skipped
67 results.error = results.error || browser.lastResult.error
68 results.disconnected = results.disconnected || browser.lastResult.disconnected
69 })
70
71 results.exitCode = this.calculateExitCode(results, singleRunBrowserNotCaptured, config)
72 return results
73 }
74
75 clearResults () {
76 this.browsers.forEach((browser) => {
77 browser.lastResult = new BrowserResult()
78 })
79 }
80
81 clone () {
82 return new BrowserCollection(this.emitter, this.browsers.slice())
83 }
84
85 // Array APIs
86 map (callback, context) {
87 return this.browsers.map(callback, context)
88 }
89
90 forEach (callback, context) {
91 return this.browsers.forEach(callback, context)
92 }
93
94 get length () {
95 return this.browsers.length
96 }
97}
98
99BrowserCollection.factory = function (emitter) {
100 return new BrowserCollection(emitter)
101}
102
103module.exports = BrowserCollection
Note: See TracBrowser for help on using the repository browser.