Skip to content
This repository has been archived by the owner on Mar 15, 2021. It is now read-only.

Commit

Permalink
Incorporating changes from Yammer's foounit modifications; Include so…
Browse files Browse the repository at this point in the history
…urce line numbers; Added params to configure the suite's UI; Fixed foounit's runtime stats in the browser
  • Loading branch information
Bob Remeika committed Jan 24, 2012
1 parent 56bb607 commit db5c24d
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 15 deletions.
18 changes: 13 additions & 5 deletions src/adapters/browser/ui.js
Expand Up @@ -3,7 +3,9 @@ if (typeof foounit.ui == 'undefined'){
}

(function (ui){
var _body, _index = 0, _autoScrolling = true;
var _body, _index = 0
, _autoScrolling = window.location.search.indexOf("foounit.ui.autoScroll=true") > -1
, _logAll = window.location.search.indexOf("foounit.ui.log=all") > -1;

var _createTitleNode = function (title, index, className){
var titleDiv = document.createElement('div');
Expand Down Expand Up @@ -102,11 +104,15 @@ if (typeof foounit.ui == 'undefined'){
}

this.bottom = function (){
window.scroll(0, 1000000);
if (_autoScrolling){
window.scroll(0, 1000000);
}
}

this.top = function (){
window.scroll(0, 0);
if (_autoScrolling){
window.scroll(0, 0);
}
}

}
Expand Down Expand Up @@ -146,7 +152,9 @@ if (typeof foounit.ui == 'undefined'){
*/
ui.onSuccess = function (example){
try {
_body.appendChild(_createSuccessNode(example, _index));
if (_logAll){
_body.appendChild(_createSuccessNode(example, _index));
}
_progressBar.success(_index);
_scroller.bottom();
++_index;
Expand Down Expand Up @@ -180,7 +188,7 @@ if (typeof foounit.ui == 'undefined'){
info.pending.length + ' pending, ' +
info.totalCount + ' total');

_progressBar.log('>> foounit runtime: ', info.runMillis + 'ms');
_progressBar.log('>> foounit runtime: ' + info.runMillis + 'ms');
_scroller.top();
} catch (e){
alert('foounit.ui.onFinish: ' + e.message);
Expand Down
31 changes: 21 additions & 10 deletions src/adapters/browser/xhr_loader_strategy.js
Expand Up @@ -40,9 +40,26 @@ foounit.browser.XhrLoaderStrategy = function (){
return parts[parts.length - 1];
};

var geval = function (src){
var geval = function (src, hint){
var g = foounit.hostenv.global;
return (g.execScript) ? g.execScript(src) : g.eval.call(null, src);
src += appendHint(src, hint);
return (g.execScript) ? g.execScript(src) : g.eval.call(g, src);
};

var leval = function (src, hint){
src = appendHint(src, hint);

var ret;
if (document.all){ // IE is slightly different
eval('ret = ' + src);
} else {
ret = eval(src);
}
return ret;
};

var appendHint = function (src, hint){
return src + "\r\n////@ sourceURL=" + hint;
};

/**
Expand All @@ -54,14 +71,8 @@ foounit.browser.XhrLoaderStrategy = function (){
, module = { exports: {} }
, funcString = '(function (foounit, module, exports, __dirname, __filename){' + code + '});';

var func;
try {
// IE sucks shit.
if (document.all){
eval('func = ' + funcString);
} else {
func = eval(funcString);
}
var func = leval(funcString, path);
func.call({}, foounit, module, module.exports, dirname(path), basename(path));
} catch (e){
console.error('Failed to load path: ' + path + ': ' + e.message, e);
Expand All @@ -75,7 +86,7 @@ foounit.browser.XhrLoaderStrategy = function (){
*/
this.load = function (path){
var code = get(path);
geval(code);
geval(code, path);
return true;
};
};

0 comments on commit db5c24d

Please sign in to comment.