All Projects β†’ bahmutov β†’ Start Server And Test

bahmutov / Start Server And Test

Starts server, waits for URL, then runs test command; when the tests end, shuts down server

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Start Server And Test

Backslide
πŸ’¦ CLI tool for making HTML presentations with Remark.js using Markdown
Stars: ✭ 679 (-22.75%)
Mutual labels:  utility, cli, server
Jql
A JSON Query Language CLI tool
Stars: ✭ 368 (-58.13%)
Mutual labels:  utility, cli
Haxor News
Browse Hacker News like a haxor: A Hacker News command line interface (CLI).
Stars: ✭ 3,342 (+280.2%)
Mutual labels:  utility, cli
Nve
Run any command on specific Node.js versions
Stars: ✭ 531 (-39.59%)
Mutual labels:  cli, server
Study
A simple, progressive, client/server AB testing library πŸ“š
Stars: ✭ 293 (-66.67%)
Mutual labels:  server, test
Markserv
🏁 serve markdown as html (GitHub style), index directories, live-reload as you edit
Stars: ✭ 304 (-65.42%)
Mutual labels:  cli, server
Saws
A supercharged AWS command line interface (CLI).
Stars: ✭ 4,886 (+455.86%)
Mutual labels:  utility, cli
UnitySettings
Runtime debugging menu (like setting on Android) for Unity.
Stars: ✭ 26 (-97.04%)
Mutual labels:  utility, test
Shell2http
Executing shell commands via HTTP server
Stars: ✭ 719 (-18.2%)
Mutual labels:  cli, server
Executor
Watch for file changes and then execute command. Very nice for test driven development.
Stars: ✭ 14 (-98.41%)
Mutual labels:  utility, cli
Supervizer
NodeJS Application Manager
Stars: ✭ 278 (-68.37%)
Mutual labels:  cli, server
Aruba
Test command-line applications with Cucumber-Ruby, RSpec or Minitest. The most up to date documentation can be found on Cucumber.Pro (https://app.cucumber.pro/projects/aruba)
Stars: ✭ 900 (+2.39%)
Mutual labels:  cli, test
cypress-angularjs-unit-test
Unit test Angularjs code using Cypress.io test runner
Stars: ✭ 23 (-97.38%)
Mutual labels:  utility, test
Javatech
β˜•οΈ 汇总 Java εΌ€ε‘δΈ­εΈΈθ§ηš„δΈ»ζ΅ζŠ€ζœ―ηš„εΊ”η”¨γ€η‰Ήζ€§γ€εŽŸη†γ€‚
Stars: ✭ 310 (-64.73%)
Mutual labels:  server, test
laika
Log, test, intercept and modify Apollo Client's operations
Stars: ✭ 99 (-88.74%)
Mutual labels:  utility, test
Remarshal
Convert between CBOR, JSON, MessagePack, TOML, and YAML
Stars: ✭ 421 (-52.1%)
Mutual labels:  utility, cli
Laravel Zero
A PHP framework for console artisans
Stars: ✭ 2,821 (+220.93%)
Mutual labels:  utility, cli
Musoq
Use SQL on various data sources
Stars: ✭ 252 (-71.33%)
Mutual labels:  utility, cli
Ponzu
Headless CMS with automatic JSON API. Featuring auto-HTTPS from Let's Encrypt, HTTP/2 Server Push, and flexible server framework written in Go.
Stars: ✭ 5,373 (+511.26%)
Mutual labels:  cli, server
Git Repo
Git-Repo: CLI utility to manage git services from your workspace
Stars: ✭ 818 (-6.94%)
Mutual labels:  utility, cli

start-server-and-test

Starts server, waits for URL, then runs test command; when the tests end, shuts down server

NPM

Build status semantic-release js-standard-style renovate-app badge

Install

Requires Node version 8.9 or above.

npm install --save-dev start-server-and-test

Use

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.

Commands

In addition to using NPM script names, you can pass entire commands (surround them with quotes so it is still a single string) that will be executed "as is". For example, to start globally installed http-server before running and recording Cypress.io tests you can use

# run http-server, then when port 8000 responds run Cypress tests
start-server-and-test 'http-server -c-1 --silent' 8000 './node_modules/.bin/cypress run --record'

Because npm scripts execute with ./node_modules/.bin in the $PATH, you can mix global and locally installed tools when using commands inside package.json file. For example, if you want to run a single spec file:

{
  "scripts": {
    "ci": "start-server-and-test 'http-server -c-1 --silent' 8080 'cypress run --spec cypress/integration/location.spec.js'"
  }
}

Or you can move http-server part into its own start script, which is used by default and have the equivalent JSON

{
  "scripts": {
    "start": "http-server -c-1 --silent",
    "ci": "start-server-and-test 8080 'cypress run --spec cypress/integration/location.spec.js'"
  }
}

Here is another example that uses Mocha

{
  "scripts": {
    "ci": "start-server-and-test 'http-server -c-1 --silent' 8080 'mocha e2e-spec.js'"
  }
}

Alias

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

Options

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\""
  }
}

or for multiple ports simply: server-test '8000|9000' test.

npx and yarn

If you have npx available, you can execute locally installed tools from the shell. For example, if the package.json has the following local tools:

{
  "devDependencies": {
    "cypress": "3.2.0",
    "http-server": "0.11.1",
    "start-server-and-test": "1.9.0"
  }
}

Then you can execute tests simply:

$ npx start-test 'http-server -c-1 .' 8080 'cypress run'
starting server using command "http-server -c-1 ."
and when url "http://localhost:8080" is responding
running tests using command "cypress run"
Starting up http-server, serving .
...

Similarly, you can use yarn to call locally installed tools

$ yarn start-test 'http-server -c-1 .' 8080 'cypress run'
yarn run v1.13.0
$ /private/tmp/test-t/node_modules/.bin/start-test 'http-server -c-1 .' 8080 'cypress run'
starting server using command "http-server -c-1 ."
and when url "http://localhost:8080" is responding
running tests using command "cypress run"
Starting up http-server, serving .
...

Note for yarn users

By default, npm is used to run scripts, however you can specify that yarn is used as follows:

"scripts": {
    "start-server": "yarn start",
    "test": "mocha e2e-spec.js",
    "ci": "start-server-and-test 'yarn start-server' http://localhost:8080 'yarn test'"
}

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

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

Debugging

To see diagnostic messages, run with environment variable DEBUG=start-server-and-test

Disable HTTPS certificate checks

To see disable HTTPS checks for wait-on, run with environment variable START_SERVER_AND_TEST_INSECURE=1.

Timeout

This utility will wait for maximum of 5 minutes while checking for the server to respond (default). Setting an environment variable WAIT_ON_TIMEOUT=600000 (milliseconds) sets the timeout for example to 10 minutes.

Starting two servers

Sometimes you need to start one API server and one webserver in order to test the application. Use the syntax:

start-test <first command> <first resource> <second command> <second resource> <test command>

For example if API runs at port 3000 and server runs at port 8080:

{
  "scripts": {
    "test": "node src/test",
    "start:api": "node src/api",
    "start:server": "node src/server",
    "test:all": "start-test start:api 3000 start:server 8080 test"
  }
}

In the above example you would run npm run test:all to start the API first, then when it responds, start the server, and when the server is responding, it would run the tests. After the tests finish, it will shut down both servers. See the repo start-two-servers-example for full example

Small print

Author: Gleb Bahmutov <[email protected]> Β© 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

MIT License

Copyright (c) 2017 Gleb Bahmutov <[email protected]>

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.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].