jquery testrunner: reset global events after each run, speeds up a test run for ajax...
[jquery.git] / test / data / testrunner.js
index 69377e4..bdb938c 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,6 +57,26 @@ function start() {
        }, 13);
 }
 
+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();
@@ -73,8 +96,7 @@ 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 )
+       if ( !validTest(name) )
                return;
                
        synchronize(function() {
@@ -161,7 +183,8 @@ function expect(asserts) {
  * Resets the test setup. Useful for tests that modify the DOM.
  */
 function reset() {
-       document.getElementById('main').innerHTML = _config.fixture;
+       $("#main").html( _config.fixture );
+       $.event.global = {};
 }
 
 /**
@@ -224,7 +247,7 @@ function serialArray( a ) {
             r.push( str );
         }
 
-       return "[ " + r.join(", ") + " ]"
+       return "[ " + r.join(", ") + " ]";
 }
 
 /**
@@ -273,8 +296,8 @@ function url(value) {
  *
  * @example equals( "Expected 2 characters.", v.formatMessage("Expected {0} characters.", 2) );
  *
- * @param Object expected
  * @param Object actual
+ * @param Object expected
  * @param String message (optional)
  */
 function equals(actual, expected, message) {