Bug Tracker

Ticket #3215: testrunner.patch

File testrunner.patch, 2.7 kB (added by chadmyers, 5 months ago)

Testrunner patch for trunk rev 5800.

  • testrunner.js

     
    1515    Test: [], 
    1616    stats: { 
    1717        all: 0, 
     18        good: 0, 
    1819        bad: 0 
    1920    }, 
    2021    queue: [], 
     
    2223    timeout: null, 
    2324    expected: null, 
    2425    currentModule: null, 
     26    startTime : new Date().getTime(), 
     27    beforeEach : null, 
     28    afterEach : null, 
    2529    asyncTimeout: 2 // seconds for async timeout 
     30     
    2631}; 
    2732 
    2833_config.filters = location.search.length > 1 && //restrict modules/tests by get parameters 
     
    3540    runTest();   
    3641}); 
    3742 
     43function qUnitTesting( testsCallback ){ 
     44    $(document).ready(function(){ 
     45        testsCallback(_config); 
     46        allTestsDone();         
     47    }); 
     48} 
     49 
    3850function synchronize(callback) { 
    3951    _config.queue[_config.queue.length] = callback; 
    4052    if(!_config.blocking) { 
     
    90102} 
    91103 
    92104function runTest() { 
    93     _config.blocking = false; 
    94     var time = new Date(); 
     105    _config.blocking = false;    
    95106    _config.fixture = document.getElementById('main').innerHTML; 
    96107    _config.ajaxSettings = $.ajaxSettings; 
     108} 
     109 
     110function allTestsDone(){ 
     111    synchronize(function(){ 
     112        updateStats(); 
     113        $("<div>").attr("id", "TESTRESULTS").html(""+_config.stats.bad).hide().appendTo("body");         
     114    }); 
     115} 
     116 
     117function updateStats(){ 
    97118    synchronize(function() { 
    98         time = new Date() - time; 
    99         $("<div>").html(['<p class="result">Tests completed in ', 
    100             time, ' milliseconds.<br/>', 
     119        _config.endTime = new Date().getTime(); 
     120        $("#results").html(['<p class="result">Tests completed in ', 
     121            (_config.endTime - _config.startTime), ' milliseconds.<br/>', 
     122            _config.stats.good, ' tests of ', _config.stats.all, ' passed.<br/>', 
    101123            _config.stats.bad, ' tests of ', _config.stats.all, ' failed.</p>'] 
    102             .join('')) 
    103             .appendTo("body"); 
     124            .join('')); 
    104125        $("#banner").addClass(_config.stats.bad ? "fail" : "pass"); 
    105126    }); 
    106127} 
     
    115136    synchronize(function() { 
    116137        _config.Test = []; 
    117138        try { 
     139            if( _config.beforeEach ){ _config.beforeEach(name); } 
    118140            callback(); 
     141            if( _config.afterEach ){ _config.afterEach(name); } 
    119142        } catch(e) { 
    120143            if( typeof console != "undefined" && console.error && console.warn ) { 
    121144                console.error("Test " + name + " died, exception and test follows"); 
     
    159182                state = "fail"; 
    160183                bad++; 
    161184                _config.stats.bad++; 
    162             } else good++; 
     185            } else { 
     186                good++; 
     187                _config.stats.good++; 
     188            } 
    163189        } 
    164190     
    165191        var li = document.createElement("li"); 
     
    185211        li.appendChild( ol ); 
    186212     
    187213        document.getElementById("tests").appendChild( li );      
    188     }); 
     214    });     
    189215} 
    190216 
    191217// call on start of module test to prepend name to all tests