Skip to content

Commit

Permalink
Merge 7e47e84 into 3fca456
Browse files Browse the repository at this point in the history
  • Loading branch information
johnjbarton authored Jan 11, 2021
2 parents 3fca456 + 7e47e84 commit fa55723
Show file tree
Hide file tree
Showing 8 changed files with 2,599 additions and 85 deletions.
10 changes: 9 additions & 1 deletion client/karma.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ var stringify = require('../common/stringify')
var constant = require('./constants')
var util = require('../common/util')

function Karma (socket, iframe, opener, navigator, location, document) {
function Karma (updater, socket, iframe, opener, navigator, location, document) {
this.updater = updater
var startEmitted = false
var karmaNavigating = false
var self = this
Expand Down Expand Up @@ -190,6 +191,7 @@ function Karma (socket, iframe, opener, navigator, location, document) {
}

socket.emit('karma_error', message)
self.updater.updateTestStatus(`karam_error ${message}`)
this.complete()
return false
}
Expand All @@ -212,17 +214,20 @@ function Karma (socket, iframe, opener, navigator, location, document) {

if (!startEmitted) {
socket.emit('start', { total: null })
self.updater.updateTestStatus('start')
startEmitted = true
}

if (resultsBufferLimit === 1) {
self.updater.updateTestStatus('result')
return socket.emit('result', convertedResult)
}

resultsBuffer.push(convertedResult)

if (resultsBuffer.length === resultsBufferLimit) {
socket.emit('result', resultsBuffer)
self.updater.updateTestStatus('result')
resultsBuffer = []
}
}
Expand All @@ -232,6 +237,7 @@ function Karma (socket, iframe, opener, navigator, location, document) {
socket.emit('result', resultsBuffer)
resultsBuffer = []
}

// A test could have incorrectly issued a navigate. Wait one turn
// to ensure the error from an incorrect navigate is processed.
setTimeout(() => {
Expand All @@ -240,6 +246,7 @@ function Karma (socket, iframe, opener, navigator, location, document) {
}

socket.emit('complete', result || {})
self.updater.updateTestStatus('complete')

if (returnUrl) {
location.href = returnUrl
Expand All @@ -258,6 +265,7 @@ function Karma (socket, iframe, opener, navigator, location, document) {
}

socket.on('execute', function (cfg) {
self.updater.updateTestStatus('execute')
// reset startEmitted and reload the iframe
startEmitted = false
self.config = cfg
Expand Down
4 changes: 2 additions & 2 deletions client/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ var socket = io(location.host, {
})

// instantiate the updater of the view
new StatusUpdater(socket, util.elm('title'), util.elm('banner'), util.elm('browsers'))
window.karma = new Karma(socket, util.elm('context'), window.open,
var updater = new StatusUpdater(socket, util.elm('title'), util.elm('banner'), util.elm('browsers'))
window.karma = new Karma(updater, socket, util.elm('context'), window.open,
window.navigator, window.location, window.document)
62 changes: 48 additions & 14 deletions client/updater.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,26 +21,60 @@ function StatusUpdater (socket, titleElement, bannerElement, browsersElement) {
}
}

function updateBanner (status) {
return function (param) {
if (!titleElement || !bannerElement) {
return
}
var paramStatus = param ? status.replace('$', param) : status
titleElement.textContent = 'Karma v' + VERSION + ' - ' + paramStatus
bannerElement.className = status === 'connected' ? 'online' : 'offline'
var connectionText = 'never-connected'
var testText = 'loading'
var pingText = ''

function updateBanner () {
if (!titleElement || !bannerElement) {
return
}
titleElement.textContent = `Karma v ${VERSION} - ${connectionText}; test: ${testText}; ${pingText}`
bannerElement.className = connectionText === 'connected' ? 'online' : 'offline'
}

function updateConnectionStatus (connectionStatus) {
connectionText = connectionStatus || connectionText
updateBanner()
}
function updateTestStatus (testStatus) {
testText = testStatus || testText
updateBanner()
}
function updatePingStatus (pingStatus) {
pingText = pingStatus || pingText
updateBanner()
}

socket.on('connect', () => {
updateConnectionStatus('connected')
})
socket.on('disconnect', () => {
updateConnectionStatus('disconnected')
})
socket.on('reconnecting', (sec) => {
updateConnectionStatus(`reconnecting in ${sec} seconds`)
})
socket.on('reconnect', () => {
updateConnectionStatus('reconnected')
})
socket.on('reconnect_failed', () => {
updateConnectionStatus('reconnect_failed')
})

socket.on('connect', updateBanner('connected'))
socket.on('disconnect', updateBanner('disconnected'))
socket.on('reconnecting', updateBanner('reconnecting in $ seconds...'))
socket.on('reconnect', updateBanner('connected'))
socket.on('reconnect_failed', updateBanner('failed to reconnect'))
socket.on('info', updateBrowsersInfo)
socket.on('disconnect', function () {
socket.on('disconnect', () => {
updateBrowsersInfo([])
})

socket.on('ping', () => {
updatePingStatus('ping...')
})
socket.on('pong', (latency) => {
updatePingStatus(`ping ${latency}ms`)
})

return { updateTestStatus: updateTestStatus }
}

module.exports = StatusUpdater
Loading

0 comments on commit fa55723

Please sign in to comment.