Starts server, waits for URL, then runs test command; when the tests end, shuts down server
Requires Node version 6 or above.
npm install --save-dev start-server-and-test
This command is meant to be used with NPM script commands. If you have a "start server", and "test" script names for example, you can start the server, wait for a url to respond, then run tests. When the test process exits, the server is shut down.
To execute all tests simply run
npm run ci
You can use either
start-test commands in your scripts.
You can use
: in front of port number like
server-test :8080, so all these are equivalent
start-server-and-test start http://localhost:8080 test server-test start http://localhost:8080 test server-test http://localhost:8080 test start-test :8080 test start-test 8080 test start-test 8080
If you use convention and name your scripts "start" and "test" you can simply provide URL
You can also shorten local url to just port, the code below is equivalent to checking
You can provide first start command, port (or url) and implicit
You can provide port number and custom test command, in that case
npm start is assumed to start the server.
You can provide multiple resources to wait on, separated by a pipe
|. (be sure to wrap in quotes)
Note for webpack-dev-server users
If you are using webpack-dev-server (directly or via
angular/cli or other boilerplates) then please use the following URL form to check
This is because under the hood this module uses wait-on to ping the server. Wait-on uses
HEAD by default, but
webpack-dev-server does not respond to
HEAD only to
GET requests. Thus you need to use
http-get:// URL format to force
wait-on to use
To see diagnostic messages, run with environment variable
Disable HTTPS certificate checks
To see disable HTTPS checks for
wait-on, run with environment variable
Author: Gleb Bahmutov <email@example.com> © 2017
License: MIT - do anything with the code, but don't blame me if it does not work.
Support: if you find any problems with this module, email / tweet / open issue on Github
Copyright (c) 2017 Gleb Bahmutov <firstname.lastname@example.org>
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.