From 2226207ecdb4b375e6eaa8034b36f00d8bb6300f Mon Sep 17 00:00:00 2001 From: Sam Saffron Date: Thu, 21 Feb 2013 12:07:22 +1100 Subject: [PATCH] smoke test --- lib/tasks/smoke_test.rake | 5 +++ spec/phantom_js/smoke_test.js | 80 +++++++++++++++++++++++++++++++++++ 2 files changed, 85 insertions(+) create mode 100644 lib/tasks/smoke_test.rake create mode 100644 spec/phantom_js/smoke_test.js diff --git a/lib/tasks/smoke_test.rake b/lib/tasks/smoke_test.rake new file mode 100644 index 00000000000..4ac5b9108c8 --- /dev/null +++ b/lib/tasks/smoke_test.rake @@ -0,0 +1,5 @@ +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}` + puts results +end diff --git a/spec/phantom_js/smoke_test.js b/spec/phantom_js/smoke_test.js new file mode 100644 index 00000000000..b74fd967843 --- /dev/null +++ b/spec/phantom_js/smoke_test.js @@ -0,0 +1,80 @@ +console.log('Starting Smoke Test'); +var system = require('system'); + +if(system.args.length !== 2) { + console.log("expecting phantomjs {smoke_test.js} {base_url}"); + phantom.exit(1); +} + +var page = require('webpage').create(); + +page.waitFor = function(desc, fn, t) { + var check,start,promise; + + console.log("RUNNING: " + desc); + + start = +new Date(); + promise = {}; + check = function() { + var r; + + try { + r = page.evaluate(fn); + } + catch(err) { + // next time + } + + if(r) { + promise.success = true; + console.log("PASSED: " + desc); + } else { + var diff = (+new Date()) - start; + if(diff > t) { + promise.failure = true; + console.log("FAILED: " + desc); + } else { + setTimeout(check, 50); + } + } + }; + + check(); + return promise; +}; + +function afterAll(promises, fn){ + var i; + var test = function(){ + var good = true; + var allDone = true; + + for(i=0;i 0); + }, 5000); + + afterAll([gotTopics], function(success){ + if(success) { + console.log("ALL PASSED"); + } + phantom.exit(); + }); +});