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(cli): add interval arg #147

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
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 start http://127.0.0.1:9000 test2 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