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: Allow interval option from environment variable #315

Merged
merged 2 commits into from Sep 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Expand Up @@ -279,6 +279,10 @@ To disable HTTPS checks for `wait-on`, run with environment variable `START_SERV

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.

### Interval

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.

### 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
2 changes: 2 additions & 0 deletions package.json
Expand Up @@ -92,6 +92,8 @@
"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-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",
"demo-commands": "node src/bin/start.js 'node test/server.js --port 8800' 8800 'node test/client --port 8800'",
"demo-multiple": "node src/bin/start.js 'node test/server --port 6000' 6000 'node test/server --port 6010' 6010 'curl http://127.0.0.1:6000 && curl http://127.0.0.1:6010'",
Expand Down
8 changes: 7 additions & 1 deletion src/index.js
Expand Up @@ -13,10 +13,16 @@ const debug = require('debug')('start-server-and-test')
* Used for timeout (ms)
*/
const fiveMinutes = 5 * 60 * 1000
const twoSeconds = 2000

const waitOnTimeout = process.env.WAIT_ON_TIMEOUT
? Number(process.env.WAIT_ON_TIMEOUT)
: fiveMinutes

const waitOnInterval = process.env.WAIT_ON_INTERVAL
? Number(process.env.WAIT_ON_INTERVAL)
: twoSeconds

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

Expand Down Expand Up @@ -74,7 +80,7 @@ function waitAndRun ({ start, url, runFn }) {
debug('starting waitOn %s', url)
const options = {
resources: Array.isArray(url) ? url : [url],
interval: 2000,
interval: waitOnInterval,
window: 1000,
timeout: waitOnTimeout,
verbose: isDebug(),
Expand Down
8 changes: 8 additions & 0 deletions src/utils.js
Expand Up @@ -199,6 +199,14 @@ function printArguments ({ services, test }) {
)
})

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

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

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