Skip to content

Commit

Permalink
feat(cli): add interval arg
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas Triau committed Jan 21, 2019
1 parent 5b2b9e4 commit ee8ae74
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 5 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ script:
- npm run demo6
- npm run demo7
- START_SERVER_AND_TEST_INSECURE=1 npm run demo9
- npm run demo11
- npm run demo-cross-env
after_success:
- npm run travis-deploy-once "npm run semantic-release"
Expand Down
15 changes: 12 additions & 3 deletions bin/start.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const utils = require('../src/utils')
let start = 'start'
let test = 'test'
let url
let interval = 2000

if (args.length === 1 && utils.isUrlOrPort(args[0])) {
// passed just single url or port number, for example
Expand All @@ -26,18 +27,26 @@ if (args.length === 1 && utils.isUrlOrPort(args[0])) {
start = args[0]
url = utils.normalizeUrl(args[1])
}
} else {
la(args.length === 3, 'expect: <start script name> <url> <test script name>')
} else if (args.length <= 4) {
start = args[0]
url = utils.normalizeUrl(args[1])
test = args[2]

if (args.length === 4) {
interval = args[3]
}
} else {
la(
false,
'expect: <start script name> <url> <test script name> <interval optional number>'
)
}

console.log(`starting server using command "npm run ${start}"`)
console.log(`and when url "${url}" is responding`)
console.log(`running tests using command "${test}"`)

startAndTest({ start, url, test }).catch(e => {
startAndTest({ start, url, test, interval }).catch(e => {
console.error(e)
process.exit(1)
})
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@
"demo8": "node bin/start.js start-multiple \":9000|:9001\" test3",
"demo9": "node bin/start.js start-https \"https://127.0.0.1:9000\" test4",
"demo10": "node bin/start.js start-fail http://127.0.0.1:9000 test",
"demo11": "node bin/start.js http://127.0.0.1:9000 1000",
"demo-cross-env": "node bin/start.js start-cross-env 9000",
"travis-deploy-once": "travis-deploy-once"
},
Expand Down
4 changes: 2 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const isDebug = () =>

const isInsecure = () => process.env.START_SERVER_AND_TEST_INSECURE

function startAndTest ({ start, url, test }) {
function startAndTest ({ start, url, test, interval }) {
la(is.unemptyString(start), 'missing start script name', start)
la(is.unemptyString(test), 'missing test script name', test)
la(
Expand Down Expand Up @@ -66,7 +66,7 @@ function startAndTest ({ start, url, test }) {
waitOn(
{
resources: Array.isArray(url) ? url : [url],
interval: 2000,
interval: interval,
window: 1000,
verbose: isDebug(),
strictSSL: !isInsecure(),
Expand Down

0 comments on commit ee8ae74

Please sign in to comment.