basic smoke test script

This commit is contained in:
Sam Saffron 2013-02-21 16:01:18 +11:00
parent 250bd3cd21
commit 012941ea62
3 changed files with 125 additions and 69 deletions

View File

@ -1,33 +1,32 @@
(function() { window.Discourse.debounce = function(func, wait, trickle) {
var timeout;
window.Discourse.debounce = function(func, wait, trickle) { timeout = null;
var timeout; return function() {
timeout = null; var args, context, currentWait, later;
return function() { context = this;
var args, context, currentWait, later; args = arguments;
context = this; later = function() {
args = arguments; timeout = null;
later = function() { return func.apply(context, args);
timeout = null;
return func.apply(context, args);
};
if (timeout && trickle) {
/* already queued, let it through
*/
return;
}
if (typeof wait === "function") {
currentWait = wait();
} else {
currentWait = wait;
}
if (timeout) {
clearTimeout(timeout);
}
timeout = setTimeout(later, currentWait);
return timeout;
}; };
};
}).call(this); if (timeout && trickle) {
/* already queued, let it through */
return;
}
if (typeof wait === "function") {
currentWait = wait();
} else {
currentWait = wait;
}
if (timeout) {
clearTimeout(timeout);
}
timeout = setTimeout(later, currentWait);
return timeout;
};
};

View File

@ -1,5 +1,16 @@
desc "run phantomjs based smoke tests on current build" desc "run phantomjs based smoke tests on current build"
task "smoke:test" => :environment do task "smoke:test" => :environment do
results = `phantomjs #{Rails.root}/spec/phantom_js/smoke_test.js #{Discourse.base_url}`
phantom_path = File.expand_path('~/phantomjs/bin/phantomjs')
phantom_path = nil unless File.exists?(phantom_path)
phantom_path = phantom_path || 'phantomjs'
url = ENV["URL"] || Discourse.base_url
puts "Testing: #{url}"
results = `#{phantom_path} #{Rails.root}/spec/phantom_js/smoke_test.js #{url}`
puts results puts results
if results !~ /ALL PASSED/
raise "FAILED"
end
end end

View File

@ -8,11 +8,9 @@ if(system.args.length !== 2) {
var page = require('webpage').create(); var page = require('webpage').create();
page.waitFor = function(desc, fn, t) { page.waitFor = function(desc, fn, timeout, after) {
var check,start,promise; var check,start,promise;
console.log("RUNNING: " + desc);
start = +new Date(); start = +new Date();
promise = {}; promise = {};
check = function() { check = function() {
@ -25,14 +23,15 @@ page.waitFor = function(desc, fn, t) {
// next time // next time
} }
var diff = (+new Date()) - start;
if(r) { if(r) {
promise.success = true; console.log("PASSED: " + desc + " " + diff + "ms" );
console.log("PASSED: " + desc); after(true);
} else { } else {
var diff = (+new Date()) - start; if(diff > timeout) {
if(diff > t) { console.log("FAILED: " + desc + " " + diff + "ms");
promise.failure = true; after(false);
console.log("FAILED: " + desc);
} else { } else {
setTimeout(check, 50); setTimeout(check, 50);
} }
@ -40,41 +39,88 @@ page.waitFor = function(desc, fn, t) {
}; };
check(); check();
return promise;
}; };
function afterAll(promises, fn){
var i;
var test = function(){
var good = true;
var allDone = true;
for(i=0;i<promises.length;i++){
good = good && promises[i].success;
allDone = allDone && (promises[i].success || promises[i].failure);
}
if(allDone){ var actions = [];
fn(good);
var test = function(desc, fn) {
actions.push({test: fn, desc: desc});
};
var navigate = function(desc, fn) {
actions.push({navigate: fn, desc: desc});
};
var run = function(){
var allPassed = true;
var done = function() {
if(allPassed) {
console.log("ALL PASSED");
} else { } else {
setTimeout(test, 50); console.log("SMOKE TEST FAILED");
}
phantom.exit();
};
var performNextAction = function(){
if(actions.length === 0) {
done();
}
else{
var action = actions[0];
actions = actions.splice(1);
if(action.test) {
page.waitFor(action.desc, action.test, 10000, function(success){
allPassed = allPassed && success;
performNextAction();
});
}
else if(action.navigate) {
console.log("NAVIGATE: " + action.desc);
page.evaluate(action.navigate);
performNextAction();
}
} }
}; };
test();
} performNextAction();
};
page.runTests = function(){
test("more than one topic shows up", function() {
return $('#topic-list tbody tr').length > 0;
});
test("expect a log in button", function(){
return $('.current-username .btn').text() === 'Log In';
});
navigate("navigate to first topic", function(){
Em.run.next(function(){
$('.main-link a:first').click();
});
});
test("at least one post body", function(){
return $('.topic-post').length > 0;
});
navigate("navigate to first user", function(){
Em.run.next(function(){
$('.topic-meta-data a:first').focus().click();
});
});
test("has about me section",function(){
return $('.about-me').length === 1;
});
run();
};
page.open(system.args[1], function (status) { page.open(system.args[1], function (status) {
console.log("Opened " + system.args[1]); console.log("Opened " + system.args[1]);
page.runTests();
var gotTopics = page.waitFor("more than one topic shows up" , function(){
return ($('#topic-list tbody tr').length > 0);
}, 5000);
afterAll([gotTopics], function(success){
if(success) {
console.log("ALL PASSED");
}
phantom.exit();
});
}); });