From 012941ea628a34f5b4d59e8efaa5cb85fe581e00 Mon Sep 17 00:00:00 2001 From: Sam Saffron Date: Thu, 21 Feb 2013 16:01:18 +1100 Subject: [PATCH] basic smoke test script --- .../discourse/components/debounce.js | 59 +++++---- lib/tasks/smoke_test.rake | 15 ++- spec/phantom_js/smoke_test.js | 120 ++++++++++++------ 3 files changed, 125 insertions(+), 69 deletions(-) diff --git a/app/assets/javascripts/discourse/components/debounce.js b/app/assets/javascripts/discourse/components/debounce.js index fe998c1c0cf..00163158150 100644 --- a/app/assets/javascripts/discourse/components/debounce.js +++ b/app/assets/javascripts/discourse/components/debounce.js @@ -1,33 +1,32 @@ -(function() { +window.Discourse.debounce = function(func, wait, trickle) { + var timeout; - window.Discourse.debounce = function(func, wait, trickle) { - var timeout; - timeout = null; - return function() { - var args, context, currentWait, later; - context = this; - args = arguments; - later = function() { - 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; + timeout = null; + return function() { + var args, context, currentWait, later; + context = this; + args = arguments; + later = function() { + timeout = null; + return func.apply(context, args); }; - }; -}).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; + }; +}; diff --git a/lib/tasks/smoke_test.rake b/lib/tasks/smoke_test.rake index 4ac5b9108c8..4952d9e6e90 100644 --- a/lib/tasks/smoke_test.rake +++ b/lib/tasks/smoke_test.rake @@ -1,5 +1,16 @@ desc "run phantomjs based smoke tests on current build" -task "smoke:test" => :environment do - results = `phantomjs #{Rails.root}/spec/phantom_js/smoke_test.js #{Discourse.base_url}` +task "smoke:test" => :environment do + + 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 + if results !~ /ALL PASSED/ + raise "FAILED" + end end diff --git a/spec/phantom_js/smoke_test.js b/spec/phantom_js/smoke_test.js index b74fd967843..04966366dac 100644 --- a/spec/phantom_js/smoke_test.js +++ b/spec/phantom_js/smoke_test.js @@ -8,11 +8,9 @@ if(system.args.length !== 2) { var page = require('webpage').create(); -page.waitFor = function(desc, fn, t) { +page.waitFor = function(desc, fn, timeout, after) { var check,start,promise; - console.log("RUNNING: " + desc); - start = +new Date(); promise = {}; check = function() { @@ -25,14 +23,15 @@ page.waitFor = function(desc, fn, t) { // next time } + var diff = (+new Date()) - start; + if(r) { - promise.success = true; - console.log("PASSED: " + desc); + console.log("PASSED: " + desc + " " + diff + "ms" ); + after(true); } else { - var diff = (+new Date()) - start; - if(diff > t) { - promise.failure = true; - console.log("FAILED: " + desc); + if(diff > timeout) { + console.log("FAILED: " + desc + " " + diff + "ms"); + after(false); } else { setTimeout(check, 50); } @@ -40,41 +39,88 @@ page.waitFor = function(desc, fn, t) { }; check(); - return promise; }; -function afterAll(promises, fn){ - var i; - var test = function(){ - var good = true; - var allDone = true; - - for(i=0;i 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) { - console.log("Opened " + system.args[1]); - - 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(); - }); + page.runTests(); });