forked from JakeChampion/fetch
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto-detect available port when running headless tests
By default the test server tried to run on port 3000, which would fail with a misleading message if something else happened to occupy that port on the system (such as a Rails app). Now start incrementing the port number from 3900 and stop when the port is found to be available.
- Loading branch information
Showing
2 changed files
with
13 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters