Permalink
Browse files

Adding display of current test result tally to the browser's `documen…

…t.title` #145.
  • Loading branch information...
1 parent 7672dc4 commit d03f13290521b4f4d1383df02ab2e95f883b7f26 @airportyh airportyh committed Jan 5, 2013
@@ -10,10 +10,6 @@ Testem's adapter for Buster.js. It works by attaching event listeners to the tes
function busterAdapter(socket){
- function emit(){
- socket.emit.apply(socket, arguments)
- }
-
var id = 1
var started = false
@@ -16,10 +16,6 @@ function jasmineAdapter(socket){
, tests: []
}
- function emit(){
- socket.emit.apply(socket, arguments)
- }
-
function JasmineAdapterReporter(){}
JasmineAdapterReporter.prototype.reportRunnerStarting = function(runner){
emit('tests-start')
@@ -24,10 +24,6 @@ function mochaAdapter(socket){
console.error('Testem: failed to register adapter for mocha.')
}
- function emit(){
- socket.emit.apply(socket, arguments)
- }
-
function getFullName(test){
var name = ''
while (test){
@@ -24,10 +24,6 @@ function qunitAdapter(socket){
, currentTest
, currentModule
, id = 1
-
- function emit(){
- socket.emit.apply(socket, arguments)
- }
function lineNumber(e){
return e.line || e.lineNumber
@@ -191,6 +191,22 @@ function init(){
socket.on('start-tests', startTests)
initTestFrameworkHooks()
addListener(window, 'load', initUI)
+ setupTestStats()
+}
+
+function setupTestStats(){
+ var originalTitle = document.title
+ var total = 0
+ var passed = 0
+ Testem.on('test-result', function(test){
+ total++
+ if (test.failed === 0) passed++
+ updateTitle()
+ })
+
+ function updateTitle(){
+ document.title = originalTitle + ' (' + passed + '/' + total + ')'
+ }
}
function takeOverConsole(){
@@ -223,10 +239,35 @@ function interceptWindowOnError(){
}
}
-init()
+function emit(){
+ Testem.emit.apply(Testem, arguments)
+}
window.Testem = {
useCustomAdapter: function(adapter){
adapter(socket)
}
+ , emit: function(evt){
+ socket.emit.apply(socket, arguments)
+ if (this.evtHandlers && this.evtHandlers[evt]){
+ var handlers = this.evtHandlers[evt]
+ var args = Array.prototype.slice.call(arguments, 1)
+ for (var i = 0; i < handlers.length; i++){
+ var handler = handlers[i]
+ handler.apply(this, args)
+ }
+ }
+ }
+ , on: function(evt, callback){
+ if (!this.evtHandlers){
+ this.evtHandlers = {}
+ }
+ if (!this.evtHandlers[evt]){
+ this.evtHandlers[evt] = []
+ }
+ this.evtHandlers[evt].push(callback)
+ }
}
+
+
+init()
@@ -1,7 +1,7 @@
<!doctype html>
<html>
<head>
-<title>Test'em Runner</title>
+<title>Test'em</title>
<link rel="stylesheet" href="/testem/buster-test.css">
<script src="/testem/buster-test.js"></script>
<script src="/testem.js"></script>
@@ -1,7 +1,7 @@
<!doctype html>
<html>
<head>
- <title>Test'em Runner</title>
+ <title>Test'em</title>
<script src="/testem.js"></script>
{{#scripts}}<script src="{{.}}"></script>{{/scripts}}
</head>
@@ -1,7 +1,7 @@
<!doctype html>
<html>
<head>
- <title>Test'em Runner</title>
+ <title>Test'em</title>
<script src="/testem/jasmine.js"></script>
<script src="/testem.js"></script>
<script src="/testem/jasmine-html.js"></script>
@@ -1,7 +1,7 @@
<!doctype html>
<html>
<head>
-<title>Test'em Runner</title>
+<title>Test'em</title>
<link rel="stylesheet" href="/testem/mocha.css">
<script src="/testem/mocha.js"></script>
<script src="/testem.js"></script>
@@ -1,6 +1,7 @@
<!doctype html>
<html>
<head>
+<title>Test'em</title>
<script src="/testem/qunit.js"></script>
<script src="/testem.js"></script>
{{#scripts}}<script src="{{.}}"></script>{{/scripts}}

0 comments on commit d03f132

Please sign in to comment.