Security News
RubyGems.org Adds New Maintainer Role
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
start-server-and-test
Advanced tools
Starts server, waits for URL, then runs test command; when the tests end, shuts down server
The start-server-and-test npm package is designed to simplify the process of starting a server, running tests, and then shutting down the server. It is particularly useful in continuous integration environments where you need to ensure that the server starts successfully before tests are executed and is properly shut down afterward. This package helps automate these steps by providing a single command that handles the entire process.
Start server, run tests, and stop server
This feature allows you to start your server using a start command (e.g., 'npm run start'), wait for the server to be accessible on a specified URL (e.g., http://localhost:3000), and then run tests using a test command (e.g., 'npm run test'). After the tests are completed, the server is automatically stopped.
start-server-and-test 'npm run start' http://localhost:3000 'npm run test'
Concurrently is a package that allows you to run multiple commands concurrently. Unlike start-server-and-test, it does not specifically manage the lifecycle of starting a server, running tests, and then stopping the server, but it can be used to achieve similar functionality with custom scripts.
Forever is a simple CLI tool for ensuring that a given script runs continuously (i.e., forever). It is different from start-server-and-test as it focuses on keeping a script running rather than managing the start-test-stop cycle, but it can be used in combination with other tools to achieve similar end results.
PM2 is a powerful, production process manager for Node.js applications with a built-in load balancer. It is more complex and feature-rich compared to start-server-and-test, which is specifically focused on integration testing environments rather than full application management.
Starts server, waits for URL, then runs test command; when the tests end, shuts down server
Requires Node version 8.9 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.
{
"scripts": {
"start-server": "npm start",
"test": "mocha e2e-spec.js",
"ci": "start-server-and-test start-server http://localhost:8080 test"
}
}
To execute all tests simply run npm run ci
You can use either start-server-and-test
, server-test
or 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
{
"scripts": {
"start": "npm start",
"test": "mocha e2e-spec.js",
"ci": "start-server-and-test http://localhost:8080"
}
}
You can also shorten local url to just port, the code below is equivalent to checking http://localhost:8080
.
{
"scripts": {
"start": "npm start",
"test": "mocha e2e-spec.js",
"ci": "server-test 8080"
}
}
You can provide first start command, port (or url) and implicit test
command
{
"scripts": {
"start-it": "npm start",
"test": "mocha e2e-spec.js",
"ci": "server-test start-it 8080"
}
}
You can provide port number and custom test command, in that case npm start
is assumed to start the server.
{
"scripts": {
"start": "npm start",
"test-it": "mocha e2e-spec.js",
"ci": "server-test :9000 test-it"
}
}
You can provide multiple resources to wait on, separated by a pipe |
. (be sure to wrap in quotes)
{
"scripts": {
"start": "npm start",
"test-it": "mocha e2e-spec.js",
"ci": "server-test \"8080|http://foo.com\""
}
}
If you are using webpack-dev-server (directly or via angular/cli
or other boilerplates) then please use the following URL form to check
start-server-and-test http-get://localhost:8080
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 GET
probe.
You can even wait on the bundle JavaScript url instead of the page url, see discussion in this issue #4
To see diagnostic messages, run with environment variable DEBUG=start-server-and-test
To see disable HTTPS checks for wait-on
, run with environment variable START_SERVER_AND_TEST_INSECURE=1
.
Sometimes you need to start one API server and one webserver in order to test the application. Just have two commands cascade. First command should wait on the webserver script, which in turn uses start-server-and-test
to start the API server before running the webserver. Something like this
{
"scripts": {
"test": "node src/test",
"start:api": "node src/api",
"start:server": "node src/server",
"start:server-and-api": "start-test start:api 7600 start:server",
"test:all": "start-test start:server-and-api 5000 test"
}
}
In the above example you would run npm run test:all
to start both servers and run the test. See repo start-two-servers-example for full example
Author: Gleb Bahmutov <gleb.bahmutov@gmail.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 <gleb.bahmutov@gmail.com>
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.
FAQs
Starts server, waits for URL, then runs test command; when the tests end, shuts down server
The npm package start-server-and-test receives a total of 524,070 weekly downloads. As such, start-server-and-test popularity was classified as popular.
We found that start-server-and-test demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.
Security News
Research
Socket's threat research team has detected five malicious npm packages targeting Roblox developers, deploying malware to steal credentials and personal data.