hi john, your right that is where it should be done.  the problem arises
from the fact that we load the scripts for the test from the html itself, as
part of the browser emulation process.  this means that we can only affect
the global scope before the html is loaded, onload, and after load.
otherwise we would need to copy the script loading process outside of the
native browser loading process and either duplicate the process (at best)
and usually only approach something similar.

for example our old script for kick off the tests was:

// Init
load("build/runtest/env.js");

var isLocal;
window.onload = function(){
    isLocal  = !!(window.location.protocol == 'file:');

    // Load the test runner
    load("dist/jquery.js",
        "build/runtest/testrunner.js");

    // Load the tests
    load(
        "test/unit/core.js",
        "test/unit/selector.js",
        "test/unit/event.js",
        "test/unit/fx.js",
        "test/unit/dimensions.js",
        "test/unit/data.js",

        // offset relies on window.open, which is currently unimplemented in
env.js
        //"test/unit/offset.js",

        // these tests require hitting a server, so we will need some clever
env.js
        // way of testing them
        "test/unit/ajax.js"
    );

    // Display the results
    results();
};

and now its just:

(function($env){

    //let it load the script from the html
    $env.scriptTypes = {
        "text/javascript"   :true
    };

    var count = 0;
    window.console = {
        log: function(result, message){
            $env.log('(' + (count++) + ')[' + ((!!result) ? 'PASS' : 'FAIL')
+ '] ' + message);
        }
    };

    window.onload = function(){
        $env.warn('Defining QUnit.done');
        QUnit.done = function(pass, fail){
            $env.warn('Writing Results to File');
            jQuery('script').each(function(){
                this.type = 'text/envjs';
            });
            $env.writeToFile(
                document.documentElement.xml,
                $env.location('jqenv.html')
            );
        };

    }

    window.location = "test/index.html";

})(Envjs);

where i did modify the qunit to define QUnit.log as in the last email.

does this make sense?  the latter approach lets the html essentially define
everything we need to know and just load and go, setting up our hooks prior
to setting window.location

thatcher

On Fri, May 15, 2009 at 4:52 PM, John Resig <jere...@gmail.com> wrote:

> I'm confused - why are you attaching the QUnit.done/log handlers inside
> window.onload? Ideally they should be the very first thing done (after
> loading the test suite itself).
>
> --John
>
>
> On Tue, May 12, 2009 at 10:59 PM, chris thatcher <
> thatcher.christop...@gmail.com> wrote:
>
>> I noticed we where using an older testrunner.js with envjs even when
>> running 1.3.2 unit tests.  i start playing with it and realized qunit works
>> great and i can even use QUnit.done to output a static html file with the
>> result of running the tests in envjs.  the only snag I had was being able to
>> hook to QUnit.log .  this may be a bug with envjs implementation of onload
>> so please feel free to point out if im mistaken.
>>
>> here is the script that initiates it:
>>
>> load("build/runtest/env.js");
>>
>> (function($env){
>>
>>     //let it load the script from the html
>>     $env.scriptTypes = {
>>         "text/javascript"   :true
>>     };
>>
>>     var count = 0;
>>     window.onload = function(){
>>
>>         //this doesnt work because onload isn't called until after the
>> tests run
>>         QUnit.log = function(result, message){
>>             $env.log('('+(count++)+')['+((!!result)?'PASS':'FAIL')+'] ' +
>> message );
>>         };
>>
>>         //this works because done is called from syncronize()
>>         QUnit.done = function(pass, fail){
>>             //write resulting window less scripts to an html file
>>             jQuery('script').each(function(){
>>                this.type = 'text/envjs';
>>             });
>>             $env.writeToFile(
>>                 document.documentElement.xml,
>>                 $env.location('jqenv.html')
>>             );
>>         };
>>
>>     };
>>
>>     window.location = "test/index.html";
>>
>> })(__env__);
>>
>>
>> I was wondering if you could either add a synchronized 'begin' or let log
>> just be global
>>
>> $.extend(window, {
>>       ///...
>>       log: log?log:function(result, message);
>> });
>>
>> thanks
>> thatcher
>> --
>> Christopher Thatcher
>>
>>
>>
>
> >
>


-- 
Christopher Thatcher

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"jQuery Development" group.
To post to this group, send email to jquery-dev@googlegroups.com
To unsubscribe from this group, send email to 
jquery-dev+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/jquery-dev?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to