test runner: when errors are thrown in a test, the message is successfully show on...
[jquery.git] / test / data / testrunner.js
index 6f42641..d4fdcf5 100644 (file)
@@ -13,6 +13,9 @@ var _config = {
        asyncTimeout: 2 // seconds for async timeout
 };
 
+_config.filters = location.search.length > 1 && //restrict modules/tests by get parameters
+               $.map( location.search.slice(1).split('&'), decodeURIComponent );
+
 var isLocal = !!(window.location.protocol == 'file:');
 
 $(function() {
@@ -54,15 +57,31 @@ 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 = $.ajaxSettings;
        synchronize(function() {
                time = new Date() - time;
                $("<div>").html(['<p class="result">Tests completed in ',
@@ -78,7 +97,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 +110,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() {
@@ -166,6 +185,8 @@ function expect(asserts) {
  */
 function reset() {
        $("#main").html( _config.fixture );
+       $.event.global = {};
+       $.ajaxSettings = $.extend({}, _config.ajaxSettings);
 }
 
 /**
@@ -228,7 +249,7 @@ function serialArray( a ) {
             r.push( str );
         }
 
-       return "[ " + r.join(", ") + " ]"
+       return "[ " + r.join(", ") + " ]";
 }
 
 /**