Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,10 @@ This utility will wait for maximum of 5 minutes while checking for the server to

This utility will check for a server response every two seconds (default). Setting an environment variable `WAIT_ON_INTERVAL=600000` (milliseconds) sets the interval for example to 10 minutes.

### Delay

This utility will delay the initial scheduler request (default behavior is equivalent to WAIT_ON_INTERVAL). Setting an environment variable `WAIT_ON_DELAY=5000` (milliseconds) sets the intial delay for 5 seconds otherwise it will be the default WAIT_ON_INTERVAL.

### Starting two servers

Sometimes you need to start one API server and one webserver in order to test the application. Use the syntax:
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@
"demo10": "node src/bin/start.js start-fail http://127.0.0.1:9000 test",
"demo11": "node src/bin/start.js http-get://127.0.0.1:9000",
"demo12": "node src/bin/start.js start-304 9000 test2",
"demo-delay-interval": "WAIT_ON_DELAY=1000 WAIT_ON_INTERVAL=5000 node src/bin/start.js start http://127.0.0.1:9000 test2",
"demo-interval": "WAIT_ON_INTERVAL=1000 node src/bin/start.js start http://127.0.0.1:9000 test2",
"demo-timeout": "WAIT_ON_TIMEOUT=10000 node src/bin/start.js start http://127.0.0.1:9000 test2",
"demo-cross-env": "node src/bin/start.js start-cross-env 9000",
Expand Down
6 changes: 6 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const debug = require('debug')('start-server-and-test')
*/
const fiveMinutes = 5 * 60 * 1000
const twoSeconds = 2000
const zeroMseconds = 0

const waitOnTimeout = process.env.WAIT_ON_TIMEOUT
? Number(process.env.WAIT_ON_TIMEOUT)
Expand All @@ -23,6 +24,10 @@ const waitOnInterval = process.env.WAIT_ON_INTERVAL
? Number(process.env.WAIT_ON_INTERVAL)
: twoSeconds

const waitOnDelay = process.env.WAIT_ON_DELAY
? Number(process.env.WAIT_ON_DELAY)
: zeroMseconds

const isDebug = () =>
process.env.DEBUG && process.env.DEBUG.indexOf('start-server-and-test') !== -1

Expand Down Expand Up @@ -81,6 +86,7 @@ function waitAndRun ({ start, url, runFn }) {
const options = {
resources: Array.isArray(url) ? url : [url],
interval: waitOnInterval,
delay: waitOnDelay,
window: 1000,
timeout: waitOnTimeout,
verbose: isDebug(),
Expand Down
4 changes: 4 additions & 0 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,10 @@ function printArguments ({ services, test }) {
console.log('WAIT_ON_TIMEOUT is set to', process.env.WAIT_ON_TIMEOUT)
}

if (process.env.WAIT_ON_DELAY !== undefined) {
console.log('WAIT_ON_DELAY is set to', process.env.WAIT_ON_DELAY)
}

console.log('running tests using command "%s"', test)
console.log('')
}
Expand Down