forked from karma-runner/karma
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: split up the client code, use commonjs
Closes karma-runner#253
- Loading branch information
Showing
14 changed files
with
231 additions
and
223 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module.exports = { | ||
VERSION: '%KARMA_VERSION%', | ||
KARMA_URL_ROOT: '%KARMA_URL_ROOT%', | ||
CONTEXT_URL: 'context.html' | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
var Karma = require('./karma'); | ||
var StatusUpdater = require('./updater'); | ||
var util = require('./util'); | ||
|
||
var KARMA_URL_ROOT = require('./constants').KARMA_URL_ROOT; | ||
|
||
|
||
// connect socket.io | ||
// https://github.com/LearnBoost/Socket.IO/wiki/Configuring-Socket.IO | ||
var socket = io.connect('http://' + location.host, { | ||
'reconnection delay': 500, | ||
'reconnection limit': 2000, | ||
'resource': KARMA_URL_ROOT.substr(1) + 'socket.io', | ||
'sync disconnect on unload': true, | ||
'max reconnection attempts': Infinity | ||
}); | ||
|
||
// 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.navigator, window.location); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
var instanceOf = require('./util').instanceOf; | ||
|
||
var stringify = function stringify(obj, depth) { | ||
|
||
if (depth === 0) { | ||
return '...'; | ||
} | ||
|
||
if (obj === null) { | ||
return 'null'; | ||
} | ||
|
||
switch (typeof obj) { | ||
case 'string': | ||
return '\'' + obj + '\''; | ||
case 'undefined': | ||
return 'undefined'; | ||
case 'function': | ||
return obj.toString().replace(/\{[\s\S]*\}/, '{ ... }'); | ||
case 'boolean': | ||
return obj ? 'true' : 'false'; | ||
case 'object': | ||
var strs = []; | ||
if (instanceOf(obj, 'Array')) { | ||
strs.push('['); | ||
for (var i = 0, ii = obj.length; i < ii; i++) { | ||
if (i) { | ||
strs.push(', '); | ||
} | ||
strs.push(stringify(obj[i], depth - 1)); | ||
} | ||
strs.push(']'); | ||
} else if (instanceOf(obj, 'Date')) { | ||
return obj.toString(); | ||
} else if (instanceOf(obj, 'Text')) { | ||
return obj.nodeValue; | ||
} else if (instanceOf(obj, 'Comment')) { | ||
return '<!--' + obj.nodeValue + '-->'; | ||
} else if (obj.outerHTML) { | ||
return obj.outerHTML; | ||
} else { | ||
strs.push(obj.constructor.name); | ||
strs.push('{'); | ||
var first = true; | ||
for(var key in obj) { | ||
if (obj.hasOwnProperty(key)) { | ||
if (first) { first = false; } else { strs.push(', '); } | ||
strs.push(key + ': ' + stringify(obj[key], depth - 1)); | ||
} | ||
} | ||
strs.push('}'); | ||
} | ||
return strs.join(''); | ||
default: | ||
return obj; | ||
} | ||
}; | ||
|
||
|
||
module.exports = stringify; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
var VERSION = require('./constants').VERSION; | ||
|
||
|
||
var StatusUpdater = function(socket, titleElement, bannerElement, browsersElement) { | ||
var updateBrowsersInfo = function(browsers) { | ||
var items = [], status; | ||
for (var i = 0; i < browsers.length; i++) { | ||
status = browsers[i].isReady ? 'idle' : 'executing'; | ||
items.push('<li class="' + status + '">' + browsers[i].name + ' is ' + status + '</li>'); | ||
} | ||
browsersElement.innerHTML = items.join('\n'); | ||
}; | ||
|
||
var updateBanner = function(status) { | ||
return function(param) { | ||
var paramStatus = param ? status.replace('$', param) : status; | ||
titleElement.innerHTML = 'Karma v' + VERSION + ' - ' + paramStatus; | ||
bannerElement.className = status === 'connected' ? 'online' : 'offline'; | ||
}; | ||
}; | ||
|
||
socket.on('connect', updateBanner('connected')); | ||
socket.on('disconnect', updateBanner('disconnected')); | ||
socket.on('reconnecting', updateBanner('reconnecting in $ ms...')); | ||
socket.on('reconnect', updateBanner('connected')); | ||
socket.on('reconnect_failed', updateBanner('failed to reconnect')); | ||
socket.on('info', updateBrowsersInfo); | ||
socket.on('disconnect', function() { | ||
updateBrowsersInfo([]); | ||
}); | ||
}; | ||
|
||
module.exports = StatusUpdater; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
exports.instanceOf = function(value, constructorName) { | ||
return Object.prototype.toString.apply(value) === '[object ' + constructorName + ']'; | ||
}; | ||
|
||
exports.elm = function(id) { | ||
return document.getElementById(id); | ||
}; | ||
|
||
exports.generateId = function(prefix) { | ||
return prefix + Math.floor(Math.random() * 10000); | ||
}; | ||
|
||
exports.isUndefined = function(value) { | ||
return typeof value === 'undefined'; | ||
}; | ||
|
||
exports.isDefined = function(value) { | ||
return !exports.isUndefined(value); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.