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.