X-Git-Url: http://git.asbjorn.it/?a=blobdiff_plain;f=test%2Fdata%2Ftestrunner.js;h=821799bbf5251028bdf9c9b4714f48235b65324f;hb=9e48649729a5d4cd9ce52bcba067ba33a562cb4b;hp=6f426419b91cf70439913d14ebc16b6a097644cc;hpb=f12d94a6282d9efe6ba5863bf0de8a8a8b09a4af;p=jquery.git diff --git a/test/data/testrunner.js b/test/data/testrunner.js index 6f42641..821799b 100644 --- a/test/data/testrunner.js +++ b/test/data/testrunner.js @@ -1,3 +1,5 @@ +jQuery.noConflict(); // Allow the test to run with other libs or jQuery's. + var _config = { fixture: null, Test: [], @@ -13,10 +15,13 @@ var _config = { asyncTimeout: 2 // seconds for async timeout }; +_config.filters = location.search.length > 1 && //restrict modules/tests by get parameters + jQuery.map( location.search.slice(1).split('&'), decodeURIComponent ); + var isLocal = !!(window.location.protocol == 'file:'); -$(function() { - $('#userAgent').html(navigator.userAgent); +jQuery(function() { + jQuery('#userAgent').html(navigator.userAgent); runTest(); }); @@ -54,23 +59,39 @@ function start() { }, 13); } -function dontrun(name) { - var filter = location.search.slice(1); - return filter && !new RegExp(filter).test(encodeURIComponent(name)); +function validTest( name ) { + var filters = _config.filters; + if( !filters ) + return true; + + var i = filters.length, + run = false; + while( i-- ){ + var filter = filters[i], + not = filter.charAt(0) == '!'; + if( not ) + filter = filter.slice(1); + if( name.indexOf(filter) != -1 ) + return !not; + if( not ) + run = true; + } + return run; } function runTest() { _config.blocking = false; var time = new Date(); _config.fixture = document.getElementById('main').innerHTML; + _config.ajaxSettings = jQuery.ajaxSettings; synchronize(function() { time = new Date() - time; - $("
").html(['

Tests completed in ', + jQuery("

").html(['

Tests completed in ', time, ' milliseconds.
', _config.stats.bad, ' tests of ', _config.stats.all, ' failed.

'] .join('')) .appendTo("body"); - $("#banner").addClass(_config.stats.bad ? "fail" : "pass"); + jQuery("#banner").addClass(_config.stats.bad ? "fail" : "pass"); }); } @@ -78,7 +99,7 @@ function test(name, callback, nowait) { if(_config.currentModule) name = _config.currentModule + " module: " + name; - if (dontrun(name)) + if ( !validTest(name) ) return; synchronize(function() { @@ -91,7 +112,7 @@ function test(name, callback, nowait) { console.error(e); console.warn(callback.toString()); } - _config.Test.push( [ false, "Died on test #" + (_config.Test.length+1) + ": " + e ] ); + _config.Test.push( [ false, "Died on test #" + (_config.Test.length+1) + ": " + e.message ] ); } }); synchronize(function() { @@ -135,11 +156,11 @@ function test(name, callback, nowait) { else n.style.display = "none"; }; - $(b).dblclick(function(event) { + jQuery(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())); + location.href = location.href.match(/^(.+?)(\?.*)?$/)[1] + "?" + encodeURIComponent(jQuery.trim(target.text())); } }); li.appendChild( b ); @@ -165,12 +186,14 @@ function expect(asserts) { * Resets the test setup. Useful for tests that modify the DOM. */ function reset() { - $("#main").html( _config.fixture ); + jQuery("#main").html( _config.fixture ); + jQuery.event.global = {}; + jQuery.ajaxSettings = jQuery.extend({}, _config.ajaxSettings); } /** * Asserts true. - * @example ok( $("a").size() > 5, "There must be at least 5 anchors" ); + * @example ok( jQuery("a").size() > 5, "There must be at least 5 anchors" ); */ function ok(a, msg) { _config.Test.push( [ !!a, msg ] ); @@ -228,7 +251,7 @@ function serialArray( a ) { r.push( str ); } - return "[ " + r.join(", ") + " ]" + return "[ " + r.join(", ") + " ]"; } /**