X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=build%2Ftest%2Fdata%2Ftestrunner.js;h=f0e31e7f03dff5b00a63db00c391ca1adc5a2c9b;hb=1501447c7066bb7684dcfc34fb1dd3df512862de;hp=86a16d5c069da5d115625499d2f626dfe9ed1449;hpb=6b8ffe79f4e616d6179f6b16099e7c25e7ae5cb1;p=jquery.git diff --git a/build/test/data/testrunner.js b/build/test/data/testrunner.js index 86a16d5..f0e31e7 100644 --- a/build/test/data/testrunner.js +++ b/build/test/data/testrunner.js @@ -15,7 +15,10 @@ var _config = { $(function() { $('#userAgent').html(navigator.userAgent); - runTest(); + if($.browser.safari) + $("h1").append(" - Disabled for Safari"); + else + runTest(); }); function synchronize(callback) { @@ -33,12 +36,13 @@ function process() { } } -function stop() { +function stop(allowFailure) { _config.blocking = true; - _config.timeout = setTimeout(function() { + var handler = allowFailure ? start : function() { ok( false, "Test timed out" ); start(); - }, _config.asyncTimeout * 1000); + }; + _config.timeout = setTimeout(handler, _config.asyncTimeout * 1000); } function start() { if(_config.timeout) @@ -62,9 +66,18 @@ function runTest() { }); } -function test(name, callback) { +function test(name, callback, nowait) { + // safari seems to have some memory problems, so we need to slow it down + if($.browser.safari && !nowait) { + test("", function() { + stop(); + setTimeout(start, 250); + }, true); + } + if(_config.currentModule) name = _config.currentModule + " module: " + name; + synchronize(function() { _config.Test = []; try { @@ -81,6 +94,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" ] ); } @@ -155,19 +171,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 [