Skip to content

Commit 693dc2c

Browse files
authoredSep 2, 2021
FEAT: Allow interval option from environment variable (#315)
* Allow interval option from environment variable * feat(test): add new demo for testing, update README
1 parent 7ac144f commit 693dc2c

File tree

4 files changed

+21
-1
lines changed

4 files changed

+21
-1
lines changed
 

‎README.md

+4
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,10 @@ To disable HTTPS checks for `wait-on`, run with environment variable `START_SERV
279279

280280
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.
281281

282+
### Interval
283+
284+
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.
285+
282286
### Starting two servers
283287

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

‎package.json

+2
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,8 @@
9292
"demo10": "node src/bin/start.js start-fail http://127.0.0.1:9000 test",
9393
"demo11": "node src/bin/start.js http-get://127.0.0.1:9000",
9494
"demo12": "node src/bin/start.js start-304 9000 test2",
95+
"demo-interval": "WAIT_ON_INTERVAL=1000 node src/bin/start.js start http://127.0.0.1:9000 test2",
96+
"demo-timeout": "WAIT_ON_TIMEOUT=10000 node src/bin/start.js start http://127.0.0.1:9000 test2",
9597
"demo-cross-env": "node src/bin/start.js start-cross-env 9000",
9698
"demo-commands": "node src/bin/start.js 'node test/server.js --port 8800' 8800 'node test/client --port 8800'",
9799
"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'",

‎src/index.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,16 @@ const debug = require('debug')('start-server-and-test')
1313
* Used for timeout (ms)
1414
*/
1515
const fiveMinutes = 5 * 60 * 1000
16+
const twoSeconds = 2000
17+
1618
const waitOnTimeout = process.env.WAIT_ON_TIMEOUT
1719
? Number(process.env.WAIT_ON_TIMEOUT)
1820
: fiveMinutes
1921

22+
const waitOnInterval = process.env.WAIT_ON_INTERVAL
23+
? Number(process.env.WAIT_ON_INTERVAL)
24+
: twoSeconds
25+
2026
const isDebug = () =>
2127
process.env.DEBUG && process.env.DEBUG.indexOf('start-server-and-test') !== -1
2228

@@ -74,7 +80,7 @@ function waitAndRun ({ start, url, runFn }) {
7480
debug('starting waitOn %s', url)
7581
const options = {
7682
resources: Array.isArray(url) ? url : [url],
77-
interval: 2000,
83+
interval: waitOnInterval,
7884
window: 1000,
7985
timeout: waitOnTimeout,
8086
verbose: isDebug(),

‎src/utils.js

+8
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,14 @@ function printArguments ({ services, test }) {
199199
)
200200
})
201201

202+
if (process.env.WAIT_ON_INTERVAL !== undefined) {
203+
console.log('WAIT_ON_INTERVAL is set to', process.env.WAIT_ON_INTERVAL)
204+
}
205+
206+
if (process.env.WAIT_ON_TIMEOUT !== undefined) {
207+
console.log('WAIT_ON_TIMEOUT is set to', process.env.WAIT_ON_TIMEOUT)
208+
}
209+
202210
console.log('running tests using command "%s"', test)
203211
console.log('')
204212
}

0 commit comments

Comments
 (0)
Please sign in to comment.