Skip to content

Commit

Permalink
Merge branch 'interval' of github.com:ntkoopman/wait-on into ntkoopma…
Browse files Browse the repository at this point in the history
…n-interval
  • Loading branch information
jeffbski committed Nov 2, 2023
2 parents c830235 + e724137 commit 84e667f
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 3 deletions.
7 changes: 7 additions & 0 deletions bin/usage.txt
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,17 @@ Standard Options:

Maximum time in ms to wait before exiting with failure (1) code,
default Infinity
Use postfix 'ms', 's', 'm' or 'h' to change the unit.

--tcpTimeout

Maximum time in ms for tcp connect, default 300ms
Use postfix 'ms', 's', 'm' or 'h' to change the unit.

--httpTimeout

Maximum time to wait for the HTTP request, default Infinity
Use postfix 'ms', 's', 'm' or 'h' to change the unit.

-v, --verbose

Expand Down
24 changes: 22 additions & 2 deletions bin/wait-on
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ const minimist = require('minimist');
const path = require('path');
const waitOn = require('../');

const interval = ['timeout', 'httpTimeout', 'tcpTimeout'];
const minimistOpts = {
string: ['c', 'd', 'i', 's', 't', 'w', 'httpTimeout', 'tcpTimeout'],
string: ['c', 'd', 'i', 's', 't', 'w'].concat(interval),
boolean: ['h', 'l', 'r', 'v'],
alias: {
c: 'config',
Expand Down Expand Up @@ -55,7 +56,11 @@ if (argv.help || !hasResources) {
'window'
].reduce(function (accum, x) {
if (argv[x]) {
accum[x] = argv[x];
let value = argv[x];
if (interval.includes(x)) {
value = parseInterval(value);
}
accum[x] = value;
}
return accum;
}, configOpts);
Expand All @@ -79,3 +84,18 @@ function errorExit(err) {
}
process.exit(1);
}

function parseInterval(arg) {
const res = /^([\d.]+)(|ms|s|m|h)$/i.exec(arg);
if (!res) {
return arg;
}
const value = parseFloat(res[1]);
switch (res[2]) {
case '':
case 'ms': return Math.floor(value);
case 's': return Math.floor(value * 1000);
case 'm': return Math.floor(value * 1000 * 60);
case 'h': return Math.floor(value * 1000 * 60 * 60);
}
}
2 changes: 1 addition & 1 deletion test/cli.mocha.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ function execCLI(args, options) {
return childProcess.spawn(process.execPath, fullArgs, options);
}

const FAST_OPTS = '-t 1000 -i 100 -w 100'.split(' ');
const FAST_OPTS = '-t 1s -i 100 -w 100'.split(' ');

describe('cli', function () {
this.timeout(3000);
Expand Down

0 comments on commit 84e667f

Please sign in to comment.