From 3aa9e1a36acdf8fee46e956c8bf24443bbe66fc0 Mon Sep 17 00:00:00 2001 From: Naomi Seyfer Date: Thu, 21 Mar 2013 11:35:06 -0700 Subject: [PATCH] Clean up test-in-console output --- packages/test-in-console/driver.js | 38 ++++++++++++++++++++-------- packages/test-in-console/package.js | 4 +-- packages/test-in-console/reporter.js | 12 +++++---- packages/test-in-console/run.sh | 24 +++++------------- packages/test-in-console/runner.js | 16 ++++++++---- 5 files changed, 54 insertions(+), 40 deletions(-) diff --git a/packages/test-in-console/driver.js b/packages/test-in-console/driver.js index ecdbdf1b02..53329b789e 100644 --- a/packages/test-in-console/driver.js +++ b/packages/test-in-console/driver.js @@ -1,10 +1,18 @@ +// Global flag for phantomjs (or other browser) to eval to see if we're done. DONE = false; +// Failure count for phantomjs exit code +FAILURES = null; var getName = function (result) { return (result.server ? "S: " : "C: ") + result.groupPath.join(" - ") + " - " + result.test; }; +var log = function (/*arguments*/) { + if (typeof console !== 'undefined') { + console.log.apply(console, arguments); + } +}; var finished = 0; @@ -16,9 +24,10 @@ var toReport = []; var hrefPath = document.location.href.split("/"); var platform = hrefPath.length && hrefPath[hrefPath.length - 1]; -if (_.isEmpty(platform)) +if (!platform) platform = "local"; var doReport = Meteor && + Meteor.settings && Meteor.settings.public && Meteor.settings.public.runId; var report = function (name, last) { @@ -88,22 +97,22 @@ Meteor.startup(function () { case "PENDING": resultSet[name].status = "OK"; report(name, true); - console.log(name, ":", "OK"); + log(name, ":", "OK"); passed++; break; case "EXPECTED": report(name, true); - console.log(name, ":", "EXPECTED FAILURE"); + log(name, ":", "EXPECTED FAILURE"); expected++; break; case "FAIL": failed++; report(name, true); - console.log(name, ":", "!!!!!!!!! FAIL !!!!!!!!!!!"); - console.log(JSON.stringify(resultSet[name].info)); + log(name, ":", "!!!!!!!!! FAIL !!!!!!!!!!!"); + log(JSON.stringify(resultSet[name].info)); break; default: - console.log(name, ": unknown state for the test to be in"); + log(name, ": unknown state for the test to be in"); } finished++; break; @@ -116,12 +125,21 @@ Meteor.startup(function () { }, function () { - console.log("passed/expected/failed/total", passed, "/", expected, "/", failed, "/", _.size(resultSet)); + if (failed > 0) { + log("~~~~~~~ THERE ARE FAILURES ~~~~~~~"); + } + log("passed/expected/failed/total", passed, "/", expected, "/", failed, "/", _.size(resultSet)); sendReports(function () { - console.log("Waiting 3s for any last reports to get sent out"); - setTimeout(function () { + if (doReport) { + log("Waiting 3s for any last reports to get sent out"); + setTimeout(function () { + FAILURES = failed; + DONE = true; + }, 3000); + } else { + FAILURES = failed; DONE = true; - }, 3000); + } }); }, ["tinytest"]); diff --git a/packages/test-in-console/package.js b/packages/test-in-console/package.js index f2c96c5f37..b407dd0e39 100644 --- a/packages/test-in-console/package.js +++ b/packages/test-in-console/package.js @@ -1,12 +1,10 @@ Package.describe({ - summary: "Run tests noninteractively in PhantomJS", + summary: "Run tests noninteractively, with results going to the console.", internal: true }); Package.on_use(function (api) { - // XXX this should go away, and there should be a clean interface - // that tinytest and the driver both implement? api.use('tinytest'); api.use('http'); diff --git a/packages/test-in-console/reporter.js b/packages/test-in-console/reporter.js index b0f02a3c34..93268c33c7 100644 --- a/packages/test-in-console/reporter.js +++ b/packages/test-in-console/reporter.js @@ -1,8 +1,8 @@ var url = null; if (Meteor.settings && Meteor.settings.public && - !_.isEmpty(Meteor.settings.public.runId) && - !_.isEmpty(Meteor.settings.public.reportTo)) { + Meteor.settings.public.runId && + Meteor.settings.public.reportTo) { url = Meteor.settings.public.reportTo + "/report/" + Meteor.settings.public.runId; @@ -10,9 +10,11 @@ if (Meteor.settings && Meteor.methods({ report: function (reports) { - Meteor.http.post(url, { - data: reports - }); + if (url) { + Meteor.http.post(url, { + data: reports + }); + } return null; } }); diff --git a/packages/test-in-console/run.sh b/packages/test-in-console/run.sh index 5ab4f30bdd..ede4415c23 100755 --- a/packages/test-in-console/run.sh +++ b/packages/test-in-console/run.sh @@ -4,28 +4,18 @@ cd `dirname $0` cd ../.. export METEOR_HOME=`pwd` -#eventually this should be the new engine way to run tests -cd $METEOR_HOME/packages - -cat > settings.json <&1 | grep Unreleased || exit 1 # syncronously get the dev bundle if its not there. -cat settings.json -meteor test-packages --driver-package test-in-console --settings=settings.json & +export URL='http://localhost:4096/' + +meteor test-packages --driver-package test-in-console -p 4096 & METEOR_PID=$! sleep 2 -phantomjs ./test-in-console/runner.js $PLATFORM +phantomjs $METEOR_HOME/packages/test-in-console/runner.js +STATUS=$? kill $METEOR_PID -rm settings.json +exit $STATUS diff --git a/packages/test-in-console/runner.js b/packages/test-in-console/runner.js index e10fba0269..e995ec789e 100644 --- a/packages/test-in-console/runner.js +++ b/packages/test-in-console/runner.js @@ -1,16 +1,22 @@ var page = require('webpage').create(); var system = require('system'); -var platform = system.args[1] || ""; -console.log("I am here"); +var platform = system.args[1] || "local"; +console.log("Running Meteor tests in PhantomJS..."); page.onConsoleMessage = function (message) { console.log(message); }; -page.open("http://localhost:3000/" + platform); +page.open(system.env.URL + platform); setInterval(function () { var done = page.evaluate(function () { - return DONE; + return typeof DONE !== 'undefined' && DONE; }); if (done) { - phantom.exit(0); + var failures = page.evaluate(function () { + if (typeof FAILURES === 'undefined') { + return 1; + } + return FAILURES; + }); + phantom.exit(failures ? 1 : 0); } }, 500);