File size: 2,003 Bytes
7e79d67 | 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 | var TestSuite = {
suite: $H(),
add: function(suiteName, test) {
TestSuite.suite[suiteName] = test;
}
};
Event.observe(window, "load", function() {
//adding ?filter=foo in the query only runs tests matching foo
var filter = undefined;
var params = window.location.search.toString().toQueryParams();
if (params["filter"]) {
filter = params["filter"];
}
//build the test suite by concatenating all tests
var suiteCounter = 0;
TestSuite.suite.each(function(suite) {
var suiteName = suite.key;
var suiteTests = suite.value;
var filteredTests = {};
var hasTests = false;
//filter the test suite
$H(suiteTests).each(function(pair) {
var name = pair.key+"_"+suiteName;
if (/^test/.test(name)) {
if (!filter || new RegExp(filter,"i").test(name)) {
hasTests = true;
filteredTests[name] = pair.value;
}
} else { //setup or teardown
filteredTests[pair.key] = pair.value;
}
});
if (hasTests) {
//move the old console
var oldlog = $('testlog');
if (oldlog) {
oldlog.id = 'testlog'+(suiteCounter++);
}
//create a new title and console
var title = $E("h3");
title.innerHTML = suiteName;
var newlog = $E('div');
newlog.id = 'testlog';
document.body.appendChild(title);
document.body.appendChild(newlog);
//launch the tests
new Test.Unit.Runner(filteredTests);
}
});
});
//override _isVisible in scriptaculous: the original code returned true
//for an element with "display:none" and no parent
Test.Unit.Assertions.prototype._isVisible= function(element) {
element = $(element);
this.assertNotNull(element);
if(element.style && Element.getStyle(element, 'display') == 'none')
return false;
if(!element.parentNode) return true;
return this._isVisible(element.parentNode);
};
Test.Unit.Testcase.prototype._isVisible = Test.Unit.Assertions.prototype._isVisible;
|