Skip to content

Commit

Permalink
Merge pull request JakeChampion#27 from github/test-port
Browse files Browse the repository at this point in the history
Auto-detect available port when running headless tests
  • Loading branch information
mislav committed Oct 30, 2014
2 parents 7668fcc + 79f7495 commit 430d871
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
17 changes: 10 additions & 7 deletions test/run.sh
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
#!/bin/bash
set -e

function stop() {
kill -9 $(<test/server.pid)
rm test/server.pid
}
trap stop EXIT
port=3900

node ./test/server.js & echo "$!" > test/server.pid
# Find next available port
while lsof -i :$((++port)) >/dev/null; do true; done

node ./node_modules/.bin/node-qunit-phantomjs http://localhost:3000/test/test.html
# Spin a test server in the background
node ./test/server.js $port &>/dev/null &
server_pid=$!
trap "kill $server_pid" INT EXIT

node ./node_modules/.bin/node-qunit-phantomjs "http://localhost:$port/test/test.html"
4 changes: 3 additions & 1 deletion test/server.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/usr/bin/env node

var port = Number(process.argv[2] || 3000)

var fs = require('fs')
var http = require('http');
var url = require('url');
Expand Down Expand Up @@ -66,4 +68,4 @@ http.createServer(function(req, res) {
}
});
}
}).listen(3000);
}).listen(port);

0 comments on commit 430d871

Please sign in to comment.