X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=build%2Ftest%2Fdata%2Ftestrunner.js;h=69377e45216b48970067d81f551148c103534bc4;hb=139393fe0978e79c427ad13f1a03a10431ef95e5;hp=c3afea3390319366d9085d2e869b8e6bcaa740fe;hpb=7cc550727c4e0bcd93c5d435f0799f568fc74dfa;p=jquery.git
diff --git a/build/test/data/testrunner.js b/build/test/data/testrunner.js
index c3afea3..69377e4 100644
--- a/build/test/data/testrunner.js
+++ b/build/test/data/testrunner.js
@@ -13,6 +13,8 @@ var _config = {
asyncTimeout: 2 // seconds for async timeout
};
+var isLocal = !!(window.location.protocol == 'file:');
+
$(function() {
$('#userAgent').html(navigator.userAgent);
runTest();
@@ -33,15 +35,23 @@ function process() {
}
}
-function stop() {
+function stop(allowFailure) {
_config.blocking = true;
- _config.timeout = setTimeout(start, _config.asyncTimeout * 1000);
+ var handler = allowFailure ? start : function() {
+ ok( false, "Test timed out" );
+ start();
+ };
+ // Disabled, caused too many random errors
+ //_config.timeout = setTimeout(handler, _config.asyncTimeout * 1000);
}
function start() {
- if(_config.timeout)
- clearTimeout(_config.timeout);
- _config.blocking = false;
- process();
+ // A slight delay, to avoid any current callbacks
+ setTimeout(function(){
+ if(_config.timeout)
+ clearTimeout(_config.timeout);
+ _config.blocking = false;
+ process();
+ }, 13);
}
function runTest() {
@@ -55,13 +65,18 @@ function runTest() {
_config.stats.bad, ' tests of ', _config.stats.all, ' failed.
']
.join(''))
.appendTo("body");
- $("").addClass(_config.stats.bad ? "fail" : "pass").insertAfter("h1");
+ $("#banner").addClass(_config.stats.bad ? "fail" : "pass");
});
}
-function test(name, callback) {
+function test(name, callback, nowait) {
if(_config.currentModule)
name = _config.currentModule + " module: " + name;
+
+ var filter = location.search.slice(1);
+ if ( filter && encodeURIComponent(name).indexOf(filter) == -1 )
+ return;
+
synchronize(function() {
_config.Test = [];
try {
@@ -78,6 +93,9 @@ function test(name, callback) {
synchronize(function() {
reset();
+ // don't output pause tests
+ if(nowait) return;
+
if(_config.expected && _config.expected != _config.Test.length) {
_config.Test.push( [ false, "Expected " + _config.expected + " assertions, but " + _config.Test.length + " were run" ] );
}
@@ -104,7 +122,7 @@ function test(name, callback) {
var li = document.createElement("li");
li.className = state;
- var b = document.createElement("b");
+ var b = document.createElement("strong");
b.innerHTML = name + "
(" + bad + ", " + good + ", " + _config.Test.length + ")";
b.onclick = function(){
var n = this.nextSibling;
@@ -113,6 +131,13 @@ function test(name, callback) {
else
n.style.display = "none";
};
+ $(b).dblclick(function(event) {
+ var target = jQuery(event.target).filter("strong").clone();
+ if ( target.length ) {
+ target.children().remove();
+ location.href = location.href.match(/^(.+?)(\?.*)?$/)[1] + "?" + encodeURIComponent($.trim(target.text()));
+ }
+ });
li.appendChild( b );
li.appendChild( ol );
@@ -152,19 +177,57 @@ function ok(a, msg) {
*/
function isSet(a, b, msg) {
var ret = true;
- if ( a && b && a.length == b.length ) {
- for ( var i in a )
+ if ( a && b && a.length != undefined && a.length == b.length ) {
+ for ( var i = 0; i < a.length; i++ )
if ( a[i] != b[i] )
ret = false;
} else
ret = false;
if ( !ret )
- _config.Test.push( [ ret, msg + " expected: " + b + " result: " + a ] );
+ _config.Test.push( [ ret, msg + " expected: " + serialArray(b) + " result: " + serialArray(a) ] );
else
_config.Test.push( [ ret, msg ] );
}
/**
+ * Asserts that two objects are equivalent
+ */
+function isObj(a, b, msg) {
+ var ret = true;
+
+ if ( a && b ) {
+ for ( var i in a )
+ if ( a[i] != b[i] )
+ ret = false;
+
+ for ( i in b )
+ if ( a[i] != b[i] )
+ ret = false;
+ } else
+ ret = false;
+
+ _config.Test.push( [ ret, msg ] );
+}
+
+function serialArray( a ) {
+ var r = [];
+
+ if ( a && a.length )
+ for ( var i = 0; i < a.length; i++ ) {
+ var str = a[i].nodeName;
+ if ( str ) {
+ str = str.toLowerCase();
+ if ( a[i].id )
+ str += "#" + a[i].id;
+ } else
+ str = a[i];
+ r.push( str );
+ }
+
+ return "[ " + r.join(", ") + " ]"
+}
+
+/**
* Returns an array of elements with the given IDs, eg.
* @example q("main", "foo", "bar")
* @result [
, , ]
@@ -182,9 +245,59 @@ function q() {
* @result returns true if "//[a]" return two elements with the IDs 'foo' and 'baar'
*/
function t(a,b,c) {
- var f = jQuery.find(b);
+ var f = jQuery(b);
var s = "";
for ( var i = 0; i < f.length; i++ )
s += (s && ",") + '"' + f[i].id + '"';
isSet(f, q.apply(q,c), a + " (" + b + ")");
-}
\ No newline at end of file
+}
+
+/**
+ * Add random number to url to stop IE from caching
+ *
+ * @example url("data/test.html")
+ * @result "data/test.html?10538358428943"
+ *
+ * @example url("data/test.php?foo=bar")
+ * @result "data/test.php?foo=bar&10538358345554"
+ */
+function url(value) {
+ return value + (/\?/.test(value) ? "&" : "?") + new Date().getTime() + "" + parseInt(Math.random()*100000);
+}
+
+/**
+ * Checks that the first two arguments are equal, with an optional message.
+ * Prints out both expected and actual values on failure.
+ *
+ * Prefered to ok( expected == actual, message )
+ *
+ * @example equals( "Expected 2 characters.", v.formatMessage("Expected {0} characters.", 2) );
+ *
+ * @param Object expected
+ * @param Object actual
+ * @param String message (optional)
+ */
+function equals(actual, expected, message) {
+ var result = expected == actual;
+ message = message || (result ? "okay" : "failed");
+ _config.Test.push( [ result, result ? message + ": " + expected : message + " expected: " + expected + " actual: " + actual ] );
+}
+
+/**
+ * Trigger an event on an element.
+ *
+ * @example triggerEvent( document.body, "click" );
+ *
+ * @param DOMElement elem
+ * @param String type
+ */
+function triggerEvent( elem, type, event ) {
+ if ( jQuery.browser.mozilla || jQuery.browser.opera ) {
+ event = document.createEvent("MouseEvents");
+ event.initMouseEvent(type, true, true, elem.ownerDocument.defaultView,
+ 0, 0, 0, 0, 0, false, false, false, false, 0, null);
+ elem.dispatchEvent( event );
+ } else if ( jQuery.browser.msie ) {
+ elem.fireEvent("on"+type);
+ }
+}