forked from madrobby/zepto
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathevidence_runner.js
96 lines (87 loc) · 3.13 KB
/
evidence_runner.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
(function(){
var ConsoleTestRunner = Evidence.AutoRunner.RUNNERS.console,
ConsoleTestResult = Evidence.UI.Console.TestResult,
AutoRunner = Evidence.AutoRunner,
printf = Evidence.UI.printf
function inherit(superclass, extra) {
var klass = function(){
this.initialize.apply(this, arguments)
}
var tmp = function(){}
tmp.prototype = superclass.prototype
klass.prototype = new tmp()
klass.prototype.constructor = klass
klass.prototype.initialize = function(){
superclass.apply(this, arguments)
}
if (extra) {
var methods = extra.call(klass, superclass.prototype)
for (var method in methods) klass.prototype[method] = methods[method]
}
return klass
}
var TestRunner = inherit(ConsoleTestRunner, function(_super) {
AutoRunner.RUNNERS.zepto = this
return {
_makeResult: function() { return new TestResult(this.logger) }
}
})
var TestResult = inherit(ConsoleTestResult, function(_super) {
return {
start: function(t0) {
Evidence.TestResult.prototype.start.call(this, t0)
this.logger.debug('Started tests.')
},
stop: function(t1) {
_super.stop.call(this, t1)
displayResults(this, (t1-this.t0)/1000)
checkLeakedGlobals()
},
pauseTest: function(testcase) {
this.logger.debug('Paused testcase ' + testcase + '.')
},
restartTest: function(testcase) {
this.logger.debug('Restarted testcase ' + testcase + '.')
},
startSuite: function(suite) {
this.logger.debug('Started suite ' + suite + '.')
}
}
})
// HACK: force our test runner as default
;(function(){
var _super = AutoRunner.prototype.retrieveOptions
AutoRunner.prototype.retrieveOptions = function() {
var options = _super.call(this)
if (!options.runner) options.runner = 'zepto'
return options
}
})()
function $(id) { return document.getElementById(id) }
function displayResults(results, seconds) {
var container = $('results')
if (container) {
if (results.failureCount || results.errorCount) {
container.className = 'failed'
container.innerHTML = printf("Finished in %d s. – <em>%d failures, %d errors</em> (%d assertions)",
[seconds, results.failureCount, results.errorCount, results.assertionCount])
} else {
container.className = 'passed'
container.innerHTML = printf("Finished in %d s. – <em>%d tests passed</em> (%d assertions)",
[seconds, results.testCount, results.assertionCount])
}
container.className += ' finished'
}
}
var globals = [], expected = ['Zepto', '$', 'Evidence']
for (var key in window) globals.push(key)
function checkLeakedGlobals() {
var opera = /^Opera\b/.test(navigator.userAgent)
for (var key in window)
if ( globals.indexOf(key) < 0 && expected.indexOf(key) < 0 &&
(!opera || typeof window[key] != 'object' || window[key].id != key) &&
window.console && console.warn
)
console.warn("unexpected global: " + key)
}
})()