From 00bbd66dea5ee0120ebc20f62919685377bfe664 Mon Sep 17 00:00:00 2001 From: Michael Merrill Date: Tue, 15 Dec 2020 11:11:15 -0700 Subject: [PATCH 1/5] Allow for resources to be passed via config --- bin/wait-on | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/bin/wait-on b/bin/wait-on index 54d4758..54e7e8d 100755 --- a/bin/wait-on +++ b/bin/wait-on @@ -40,8 +40,10 @@ if (argv.help || !argv._.length) { opts = require(path.resolve(configFile)); } - // add in the resources listed on the command line - opts.resources = argv._; + // add in the resources listed on the command line (if not present in config) + if (!opts.resources) { + opts.resources = argv._; + } // now check for specific options and set those opts = [ From 4d94e7466c8887ada0c5877cfe5e688063624e22 Mon Sep 17 00:00:00 2001 From: Michael Merrill Date: Tue, 15 Dec 2020 11:28:10 -0700 Subject: [PATCH 2/5] remove argv length check --- bin/wait-on | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/wait-on b/bin/wait-on index 54e7e8d..a164f54 100755 --- a/bin/wait-on +++ b/bin/wait-on @@ -24,7 +24,7 @@ var minimistOpts = { var argv = minimist(process.argv.slice(2), minimistOpts); -if (argv.help || !argv._.length) { +if (argv.help) { // help fs.createReadStream(path.join(__dirname, '/usage.txt')) .pipe(process.stdout) From 7e9618de1232ddfc6e7517ad0f48364424353cd8 Mon Sep 17 00:00:00 2001 From: Jeff Barczewski Date: Mon, 28 Dec 2020 10:31:04 -0600 Subject: [PATCH 3/5] allow resources to be specified in config If resources are not specified on the command line then if they are available in the config they will be used as default resources. Resources specified on the command line will override any defined in the config file, thus those in the config file are ignored. --- README.md | 1 + bin/wait-on | 20 ++++++++----------- exampleConfig.js | 6 ++++-- test/cli.mocha.js | 36 +++++++++++++++++++++++++++++++++++ test/config-http-resources.js | 3 +++ 5 files changed, 52 insertions(+), 14 deletions(-) create mode 100644 test/config-http-resources.js diff --git a/README.md b/README.md index b2728ee..d41c8c2 100644 --- a/README.md +++ b/README.md @@ -232,6 +232,7 @@ waitOn(opts, [cb]) - function which triggers resource checks - opts.delay - optional initial delay in ms, default 0 - opts.interval - optional poll resource interval in ms, default 250ms - opts.log - optional flag which outputs to stdout, remaining resources waited on and when complete or errored +- opts.resources - optional array of string resources to wait for if none are specified via command line - opts.reverse - optional flag to reverse operation so checks are for resources being NOT available, default false - opts.simultaneous - optional count to limit concurrent connections per resource at a time, setting to 1 waits for previous connection to succeed, fail, or timeout before sending another, default infinity - opts.timeout - optional timeout in ms, default Infinity. Aborts with error. diff --git a/bin/wait-on b/bin/wait-on index 32ea212..c0ad7ee 100755 --- a/bin/wait-on +++ b/bin/wait-on @@ -23,8 +23,11 @@ const minimistOpts = { }; const argv = minimist(process.argv.slice(2), minimistOpts); +// if a js/json configuration file is provided require it +const configOpts = argv.config ? require(path.resolve(argv.config)) : {}; +const hasResources = argv._.length || (configOpts.resources && configOpts.resources.length); -if (argv.help) { +if (argv.help || !hasResources) { // help fs.createReadStream(path.join(__dirname, '/usage.txt')) .pipe(process.stdout) @@ -32,17 +35,10 @@ if (argv.help) { process.exit(1); }); } else { - let opts = {}; - - // if a js/json configuration file is provided require it - const configFile = argv.config; - if (configFile) { - opts = require(path.resolve(configFile)); - } - - // add in the resources listed on the command line (if not present in config) - if (!opts.resources) { - opts.resources = argv._; + // if resources are present in the command line then they take + // precedence over those in the config file. + if (argv._.length) { + configOpts.resources = argv._; } // now check for specific options and set those diff --git a/exampleConfig.js b/exampleConfig.js index 924d257..c0f7020 100644 --- a/exampleConfig.js +++ b/exampleConfig.js @@ -13,11 +13,13 @@ module.exports = { passphrase: 'yourpassphrase', auth: { user: 'yourusername', - pass: 'yourpassword', + pass: 'yourpassword' }, strictSSL: false, followRedirect: false, headers: { - 'x-custom': 'headers', + 'x-custom': 'headers' }, + // optional default resources if not specified in command args + resources: ['http://foo/bar', 'http://cat/dog'] }; diff --git a/test/cli.mocha.js b/test/cli.mocha.js index b327438..06a7e4b 100644 --- a/test/cli.mocha.js +++ b/test/cli.mocha.js @@ -533,4 +533,40 @@ describe('cli', function () { done(); }); }); + + context('resources are specified in config', () => { + it('should succeed when http resources become available later', function (done) { + setTimeout(function () { + httpServer = http.createServer().on('request', function (req, res) { + res.end('data'); + }); + httpServer.listen(8123, 'localhost'); + }, 300); + + execCLI(['--config', path.join(__dirname, 'config-http-resources.js')].concat(FAST_OPTS), {}).on( + 'exit', + function (code) { + expect(code).toBe(0); + done(); + } + ); + }); + + it('should succeed when http resources from command line become available later (ignores config resources)', function (done) { + setTimeout(function () { + httpServer = http.createServer().on('request', function (req, res) { + res.end('data'); + }); + httpServer.listen(3030, 'localhost'); + }, 300); + + execCLI( + ['--config', path.join(__dirname, 'config-http-resources.js'), 'http://localhost:3030/'].concat(FAST_OPTS), + {} + ).on('exit', function (code) { + expect(code).toBe(0); + done(); + }); + }); + }); }); diff --git a/test/config-http-resources.js b/test/config-http-resources.js new file mode 100644 index 0000000..9266535 --- /dev/null +++ b/test/config-http-resources.js @@ -0,0 +1,3 @@ +module.exports = { + resources: ['http://localhost:8123', 'http://localhost:8123/foo'], +}; From 211b0aed9ca1b839a058a95a6184a172a8f7e180 Mon Sep 17 00:00:00 2001 From: Jeff Barczewski Date: Mon, 28 Dec 2020 10:32:00 -0600 Subject: [PATCH 4/5] formatting --- .prettierrc.js | 6 ++++ bin/wait-on | 10 +++---- lib/wait-on.js | 26 ++++++++++------- test/api.mocha.js | 74 +++++++++++++++++++++++------------------------ test/cli.mocha.js | 52 ++++++++++++++++----------------- 5 files changed, 89 insertions(+), 79 deletions(-) create mode 100644 .prettierrc.js diff --git a/.prettierrc.js b/.prettierrc.js new file mode 100644 index 0000000..9851b79 --- /dev/null +++ b/.prettierrc.js @@ -0,0 +1,6 @@ +module.exports = { + tabWidth: 2, + singleQuote: true, + printWidth: 120, + trailingComma: 'none', +}; diff --git a/bin/wait-on b/bin/wait-on index c0ad7ee..0670fba 100755 --- a/bin/wait-on +++ b/bin/wait-on @@ -18,8 +18,8 @@ const minimistOpts = { t: 'timeout', v: 'verbose', w: 'window', - h: 'help', - }, + h: 'help' + } }; const argv = minimist(process.argv.slice(2), minimistOpts); @@ -42,7 +42,7 @@ if (argv.help || !hasResources) { } // now check for specific options and set those - opts = [ + const opts = [ 'delay', 'httpTimeout', 'interval', @@ -52,13 +52,13 @@ if (argv.help || !hasResources) { 'timeout', 'tcpTimeout', 'verbose', - 'window', + 'window' ].reduce(function (accum, x) { if (argv[x]) { accum[x] = argv[x]; } return accum; - }, opts); + }, configOpts); waitOn(opts, function (err) { if (err) { diff --git a/lib/wait-on.js b/lib/wait-on.js index 14de64b..43f5ab8 100644 --- a/lib/wait-on.js +++ b/lib/wait-on.js @@ -46,11 +46,11 @@ const WAIT_ON_SCHEMA = Joi.object({ proxy: [Joi.boolean(), Joi.object()], auth: Joi.object({ username: Joi.string(), - password: Joi.string(), + password: Joi.string() }), strictSSL: Joi.boolean().default(false), followRedirect: Joi.boolean().default(true), // HTTP 3XX responses - headers: Joi.object(), + headers: Joi.object() }); /** @@ -112,7 +112,7 @@ function waitOnImpl(opts, cbFunc) { ...validResult.value, // use defaults // window needs to be at least interval ...(validResult.value.window < validResult.value.interval ? { window: validResult.value.interval } : {}), - ...(validResult.value.verbose ? { log: true } : {}), // if debug logging then normal log is also enabled + ...(validResult.value.verbose ? { log: true } : {}) // if debug logging then normal log is also enabled }; const { resources, log: shouldLog, timeout, verbose, reverse } = validatedOpts; @@ -125,10 +125,14 @@ function waitOnImpl(opts, cbFunc) { let lastResourcesState = resources; // the last state we had recorded const timeoutError$ = - timeout !== Infinity ? timer(timeout).pipe(mergeMap(() => { - const resourcesWaitingFor = determineRemainingResources(resources, lastResourcesState).join(', ') - return throwError(Error(`${TIMEOUT_ERR_MSG}: ${resourcesWaitingFor}`)) - })) : NEVER; + timeout !== Infinity + ? timer(timeout).pipe( + mergeMap(() => { + const resourcesWaitingFor = determineRemainingResources(resources, lastResourcesState).join(', '); + return throwError(Error(`${TIMEOUT_ERR_MSG}: ${resourcesWaitingFor}`)); + }) + ) + : NEVER; function cleanup(err) { if (err) { @@ -159,7 +163,7 @@ function waitOnImpl(opts, cbFunc) { logWaitingForWDeps(resourceStates); }, error: cleanup, - complete: cleanup, + complete: cleanup }); } @@ -270,7 +274,7 @@ function createHTTP$({ validatedOpts, output }, resource) { proxy, reverse, simultaneous, - strictSSL: rejectUnauthorized, + strictSSL: rejectUnauthorized } = validatedOpts; const method = HTTP_GET_RE.test(resource) ? 'get' : 'head'; const url = resource.replace('-get:', ':'); @@ -283,13 +287,13 @@ function createHTTP$({ validatedOpts, output }, resource) { ...pick(['auth', 'headers', 'validateStatus'], validatedOpts), httpsAgent: new https.Agent({ rejectUnauthorized, - ...pick(['ca', 'cert', 'key', 'passphrase'], validatedOpts), + ...pick(['ca', 'cert', 'key', 'passphrase'], validatedOpts) }), ...(followRedirect ? {} : { maxRedirects: 0 }), // defaults to 5 (enabled) proxy, // can be undefined, false, or object ...(timeout && { timeout }), ...urlSocketOptions, - method, + method // by default it provides full response object // validStatus is 2xx unless followRedirect is true (default) }; diff --git a/test/api.mocha.js b/test/api.mocha.js index 31f3b9b..86cb5e3 100644 --- a/test/api.mocha.js +++ b/test/api.mocha.js @@ -31,7 +31,7 @@ describe('api', function () { temp.mkdir({}, function (err, dirPath) { if (err) return done(err); const opts = { - resources: [path.resolve(dirPath, 'foo'), path.resolve(dirPath, 'bar/deeper/deep/yet')], + resources: [path.resolve(dirPath, 'foo'), path.resolve(dirPath, 'bar/deeper/deep/yet')] }; fs.writeFileSync(opts.resources[0], 'data1'); mkdirp.sync(path.dirname(opts.resources[1])); @@ -47,7 +47,7 @@ describe('api', function () { temp.mkdir({}, function (err, dirPath) { if (err) return done(err); const opts = { - resources: [path.resolve(dirPath, 'foo'), path.resolve(dirPath, 'bar/deeper/deep/yet')], + resources: [path.resolve(dirPath, 'foo'), path.resolve(dirPath, 'bar/deeper/deep/yet')] }; setTimeout(function () { @@ -65,7 +65,7 @@ describe('api', function () { it('should succeed when http resources are become available later', function (done) { const opts = { - resources: ['http://localhost:3000', 'http://localhost:3000/foo'], + resources: ['http://localhost:3000', 'http://localhost:3000/foo'] }; setTimeout(function () { @@ -86,7 +86,7 @@ describe('api', function () { resources: ['http://localhost:3000'], validateStatus: function (status) { return status === 401 || (status >= 200 && status < 300); - }, + } }; setTimeout(function () { @@ -106,7 +106,7 @@ describe('api', function () { it('should succeed when http resource become available later via redirect', function (done) { const opts = { // followRedirect: true // default is true - resources: ['http://localhost:3000'], + resources: ['http://localhost:3000'] }; setTimeout(function () { @@ -128,7 +128,7 @@ describe('api', function () { it('should succeed when http GET resources become available later', function (done) { const opts = { - resources: ['http-get://localhost:3011', 'http-get://localhost:3011/foo'], + resources: ['http-get://localhost:3011', 'http-get://localhost:3011/foo'] }; setTimeout(function () { @@ -147,7 +147,7 @@ describe('api', function () { it('should succeed when http GET resource become available later via redirect', function (done) { const opts = { // followRedirect: true, // default is true - resources: ['http-get://localhost:3000'], + resources: ['http-get://localhost:3000'] }; setTimeout(function () { @@ -197,7 +197,7 @@ describe('api', function () { it('should succeed when a service is listening to tcp port', function (done) { const opts = { - resources: ['tcp:localhost:3001', 'tcp:3001'], + resources: ['tcp:localhost:3001', 'tcp:3001'] }; setTimeout(function () { @@ -219,7 +219,7 @@ describe('api', function () { if (err) return done(err); socketPath = path.resolve(dirPath, 'sock'); const opts = { - resources: ['socket:' + socketPath], + resources: ['socket:' + socketPath] }; setTimeout(function () { @@ -240,7 +240,7 @@ describe('api', function () { if (err) return done(err); socketPath = path.resolve(dirPath, 'sock'); const opts = { - resources: ['http://unix:' + socketPath + ':/', 'http://unix:' + socketPath + ':/foo'], + resources: ['http://unix:' + socketPath + ':/', 'http://unix:' + socketPath + ':/foo'] }; setTimeout(function () { @@ -263,7 +263,7 @@ describe('api', function () { if (err) return done(err); socketPath = path.resolve(dirPath, 'sock'); const opts = { - resources: ['http-get://unix:' + socketPath + ':/', 'http-get://unix:' + socketPath + ':/foo'], + resources: ['http-get://unix:' + socketPath + ':/', 'http-get://unix:' + socketPath + ':/foo'] }; setTimeout(function () { @@ -287,7 +287,7 @@ describe('api', function () { if (err) return done(err); const opts = { resources: [path.resolve(dirPath, 'foo')], - timeout: 1000, + timeout: 1000 }; waitOn(opts, function (err) { expect(err).toExist(); @@ -301,7 +301,7 @@ describe('api', function () { if (err) return done(err); const opts = { resources: [path.resolve(dirPath, 'foo'), path.resolve(dirPath, 'bar')], - timeout: 1000, + timeout: 1000 }; fs.writeFile(opts.resources[0], 'data', function () {}); waitOn(opts, function (err) { @@ -316,7 +316,7 @@ describe('api', function () { resources: ['http://localhost:3002'], timeout: 1000, interval: 100, - window: 100, + window: 100 }; setTimeout(function () { @@ -338,7 +338,7 @@ describe('api', function () { resources: ['http://localhost:3010'], timeout: 1000, interval: 100, - window: 100, + window: 100 }; waitOn(opts, function (err) { @@ -353,7 +353,7 @@ describe('api', function () { timeout: 1000, interval: 100, window: 100, - httpTimeout: 70, + httpTimeout: 70 }; httpServer = http.createServer().on('request', function (req, res) { @@ -376,7 +376,7 @@ describe('api', function () { interval: 100, window: 100, followRedirect: false, - resources: ['http://localhost:3000'], + resources: ['http://localhost:3000'] }; httpServer = http.createServer().on('request', function (req, res) { @@ -399,7 +399,7 @@ describe('api', function () { resources: ['http-get://localhost:3010'], timeout: 1000, interval: 100, - window: 100, + window: 100 }; waitOn(opts, function (err) { @@ -413,7 +413,7 @@ describe('api', function () { resources: ['https://localhost:3010/foo/bar'], timeout: 1000, interval: 100, - window: 100, + window: 100 }; waitOn(opts, function (err) { @@ -427,7 +427,7 @@ describe('api', function () { resources: ['https-get://localhost:3010/foo/bar'], timeout: 1000, interval: 100, - window: 100, + window: 100 }; waitOn(opts, function (err) { @@ -442,7 +442,7 @@ describe('api', function () { interval: 100, window: 100, followRedirect: false, - resources: ['http-get://localhost:3000'], + resources: ['http-get://localhost:3000'] }; httpServer = http.createServer().on('request', function (req, res) { @@ -463,7 +463,7 @@ describe('api', function () { it('should timeout when a service is not listening to tcp port', function (done) { const opts = { resources: ['tcp:localhost:3010'], - timeout: 1000, + timeout: 1000 }; waitOn(opts, function (err) { @@ -481,7 +481,7 @@ describe('api', function () { resources: ['socket:' + socketPath], timeout: 1000, interval: 100, - window: 100, + window: 100 }; waitOn(opts, function (err) { @@ -495,7 +495,7 @@ describe('api', function () { const opts = { resources: ['tcp:256.0.0.1:1234'], timeout: 1000, - tcpTimeout: 1000, + tcpTimeout: 1000 }; waitOn(opts, function (err) { @@ -513,7 +513,7 @@ describe('api', function () { resources: ['http://unix:' + socketPath + ':/', 'http://unix:' + socketPath + ':/foo'], timeout: 1000, interval: 100, - window: 100, + window: 100 }; setTimeout(function () { @@ -540,7 +540,7 @@ describe('api', function () { resources: ['package.json', 'http://unix:' + socketPath + ':/', 'http://unix:' + socketPath + ':/foo'], timeout: 1000, interval: 100, - window: 100, + window: 100 }; httpServer = http.createServer().on('request', function (req, res) { @@ -565,7 +565,7 @@ describe('api', function () { timeout: 1000, tcpTimeout: 1000, reverse: true, - window: 100, + window: 100 }; waitOn(opts, function (err) { @@ -580,7 +580,7 @@ describe('api', function () { if (err) return done(err); const opts = { resources: [path.resolve(dirPath, 'foo'), path.resolve(dirPath, 'bar')], - reverse: true, + reverse: true }; waitOn(opts, function (err) { expect(err).toNotExist(); @@ -594,7 +594,7 @@ describe('api', function () { if (err) return done(err); const opts = { resources: [path.resolve(dirPath, 'foo'), path.resolve(dirPath, 'bar')], - reverse: true, + reverse: true }; fs.writeFileSync(opts.resources[0], 'data1'); fs.writeFileSync(opts.resources[1], 'data2'); @@ -615,7 +615,7 @@ describe('api', function () { const opts = { resources: [path.resolve(dirPath, 'foo'), path.resolve(dirPath, 'bar')], reverse: true, - timeout: 1000, + timeout: 1000 }; fs.writeFileSync(opts.resources[0], 'data1'); fs.writeFileSync(opts.resources[1], 'data2'); @@ -631,7 +631,7 @@ describe('api', function () { temp.mkdir({}, function (err, dirPath) { if (err) return done(err); const opts = { - resources: [path.resolve(dirPath, 'foo'), path.resolve(dirPath, 'bar')], + resources: [path.resolve(dirPath, 'foo'), path.resolve(dirPath, 'bar')] }; fs.writeFileSync(opts.resources[0], 'data1'); fs.writeFileSync(opts.resources[1], 'data2'); @@ -649,7 +649,7 @@ describe('api', function () { temp.mkdir({}, function (err, dirPath) { if (err) return done(err); const opts = { - resources: [path.resolve(dirPath, 'foo'), path.resolve(dirPath, 'bar')], + resources: [path.resolve(dirPath, 'foo'), path.resolve(dirPath, 'bar')] }; setTimeout(function () { @@ -672,7 +672,7 @@ describe('api', function () { if (err) return done(err); const opts = { resources: [path.resolve(dirPath, 'foo')], - timeout: 1000, + timeout: 1000 }; waitOn(opts) .then(function () { @@ -690,7 +690,7 @@ describe('api', function () { if (err) return done(err); const opts = { resources: [path.resolve(dirPath, 'foo'), path.resolve(dirPath, 'bar')], - timeout: 1000, + timeout: 1000 }; fs.writeFile(opts.resources[0], 'data', function () {}); waitOn(opts) @@ -709,7 +709,7 @@ describe('api', function () { if (err) return done(err); const opts = { resources: [path.resolve(dirPath, 'foo'), path.resolve(dirPath, 'bar')], - reverse: true, + reverse: true }; waitOn(opts) .then(function () { @@ -726,7 +726,7 @@ describe('api', function () { if (err) return done(err); const opts = { resources: [path.resolve(dirPath, 'foo'), path.resolve(dirPath, 'bar')], - reverse: true, + reverse: true }; fs.writeFileSync(opts.resources[0], 'data1'); fs.writeFileSync(opts.resources[1], 'data2'); @@ -750,7 +750,7 @@ describe('api', function () { const opts = { resources: [path.resolve(dirPath, 'foo'), path.resolve(dirPath, 'bar')], reverse: true, - timeout: 1000, + timeout: 1000 }; fs.writeFileSync(opts.resources[0], 'data1'); fs.writeFileSync(opts.resources[1], 'data2'); diff --git a/test/cli.mocha.js b/test/cli.mocha.js index 06a7e4b..e4e9369 100644 --- a/test/cli.mocha.js +++ b/test/cli.mocha.js @@ -40,7 +40,7 @@ describe('cli', function () { temp.mkdir({}, function (err, dirPath) { if (err) return done(err); const opts = { - resources: [path.resolve(dirPath, 'foo'), path.resolve(dirPath, 'bar/deeper/deep/yet')], + resources: [path.resolve(dirPath, 'foo'), path.resolve(dirPath, 'bar/deeper/deep/yet')] }; fs.writeFileSync(opts.resources[0], 'data1'); mkdirp.sync(path.dirname(opts.resources[1])); @@ -57,7 +57,7 @@ describe('cli', function () { temp.mkdir({}, function (err, dirPath) { if (err) return done(err); const opts = { - resources: [path.resolve(dirPath, 'foo'), path.resolve(dirPath, 'bar/deeper/deep/yet')], + resources: [path.resolve(dirPath, 'foo'), path.resolve(dirPath, 'bar/deeper/deep/yet')] }; setTimeout(function () { @@ -75,7 +75,7 @@ describe('cli', function () { it('should succeed when http resources become available later', function (done) { const opts = { - resources: ['http://localhost:8123', 'http://localhost:8123/foo'], + resources: ['http://localhost:8123', 'http://localhost:8123/foo'] }; setTimeout(function () { @@ -93,7 +93,7 @@ describe('cli', function () { it('should succeed when http resources become available later via redirect', function (done) { const opts = { - resources: ['http://localhost:8123'], + resources: ['http://localhost:8123'] }; setTimeout(function () { @@ -115,7 +115,7 @@ describe('cli', function () { it('should succeed when http GET resources become available later', function (done) { const opts = { - resources: ['http-get://localhost:8124', 'http-get://localhost:8124/foo'], + resources: ['http-get://localhost:8124', 'http-get://localhost:8124/foo'] }; setTimeout(function () { @@ -133,7 +133,7 @@ describe('cli', function () { it('should succeed when http GET resources become available later via redirect', function (done) { const opts = { - resources: ['http-get://localhost:8124'], + resources: ['http-get://localhost:8124'] }; setTimeout(function () { @@ -171,7 +171,7 @@ describe('cli', function () { it('should succeed when a service is listening to tcp port', function (done) { const opts = { - resources: ['tcp:localhost:3030', 'tcp:3030'], + resources: ['tcp:localhost:3030', 'tcp:3030'] }; setTimeout(function () { @@ -193,7 +193,7 @@ describe('cli', function () { if (err) return done(err); socketPath = path.resolve(dirPath, 'sock'); const opts = { - resources: ['socket:' + socketPath], + resources: ['socket:' + socketPath] }; setTimeout(function () { @@ -214,7 +214,7 @@ describe('cli', function () { if (err) return done(err); socketPath = path.resolve(dirPath, 'sock'); const opts = { - resources: ['http://unix:' + socketPath + ':/', 'http://unix:' + socketPath + ':/foo'], + resources: ['http://unix:' + socketPath + ':/', 'http://unix:' + socketPath + ':/foo'] }; setTimeout(function () { @@ -237,7 +237,7 @@ describe('cli', function () { if (err) return done(err); socketPath = path.resolve(dirPath, 'sock'); const opts = { - resources: ['http-get://unix:' + socketPath + ':/', 'http-get://unix:' + socketPath + ':/foo'], + resources: ['http-get://unix:' + socketPath + ':/', 'http-get://unix:' + socketPath + ':/foo'] }; setTimeout(function () { @@ -261,7 +261,7 @@ describe('cli', function () { if (err) return done(err); const opts = { resources: [path.resolve(dirPath, 'foo')], - timeout: 1000, + timeout: 1000 }; // timeout is in FAST_OPTS execCLI(opts.resources.concat(FAST_OPTS), {}).on('exit', function (code) { @@ -276,7 +276,7 @@ describe('cli', function () { if (err) return done(err); const opts = { resources: [path.resolve(dirPath, 'foo'), path.resolve(dirPath, 'bar')], - timeout: 1000, + timeout: 1000 }; fs.writeFile(opts.resources[0], 'data', function () {}); // timeout is in FAST_OPTS @@ -292,7 +292,7 @@ describe('cli', function () { resources: ['http://localhost:3998'], timeout: 1000, interval: 100, - window: 100, + window: 100 }; setTimeout(function () { @@ -314,7 +314,7 @@ describe('cli', function () { resources: ['http://localhost:3999'], timeout: 1000, interval: 100, - window: 100, + window: 100 }; // timeout is in FAST_OPTS @@ -330,7 +330,7 @@ describe('cli', function () { timeout: 1000, interval: 100, window: 100, - httpTimeout: 70, + httpTimeout: 70 }; httpServer = http.createServer().on('request', function (req, res) { @@ -354,7 +354,7 @@ describe('cli', function () { resources: ['http-get://localhost:3999'], timeout: 1000, interval: 100, - window: 100, + window: 100 }; // timeout, interval, window are in FAST_OPTS @@ -369,7 +369,7 @@ describe('cli', function () { resources: ['https://localhost:3010/foo/bar'], timeout: 1000, interval: 100, - window: 100, + window: 100 }; // timeout, interval, window are in FAST_OPTS @@ -384,7 +384,7 @@ describe('cli', function () { resources: ['https-get://localhost:3010/foo/bar'], timeout: 1000, interval: 100, - window: 100, + window: 100 }; // timeout, interval, window are in FAST_OPTS @@ -397,7 +397,7 @@ describe('cli', function () { it('should timeout when a service is not listening to tcp port', function (done) { const opts = { resources: ['tcp:localhost:3010'], - timeout: 1000, + timeout: 1000 }; // timeout is in FAST_OPTS @@ -411,7 +411,7 @@ describe('cli', function () { const opts = { resources: ['tcp:256.0.0.1:1234'], timeout: 1000, - tcpTimeout: 1000, + tcpTimeout: 1000 }; const addOpts = '--tcpTimeout 1000'.split(' '); @@ -431,7 +431,7 @@ describe('cli', function () { resources: ['socket:' + socketPath], timeout: 1000, interval: 100, - window: 100, + window: 100 }; // timeout, interval, window are in FAST_OPTS @@ -451,7 +451,7 @@ describe('cli', function () { resources: ['http://unix:' + socketPath + ':/', 'http://unix:' + socketPath + ':/foo'], timeout: 1000, interval: 100, - window: 100, + window: 100 }; setTimeout(function () { @@ -474,7 +474,7 @@ describe('cli', function () { temp.mkdir({}, function (err, dirPath) { if (err) return done(err); const opts = { - resources: [path.resolve(dirPath, 'foo'), path.resolve(dirPath, 'bar')], + resources: [path.resolve(dirPath, 'foo'), path.resolve(dirPath, 'bar')] }; const OPTS = FAST_OPTS.concat(['-r']); execCLI(opts.resources.concat(OPTS), {}).on('exit', function (code) { @@ -488,7 +488,7 @@ describe('cli', function () { temp.mkdir({}, function (err, dirPath) { if (err) return done(err); const opts = { - resources: [path.resolve(dirPath, 'foo'), path.resolve(dirPath, 'bar')], + resources: [path.resolve(dirPath, 'foo'), path.resolve(dirPath, 'bar')] }; fs.writeFileSync(opts.resources[0], 'data1'); fs.writeFileSync(opts.resources[1], 'data2'); @@ -508,7 +508,7 @@ describe('cli', function () { temp.mkdir({}, function (err, dirPath) { if (err) return done(err); const opts = { - resources: [path.resolve(dirPath, 'foo'), path.resolve(dirPath, 'bar')], + resources: [path.resolve(dirPath, 'foo'), path.resolve(dirPath, 'bar')] }; fs.writeFileSync(opts.resources[0], 'data1'); fs.writeFileSync(opts.resources[1], 'data2'); @@ -524,7 +524,7 @@ describe('cli', function () { const opts = { resources: ['tcp:256.0.0.1:1234'], timeout: 1000, - tcpTimeout: 1000, + tcpTimeout: 1000 }; // timeout is in FAST_OPTS const OPTS = FAST_OPTS.concat(['-r', '--tcpTimeout', '1000']); From 4d2e6d9cc5447ac93b824422868dfdb4f2a0d234 Mon Sep 17 00:00:00 2001 From: Jeff Barczewski Date: Wed, 17 Mar 2021 14:45:09 -0500 Subject: [PATCH 5/5] indicate that resources can now be provided in config config file can now define resources to use as well ```js module.exports = { resources: ['http://localhost:8123', 'http://localhost:8123/foo'], }; ``` --- README.md | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index d41c8c2..1eef59f 100644 --- a/README.md +++ b/README.md @@ -67,7 +67,8 @@ Description: once resources are available. ex: wait-on f1 && NEXT_CMD resources types are defined by their prefix, if no prefix is - present, the resource is assumed to be of type 'file' + present, the resource is assumed to be of type 'file'. Resources + can also be provided in the config file. resource prefixes are: @@ -86,7 +87,7 @@ Standard Options: -c, --config - js or json config file, useful for http(s) options + js or json config file, useful for http(s) options and resources -d, --delay @@ -155,7 +156,7 @@ var opts = { 'tcp:foo.com:8000', 'socket:/my/sock', 'http://unix:/my/sock:/my/url', - 'http-get://unix:/my/sock:/my/url', + 'http-get://unix:/my/sock:/my/url' ], delay: 1000, // initial delay in ms, default 0 interval: 100, // poll interval in ms, default 250ms @@ -188,16 +189,16 @@ var opts = { } */, auth: { user: 'theuser', // or username - pass: 'thepassword', // or password + pass: 'thepassword' // or password }, strictSSL: false, followRedirect: true, headers: { - 'x-custom': 'headers', + 'x-custom': 'headers' }, validateStatus: function (status) { return status >= 200 && status < 300; // default if not provided - }, + } }; // Usage with callback function