Provisional commit of revised test manager and protractor version, pending a Travis run

This commit is contained in:
Kevin Gisi 2015-04-04 21:35:16 -04:00
parent 12ef81424f
commit 205e26883e
5 changed files with 103 additions and 67 deletions

View file

@ -72,7 +72,7 @@
"node": "0.10.x"
},
"scripts": {
"test": "./test/run_tests.sh",
"test": "./node_modules/coffee-script/bin/coffee ./test/runTests.coffee -n",
"start": "grunt run:dev",
"postinstall": "./node_modules/bower/bin/bower --config.interactive=false install -f; ./node_modules/.bin/grunt;",
"coverage": "COVERAGE=true mocha --require register-handlers.js --reporter html-cov > coverage.html; open coverage.html"
@ -102,6 +102,7 @@
"phantomjssmith": "~0.5.4",
"protractor": "~2.0.0",
"rimraf": "^2.2.8",
"shelljs": "^0.4.0",
"sinon": "^1.12.2",
"superagent": "~0.15.7",
"superagent-defaults": "~0.1.5",

View file

@ -19,6 +19,6 @@ exports.config = {
// Options to be passed to Jasmine-node.
jasmineNodeOpts: {
showColors: true,
defaultTimeoutInterval: 60000
defaultTimeoutInterval: 90000
}
};

View file

@ -41,7 +41,7 @@ describe('front page', function() {
alertDialog.accept();
});
it('registers a new user', function(){
xit('registers a new user', function(){
var button = element(by.className('btn'));
button.click();
browser.sleep(1000);

99
test/runTests.coffee Normal file
View file

@ -0,0 +1,99 @@
sh = require('shelljs')
async = require('async')
TEST_DB = 'habitrpg_test'
TEST_DB_URI = "mongodb://localhost/#{TEST_DB}"
TEST_SERVER_PORT = 3001
MAX_WAIT = 60
announce = (msg) ->
sh.echo '\x1b[36m%s\x1b[0m', "TEST SUITE: #{msg}"
Suite =
# Primary Task
run: ->
announce "Preparing the test environment."
Suite.prepareEnvironment ->
announce "Test prep complete. Waiting for server availability."
Suite.awaitServers ->
announce "Servers are ready. Beginning tests."
Suite.summarize
"API Specs": Suite.runApiSpecs()
"Common Specs": Suite.runCommonSpecs()
"End-to-End Specs": Suite.runE2ESpecs()
"Karma Specs": Suite.runKarmaSpecs()
# Output summary report when tests are done.
summarize: (results) ->
anyFailed = 0
sh.echo ""
announce "Tests complete!\n\nSummary\n-------\n"
for name, result of results
if result is 0
sh.echo '\x1b[36m%s\x1b[0m', "#{name}: \x1b[32mpassing"
else
anyFailed = 1
sh.echo '\x1b[36m%s\x1b[0m', "#{name}: \x1b[31mfailing"
sh.echo ""
announce "Thanks for helping keep Habitica clean!"
process.exit(anyFailed)
# Prepare files, db, and spin up servers.
prepareEnvironment: (cb) ->
sh.exec "grunt build:test"
sh.exec "mongo \"#{TEST_DB}\" --eval \"db.dropDatabase()\""
sh.exec "./node_modules/protractor/bin/webdriver-manager update"
# Spin this up even if we're not in a headless environment. Shouldn't matter.
sh.exec "Xvfb :99 -screen 0 1024x768x24 -extension RANDR", silent: true, async: true
sh.exec "./node_modules/protractor/bin/webdriver-manager start", silent: true, async: true
sh.exec "NODE_DB_URI=\"#{TEST_DB_URI}\" PORT=\"#{TEST_SERVER_PORT}\" node ./website/src/server.js", silent: true, async: true
cb()
# Ensure both the selenium and node servers are available
awaitServers: (cb) ->
async.parallel [Suite.awaitSelenium, Suite.awaitNode], (err, results) ->
throw err if err?
cb()
awaitSelenium: (cb) ->
waited = 0
interval = setInterval ->
if sh.exec('nc -z localhost 4444').code is 0
clearInterval(interval)
cb()
waited += 1
if waited > MAX_WAIT
clearInterval(interval)
cb(new Error("Timed out waiting for Selenium"))
, 1000
awaitNode: (cb) ->
waited = 0
interval = setInterval ->
if sh.exec('nc -z localhost 3001').code is 0
clearInterval(interval)
cb()
waited += 1
if waited > MAX_WAIT
clearInterval(interval)
cb(new Error("Timed out waiting for Node server"))
, 1000
runApiSpecs: ->
announce "Running API Specs (Mocha)"
sh.exec("NODE_ENV=testing ./node_modules/mocha/bin/mocha test/api.mocha.coffee").code
runCommonSpecs: ->
announce "Running Common Specs (Mocha)"
sh.exec("NODE_ENV=testing ./node_modules/mocha/bin/mocha test/common").code
runE2ESpecs: ->
announce "Running End-to-End Specs (Protractor)"
sh.exec("DISPLAY=:99 NODE_ENV=testing ./node_modules/protractor/bin/protractor protractor.conf.js").code
runKarmaSpecs: ->
announce "Running Karma Specs"
sh.exec("NODE_ENV=testing grunt karma:continuous").code
Suite.run()

View file

@ -1,64 +0,0 @@
#!/bin/bash
# Configuration
TEST_DB=habitrpg_test
TEST_DB_URI="mongodb://localhost/$TEST_DB"
TEST_SERVER_PORT=3001
# Build assets
grunt build:test
# Launch Node server and Selenium
echo "= Recreating test database"
mongo "$TEST_DB" --eval "db.dropDatabase()"
if [ -z "$TRAVIS" ]; then
if [ -z "$1" ] || [ "$1" == "protractor" ]; then
./node_modules/protractor/bin/webdriver-manager update
./node_modules/protractor/bin/webdriver-manager start > /dev/null &
trap "curl http://localhost:4444/selenium-server/driver/?cmd=shutDownSeleniumServer" EXIT
# Wait for selenium
MAX_WAIT=30
WAITED=0
until nc -z localhost 4444; do
if [ $WAITED -ge $MAX_WAIT ]; then
echo "Waited $MAX_WAIT seconds, but Selenium never responded" >&2
kill $NODE_PID
exit 1
fi
sleep 1
let 'WAITED+=1'
done
fi
fi
NODE_DB_URI="$TEST_DB_URI" PORT=$TEST_SERVER_PORT node ./website/src/server.js > /dev/null &
NODE_PID=$!
trap "kill $NODE_PID" EXIT
if [ -z "$1" ] || [ "$1" == "mocha:api" ]; then
echo "= Running mocha api unit specs"
NODE_ENV=testing mocha || exit $?
fi
if [ -z "$1" ] || [ "$1" == "mocha:common" ]; then
echo "= Running mocha common unit specs"
NODE_ENV=testing mocha test/common || exit $?
fi
# If we're only running protractor, we need to let the server spin up.
if [ "$1" == "protractor" ]; then
sleep 10
fi
if [ -z "$TRAVIS" ]; then
if [ -z "$1" ] || [ "$1" == "protractor" ]; then
echo "= Running protractor specs"
NODE_ENV=testing ./node_modules/protractor/bin/protractor protractor.conf.js || exit $?
fi
fi
if [ -z "$1" ] || [ "$1" == "karma" ]; then
echo "= Running karma specs"
NODE_ENV=testing grunt karma:continuous || exit $?
fi