forked from karma-runner/karma-browserstack-launcher
-
Notifications
You must be signed in to change notification settings - Fork 0
/
browserstack-reporter.js
53 lines (43 loc) · 1.44 KB
/
browserstack-reporter.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
var Browserstack = require('browserstack')
var BrowserStackReporter = function (logger, /* BrowserStack:sessionMapping */ sessionMapping) {
var log = logger.create('reporter.browserlabs')
var pendingUpdates = 0
var callWhenFinished = function () {}
var exitIfAllFinished = function () {
if (pendingUpdates === 0) {
callWhenFinished()
}
}
// We're only interested in the final results per browser
this.onBrowserComplete = function (browser) {
var result = browser.lastResult
if (result.disconnected) {
log.error('✖ Test Disconnected')
}
if (result.error) {
log.error('✖ Test Errored')
}
var browserId = browser.launchId || browser.id
if (browserId in sessionMapping) {
pendingUpdates++
var browserstackClient = Browserstack.createAutomateClient(sessionMapping.credentials)
var apiStatus = !(result.failed || result.error || result.disconnected) ? 'completed' : 'error'
browserstackClient.updateSession(sessionMapping[browserId], {
status: apiStatus
}, function (error) {
if (error) {
log.error('✖ Could not update BrowserStack status')
log.debug(error)
}
pendingUpdates--
exitIfAllFinished()
})
}
}
// Wait until all updates have been pushed to Browserstack
this.onExit = function (done) {
callWhenFinished = done
exitIfAllFinished()
}
}
module.exports = BrowserStackReporter