Skip to content

Commit

Permalink
merged
Browse files Browse the repository at this point in the history
  • Loading branch information
moschel committed Mar 24, 2012
1 parent e3135ca commit 34f1238
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 85 deletions.
18 changes: 4 additions & 14 deletions commandline/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,9 @@ steal('funcunit/commandline/output', function(){
// bind all events
FuncUnit.bindEvents = function(browser){
browser.bind("begin", function(data){
FuncUnit.begin();
})
.bind("browserStart", function(data){
FuncUnit.starttime = new Date().getTime();
browserFailed = browserTotal = 0;
FuncUnit.browserStart(data.browser);
})
.bind("browserDone", function(data){
FuncUnit.endtime = new Date().getTime();
var duration = (FuncUnit.endtime - FuncUnit.starttime) / 1000;
FuncUnit.browserDone(data.browser, browserFailed, browserTotal, duration)
FuncUnit.begin(FuncUnit.browserName);
})
.bind('testDone', function(data){
browserFailed += data.failed;
Expand All @@ -40,12 +32,10 @@ steal('funcunit/commandline/output', function(){
FuncUnit.moduleDone(data.name, data.failed, data.total)
})
.bind('done', function(data){
FuncUnit.done(totalFailed, total);
FuncUnit.endtime = new Date().getTime();
var duration = (FuncUnit.endtime - FuncUnit.starttime) / 1000;
FuncUnit.done(totalFailed, total, duration);
this.close();
})
// for selenium, all browsers are done running
.bind('allDone', function(data){

})
.bind('coverage', function(data){
FuncUnit.coverage(data)
Expand Down
9 changes: 2 additions & 7 deletions commandline/output/output.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ steal('funcunit/commandline/output/json2.js', function(){
var streamClosed = false;

steal.extend(FuncUnit,{
begin: function(){
begin: function(name){
print("Starting " + name + "...")
classPrefix = 'QUnit.';
filename = 'testresults.xml';
if(filename) {
Expand Down Expand Up @@ -157,12 +158,6 @@ steal('funcunit/commandline/output/json2.js', function(){
java.lang.System.exit(1);
}
},
browserStart: function(name){
print("Starting " + name + "...")
},
browserDone: function(name, failures, total){
print("\n" + name+" done :-)");
},
coverage: function(stats){
var percentage = function(num){
return Math.round(num*1000)/10+"%";
Expand Down
10 changes: 5 additions & 5 deletions commandline/selenium.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
steal('funcunit/selenium', function(){
var getDefaultBrowsers = function(){
return ["*firefox"];
var getDefaultBrowser = function(){
return "*firefox";
}

/**
* Loads the FuncUnit page in Selenium
*/
FuncUnit.loader.selenium = function(page){
FuncUnit.browsers = FuncUnit.browsers || getDefaultBrowsers();
FuncUnit.loader.selenium = function(page, browser){
FuncUnit.browserName = browser || getDefaultBrowser();

// expose FuncUnit.browser so people can call close themselves
FuncUnit.browser = new steal.browser.selenium({
Expand All @@ -16,6 +16,6 @@ steal('funcunit/selenium', function(){
});

FuncUnit.bindEvents(FuncUnit.browser)
FuncUnit.browser.open(page, FuncUnit.browsers)
FuncUnit.browser.open(page)
}
})
23 changes: 4 additions & 19 deletions commandline/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,9 @@ steal(function(){
}

// if coverage is true, use this to change the URL
// page can be a .html or a .js file
FuncUnit._getPageUrl = function(page, coverage, ignores){
var isHtml = true,
testFile = page;

if(!/\.html$/.test(page)){
isHtml = false;
page = "funcunit/dashboard/frame/qunit.html";
if(FuncUnit.jmvcRoot){
page = FuncUnit.jmvcRoot + "/" + page;
}
FuncUnit._getPageUrl = function(page, coverage){
if(FuncUnit.jmvcRoot){
page = FuncUnit.jmvcRoot + "/" + page;
}
if(!/https?:|file:/.test(page)){ // if theres no protocol, turn it into a filesystem urls
var cwd = (new java.io.File (".")).getCanonicalPath()+"";
Expand All @@ -48,14 +40,7 @@ steal(function(){
var newPage = /https?:/.test(page) ? page: page.replace(/ /g,"%20");

if(coverage){
if(!(ignores && ignores.length)){
ignores = ["true"];
}
newPage = newPage+"?steal[instrument]=";
newPage += ignores.join(",");
}
if(!isHtml){
newPage += "&test="+testFile;
newPage = newPage+"?coverage=true";
}
return newPage;
}
Expand Down
7 changes: 4 additions & 3 deletions run
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,16 @@

var opts = steal.opts(_args, {
coverage: 0,
settings: 1
settings: 1,
browser: 1
})
steal('funcunit/commandline/utils.js')
.then('funcunit/commandline/'+type+'.js',
function(){
FuncUnit._loadSettingsFile(page, opts.settings);
FuncUnit.funcunitPage = FuncUnit._getPageUrl(page, opts.coverage, FuncUnit.coverageIgnore);
FuncUnit.funcunitPage = FuncUnit._getPageUrl(page, opts.coverage);
print("Opening "+FuncUnit.funcunitPage);
FuncUnit.loader[type](FuncUnit.funcunitPage);
FuncUnit.loader[type](FuncUnit.funcunitPage, opts.browser);
})

})()
38 changes: 7 additions & 31 deletions selenium/selenium.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,10 @@ steal('steal/browser', function(){
/**
* Opens the browser, at each of the specified browsers, one by one
* @param {Object} page
* @param {Object} browsers
*/
open: function(page, browsers){
this._currentBrowserIndex = 0;
open: function(page){
this.page = this._getPageUrl(page);
this.browsers = browsers || ["*firefox"];
this._browserStart(0);
this._browserStart();
this._poll();
// block until we're done
this.browserOpen = true;
Expand Down Expand Up @@ -114,41 +111,22 @@ steal('steal/browser', function(){
}
},
// create new selenium instance, start it, open page, set FuncUnit.mode = "Selenium", start polling for data
_browserStart: function(index){
var browser = this.browsers[this._currentBrowserIndex];
this.trigger("browserStart", {
browser: browser
})
_browserStart: function(){
this.selenium = this.DefaultSelenium(this.options.serverHost,
this.options.serverPort,
browser,
FuncUnit.browserName,
this.page);
this.selenium.start();
this.selenium.open(this.page);
selThreads.resumePolling();
},
close: function(data){
//print(">>>>>>>>>> CLOSING")
//this.keepPolling = false;
var browser = this.browsers[this._currentBrowserIndex];
this.trigger("browserDone", {
browser: browser
});
selThreads.pausePolling();
this.selenium.close();
this.selenium.stop();
//print(">>>>>>>>>> STOPPED")
this._currentBrowserIndex++;
if (this._currentBrowserIndex < this.browsers.length) {
this._browserStart(this._currentBrowserIndex)
}
else {
selThreads.stopPolling();
//print(">>>>>>>>>> ALL DONE")
this.trigger("allDone");
this.killServer();
this.browserOpen = false;
}
selThreads.stopPolling();
this.killServer();
this.browserOpen = false;
},
evaluate: function(fn){
var txt = fn.toString().replace(/\n|\r\n/g,""),
Expand Down Expand Up @@ -204,8 +182,6 @@ steal('steal/browser', function(){
var resultJSON,
res,
evt;
//self.keepPolling = true;
//print(">>>>>>>>>> POLLING")
resultJSON = self.selenium.getEval("Selenium.getResult()");
eval("res = "+resultJSON);
if(res && res.length){
Expand Down
7 changes: 2 additions & 5 deletions settings.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
FuncUnit = {
// the list of browsers that selenium runs tests on
// browsers: ["*firefox", "*googlechrome"],

// the root where funcunit folder lives, used when running from commandline
// jmvcRoot: "http://localhost:3000/javascriptmvc",

Expand All @@ -15,6 +12,6 @@ FuncUnit = {
// any files or directories that coverage calculations should ignore
coverageIgnore: ['*/test', "*_test.js", "*jquery.js", "*qunit.js"]

// uncomment this to ignore all JMVC directories
// coverageIgnore: ["!jmvc"]
// uncomment this to record test output in an xml format that jenkins can read
// outputFile: "testresults.xml"
}
2 changes: 1 addition & 1 deletion syn
Submodule syn updated from 4206b2 to ba495a

0 comments on commit 34f1238

Please sign in to comment.