Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: start and wait for multiple services 248 #249

Merged
merged 14 commits into from Apr 14, 2020
3 changes: 2 additions & 1 deletion .travis.yml
Expand Up @@ -5,7 +5,7 @@ cache:
notifications:
email: true
node_js:
- '8'
- '12'
script:
- npm test
- npm run demo
Expand All @@ -20,6 +20,7 @@ script:
- START_SERVER_AND_TEST_INSECURE=1 npm run demo9
- npm run demo-cross-env
- npm run demo-commands
- npm run demo-multiple
after_success:
- npm run travis-deploy-once "npm run semantic-release"
branches:
Expand Down
13 changes: 9 additions & 4 deletions README.md
Expand Up @@ -216,21 +216,26 @@ This utility will wait for maximum of 5 minutes while checking for the server to

### Starting two servers

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
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:

```json
{
"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"
"test:all": "start-test start:api 3000 start:server 8080 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](https://github.com/bahmutov/start-two-servers-example) for full example
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](https://github.com/bahmutov/start-two-servers-example) for full example

### Small print

Expand Down
157 changes: 127 additions & 30 deletions __snapshots__/utils-spec.js
@@ -1,73 +1,170 @@
exports['utils getArguments allows 5 arguments 1'] = {
"args": [
"start",
"6000",
"start:web",
"6010",
"test"
],
"parsed": {
"services": [
{
"start": "npm run start",
"url": [
"http://localhost:6000"
]
},
{
"start": "start:web",
"url": [
"http://localhost:6010"
]
}
],
"test": "npm run test"
}
}

exports['utils getArguments determines NPM script for each command 1'] = {
"args": [
"startA",
"6000",
"startB",
"6010",
"testC"
],
"parsed": {
"services": [
{
"start": "npm run startA",
"url": [
"http://localhost:6000"
]
},
{
"start": "npm run startB",
"url": [
"http://localhost:6010"
]
}
],
"test": "npm run testC"
}
}

exports['utils getArguments handles 3 arguments with http-get url 1'] = {
"start": "npm run start",
"url": [
"http-get://localhost:8080"
"services": [
{
"start": "npm run start",
"url": [
"http-get://localhost:8080"
]
}
],
"test": "npm run test"
}

exports['utils getArguments returns 3 arguments 1'] = {
"start": "npm run start",
"url": [
"http://localhost:8080"
"args": [
"start",
"8080",
"test"
],
"test": "npm run test"
"parsed": {
"services": [
{
"start": "npm run start",
"url": [
"http://localhost:8080"
]
}
],
"test": "npm run test"
}
}

exports['utils getArguments returns 3 arguments with url 1'] = {
"start": "npm run start",
"url": [
"http://localhost:8080"
"services": [
{
"start": "npm run start",
"url": [
"http://localhost:8080"
]
}
],
"test": "npm run test"
}

exports['utils getArguments understands custom commands 1'] = {
"start": "custom-command --with argument",
"url": [
"http://localhost:3000"
"services": [
{
"start": "custom-command --with argument",
"url": [
"http://localhost:3000"
]
}
],
"test": "test-command --x=1"
}

exports['utils getArguments understands several ports 1'] = {
"start": "npm run start",
"url": [
"http://localhost:3000",
"http://localhost:4000",
"http://localhost:5000"
"services": [
{
"start": "npm run start",
"url": [
"http://localhost:3000",
"http://localhost:4000",
"http://localhost:5000"
]
}
],
"test": "npm run test"
}

exports['utils getArguments understands single :port 1'] = {
"start": "npm run start",
"url": [
"http://localhost:3000"
"services": [
{
"start": "npm run start",
"url": [
"http://localhost:3000"
]
}
],
"test": "npm run test"
}

exports['utils getArguments understands single port 1'] = {
"start": "npm run start",
"url": [
"http://localhost:3000"
"services": [
{
"start": "npm run start",
"url": [
"http://localhost:3000"
]
}
],
"test": "npm run test"
}

exports['utils getArguments understands start plus url 1'] = {
"start": "start-server",
"url": [
"http://localhost:6000"
"services": [
{
"start": "start-server",
"url": [
"http://localhost:6000"
]
}
],
"test": "npm run test"
}

exports['utils getArguments understands url plus test 1'] = {
"start": "npm run start",
"url": [
"http://localhost:6000"
"services": [
{
"start": "npm run start",
"url": [
"http://localhost:6000"
]
}
],
"test": "npm run test"
}