diff --git a/README.md b/README.md index d65d1b8..97727f3 100644 --- a/README.md +++ b/README.md @@ -155,7 +155,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 @@ -176,22 +176,17 @@ var opts = { passphrase: 'yourpassphrase', auth: { user: 'theuser', // or username - pass: 'thepassword' // or password - }, - httpSignature: { - keyId: 'yourKeyId', - key: 'yourKey' + pass: 'thepassword', // or password }, strictSSL: false, - followAllRedirects: true, followRedirect: true, headers: { - 'x-custom': 'headers' - } + 'x-custom': 'headers', + }, }; // Usage with callback function -waitOn(opts, function(err) { +waitOn(opts, function (err) { if (err) { return handleError(err); } @@ -200,10 +195,10 @@ waitOn(opts, function(err) { // Usage with promises waitOn(opts) - .then(function() { + .then(function () { // once here, all resources are available }) - .catch(function(err) { + .catch(function (err) { handleError(err); }); @@ -227,17 +222,15 @@ waitOn(opts, [cb]) - function which triggers resource checks - opts.tcpTimeout - optional tcp timeout in ms, default 300ms - opts.verbose - optional flag which outputs debug output, default false - opts.window - optional stabilization time in ms, default 750ms. Waits this amount of time for file sizes to stabilize or other resource availability to remain unchanged. -- http(s) specific options, see https://github.com/request/request#readme for specific details +- http(s) specific options, see https://nodejs.org/api/tls.html#tls_tls_connect_options_callback for specific details - opts.ca: [ /* strings or binaries */ ], - opts.cert: [ /* strings or binaries */ ], - opts.key: [ /* strings or binaries */ ], - opts.passphrase: 'yourpassphrase', - opts.auth: { user, pass } - - opts.httpSignature: { keyId, key } - opts.strictSSL: false, - - opts.followAllRedirects: true, - - opts.followRedirect: true, + - opts.followRedirect: false, // defaults to true - opts.headers: { 'x-custom': 'headers' }, - cb(err) - if err is provided then, resource checks did not succeed diff --git a/exampleConfig.js b/exampleConfig.js index ce918ac..924d257 100644 --- a/exampleConfig.js +++ b/exampleConfig.js @@ -1,22 +1,23 @@ module.exports = { // specify additional options here, especially http(s) - // see https://github.com/request/request#readme for specifics - ca: [ /* strings or binaries */], - cert: [ /* strings or binaries */], - key: [ /* strings or binaries */], + // see https://nodejs.org/api/tls.html#tls_tls_connect_options_callback for specifics + ca: [ + /* strings or binaries */ + ], + cert: [ + /* strings or binaries */ + ], + key: [ + /* strings or binaries */ + ], passphrase: 'yourpassphrase', auth: { user: 'yourusername', - pass: 'yourpassword' - }, - httpSignature: { - keyId: 'keyId', - key: 'yourkey' + pass: 'yourpassword', }, strictSSL: false, - followAllRedirects: false, followRedirect: false, headers: { - 'x-custom': 'headers' - } + 'x-custom': 'headers', + }, }; diff --git a/lib/wait-on.js b/lib/wait-on.js index 971b3ac..a5a86b1 100644 --- a/lib/wait-on.js +++ b/lib/wait-on.js @@ -3,8 +3,10 @@ const fs = require('fs'); const { promisify } = require('util'); const Joi = require('@hapi/joi'); +const https = require('https'); const net = require('net'); -const requestProm = require('request-promise-native'); +const util = require('util'); +const axios = require('axios').default; const { isBoolean, isEmpty, negate, noop, once, partial, pick, zip } = require('lodash/fp'); const { NEVER, combineLatest, from, merge, throwError, timer } = require('rxjs'); const { distinctUntilChanged, map, mergeMap, scan, startWith, take, takeWhile } = require('rxjs/operators'); @@ -15,62 +17,34 @@ const fstat = promisify(fs.stat); const PREFIX_RE = /^((https?-get|https?|tcp|socket|file):)(.+)$/; const HOST_PORT_RE = /^(([^:]*):)?(\d+)$/; const HTTP_GET_RE = /^https?-get:/; +const HTTP_UNIX_RE = /^http:\/\/unix:([^:]+):([^:]+)$/; const TIMEOUT_ERR_MSG = 'Timeout'; const WAIT_ON_SCHEMA = Joi.object({ - resources: Joi.array() - .items(Joi.string().required()) - .required(), - delay: Joi.number() - .integer() - .min(0) - .default(0), - httpTimeout: Joi.number() - .integer() - .min(0), - interval: Joi.number() - .integer() - .min(0) - .default(250), + resources: Joi.array().items(Joi.string().required()).required(), + delay: Joi.number().integer().min(0).default(0), + httpTimeout: Joi.number().integer().min(0), + interval: Joi.number().integer().min(0).default(250), log: Joi.boolean().default(false), reverse: Joi.boolean().default(false), - simultaneous: Joi.number() - .integer() - .min(1) - .default(Infinity), - timeout: Joi.number() - .integer() - .min(0) - .default(Infinity), + simultaneous: Joi.number().integer().min(1).default(Infinity), + timeout: Joi.number().integer().min(0).default(Infinity), verbose: Joi.boolean().default(false), - window: Joi.number() - .integer() - .min(0) - .default(750), - tcpTimeout: Joi.number() - .integer() - .min(0) - .default(300), - - // http options3 + window: Joi.number().integer().min(0).default(750), + tcpTimeout: Joi.number().integer().min(0).default(300), + + // http/https options ca: [Joi.string(), Joi.binary()], cert: [Joi.string(), Joi.binary()], - key: [Joi.string(), Joi.binary()], + key: [Joi.string(), Joi.binary(), Joi.object()], passphrase: Joi.string(), auth: Joi.object({ - user: Joi.string(), username: Joi.string(), password: Joi.string(), - pass: Joi.string() - }), - httpSignature: Joi.object({ - keyId: Joi.string().required(), - key: Joi.string().required() }), - strictSSL: Joi.boolean(), - followAllRedirects: Joi.boolean(), - followRedirect: Joi.boolean(), - headers: Joi.object() + strictSSL: Joi.boolean().default(false), + followRedirect: Joi.boolean().default(true), // HTTP 3XX responses + headers: Joi.object(), }); /** @@ -86,6 +60,9 @@ const WAIT_ON_SCHEMA = Joi.object({ - https-get: - HTTPS GET returns 2XX response. ex: https://my/bar - tcp:my.server.com:3000 verifies a service is listening on port - socket:/path/sock verifies a service is listening on (UDS) socket + For http over socket, use http://unix:SOCK_PATH:URL_PATH + like http://unix:/path/to/sock:/foo/bar or + http-get://unix:/path/to/sock:/foo/bar @param opts object configuring waitOn @param opts.resources array of string resources to wait for. prefix determines the type of resource with the default type of `file:` @@ -107,8 +84,8 @@ function waitOn(opts, cb) { return waitOnImpl(opts, cb); } else { // promise API - return new Promise(function(resolve, reject) { - waitOnImpl(opts, function(err) { + return new Promise(function (resolve, reject) { + waitOnImpl(opts, function (err) { if (err) { reject(err); } else { @@ -129,7 +106,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; @@ -167,14 +144,14 @@ function waitOnImpl(opts, cbFunc) { const resourcesCompleted$ = combineLatest(resources.map(createResourceWithDeps$)); merge(timeoutError$, resourcesCompleted$) - .pipe(takeWhile(resourceStates => resourceStates.some(x => !x))) + .pipe(takeWhile((resourceStates) => resourceStates.some((x) => !x))) .subscribe({ - next: resourceStates => { + next: (resourceStates) => { lastResourcesState = resourceStates; logWaitingForWDeps(resourceStates); }, error: cleanup, - complete: cleanup + complete: cleanup, }); } @@ -214,7 +191,7 @@ function createFileResource$( ) { const filePath = extractPath(resource); const checkOperator = reverse - ? map(size => size === -1) // check that file does not exist + ? map((size) => size === -1) // check that file does not exist : scan( // check that file exists and the size is stable (acc, x) => { @@ -244,7 +221,7 @@ function createFileResource$( return from(getFileSize(filePath)); }, simultaneous), checkOperator, - map(x => (isNotABoolean(x) ? false : x)), + map((x) => (isNotABoolean(x) ? false : x)), startWith(false), distinctUntilChanged(), take(2) @@ -277,35 +254,39 @@ async function getFileSize(filePath) { } function createHTTP$({ validatedOpts, output }, resource) { - const { delay, interval, reverse, simultaneous } = validatedOpts; - const method = HTTP_GET_RE.test(resource) ? 'GET' : 'HEAD'; - const uri = resource.replace('-get:', ':'); + const { + delay, + followRedirect, + httpTimeout: timeout, + interval, + reverse, + simultaneous, + strictSSL: rejectUnauthorized, + } = validatedOpts; + const method = HTTP_GET_RE.test(resource) ? 'get' : 'head'; + const url = resource.replace('-get:', ':'); + const matchHttpUnixSocket = HTTP_UNIX_RE.exec(url); // http://unix:/sock:/url + const urlSocketOptions = matchHttpUnixSocket + ? { socketPath: matchHttpUnixSocket[1], url: matchHttpUnixSocket[2] } + : { url }; + const socketPathDesc = urlSocketOptions.socketPath ? `socketPath:${urlSocketOptions.socketPath}` : ''; const httpOptions = { - ...pick( - [ - 'auth', - 'httpSignature', - 'followRedirect', - 'followAllRedirects', - 'strictSSL', - 'headers', - 'cert', - 'key', - 'passphrase', - 'ca' - ], - validatedOpts - ), - ...(validatedOpts.httpTimeout ? { timeout: validatedOpts.httpTimeout } : {}), - uri, + ...pick(['auth', 'headers'], validatedOpts), + httpsAgent: new https.Agent({ + rejectUnauthorized, + ...pick(['ca', 'cert', 'key', 'passphrase'], validatedOpts), + }), + ...(followRedirect ? {} : { maxRedirects: 0 }), // defaults to 5 (enabled) + ...(timeout && { timeout }), + ...urlSocketOptions, method, - resolveWithFullResponse: true, - simple: true // statusCodes other than 2xx will reject + // by default it provides full response object + // validStatus is 2xx unless followRedirect is true (default) }; const checkFn = reverse ? negateAsync(httpCallSucceeds) : httpCallSucceeds; return timer(delay, interval).pipe( mergeMap(() => { - output(`making HTTP ${method} request to ${uri} ...`); + output(`making HTTP(S) ${method} request to ${socketPathDesc} url:${urlSocketOptions.url} ...`); return from(checkFn(output, httpOptions)); }, simultaneous), startWith(false), @@ -316,11 +297,15 @@ function createHTTP$({ validatedOpts, output }, resource) { async function httpCallSucceeds(output, httpOptions) { try { - const result = await requestProm(httpOptions); - output(` HTTP result for ${httpOptions.uri}: ${JSON.stringify(result)}`); + const result = await axios(httpOptions); + output( + ` HTTP(S) result for ${httpOptions.url}: ${util.inspect( + pick(['status', 'statusText', 'headers', 'data'], result) + )}` + ); return true; } catch (err) { - output(` HTTP error for ${httpOptions.uri} ${err.toString()}`); + output(` HTTP(S) error for ${httpOptions.url} ${err.toString()}`); return false; } } @@ -342,10 +327,10 @@ function createTCP$({ validatedOpts: { delay, interval, tcpTimeout, reverse, sim async function tcpExists(output, tcpPath, tcpTimeout) { const [, , /* full, hostWithColon */ hostMatched, port] = HOST_PORT_RE.exec(tcpPath); const host = hostMatched || 'localhost'; - return new Promise(resolve => { + return new Promise((resolve) => { const conn = net .connect(port, host) - .on('error', err => { + .on('error', (err) => { output(` error connecting to TCP host:${host} port:${port} ${err.toString()}`); resolve(false); }) @@ -378,10 +363,10 @@ function createSocket$({ validatedOpts: { delay, interval, reverse, simultaneous } async function socketExists(output, socketPath) { - return new Promise(resolve => { + return new Promise((resolve) => { const conn = net .connect(socketPath) - .on('error', err => { + .on('error', (err) => { output(` error connecting to socket socket:${socketPath} ${err.toString()}`); resolve(false); }) @@ -394,7 +379,7 @@ async function socketExists(output, socketPath) { } function negateAsync(asyncFn) { - return async function(...args) { + return async function (...args) { return !(await asyncFn(...args)); }; } diff --git a/package-lock.json b/package-lock.json index 75d98fa..2533536 100644 --- a/package-lock.json +++ b/package-lock.json @@ -95,6 +95,7 @@ "version": "6.12.0", "resolved": "https://registry.npmjs.org/ajv/-/ajv-6.12.0.tgz", "integrity": "sha512-D6gFiFA0RRLyUbvijN74DWAjXSFxWKaWP7mldxkVhyhAV3+SWA9HEJPHQ2c9soIeTFJqcSdFDGFgdqs1iUU2Hw==", + "dev": true, "requires": { "fast-deep-equal": "^3.1.1", "fast-json-stable-stringify": "^2.0.0", @@ -358,39 +359,19 @@ } } }, - "asn1": { - "version": "0.2.4", - "resolved": "https://registry.npmjs.org/asn1/-/asn1-0.2.4.tgz", - "integrity": "sha512-jxwzQpLQjSmWXgwaCZE9Nz+glAG01yF1QnWgbhGwHI5A6FRIEY6IVqtHhIepHqI7/kyEyQEagBC5mBEFlIYvdg==", - "requires": { - "safer-buffer": "~2.1.0" - } - }, - "assert-plus": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/assert-plus/-/assert-plus-1.0.0.tgz", - "integrity": "sha1-8S4PPF13sLHN2RRpQuTpbB5N1SU=" - }, "astral-regex": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/astral-regex/-/astral-regex-1.0.0.tgz", "integrity": "sha512-+Ryf6g3BKoRc7jfp7ad8tM4TtMiaWvbF/1/sQcZPkkS7ag3D5nMBCe2UfOTONtAkaG0tO0ij3C5Lwmf1EiyjHg==", "dev": true }, - "asynckit": { - "version": "0.4.0", - "resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz", - "integrity": "sha1-x57Zf380y48robyXkLzDZkdLS3k=" - }, - "aws-sign2": { - "version": "0.7.0", - "resolved": "https://registry.npmjs.org/aws-sign2/-/aws-sign2-0.7.0.tgz", - "integrity": "sha1-tG6JCTSpWR8tL2+G1+ap8bP+dqg=" - }, - "aws4": { - "version": "1.9.1", - "resolved": "https://registry.npmjs.org/aws4/-/aws4-1.9.1.tgz", - "integrity": "sha512-wMHVg2EOHaMRxbzgFJ9gtjOOCrI80OHLG14rxi28XwOW8ux6IiEbRCGGGqCtdAIg4FQCbW20k9RsT4y3gJlFug==" + "axios": { + "version": "0.19.2", + "resolved": "https://registry.npmjs.org/axios/-/axios-0.19.2.tgz", + "integrity": "sha512-fjgm5MvRHLhx+osE2xoekY70AhARk3a6hkN+3Io1jc00jtquGvxYlKlsFUhmUET0V5te6CcZI7lcv2Ym61mjHA==", + "requires": { + "follow-redirects": "1.5.10" + } }, "balanced-match": { "version": "1.0.0", @@ -398,14 +379,6 @@ "integrity": "sha1-ibTRmasr7kneFk6gK4nORi1xt2c=", "dev": true }, - "bcrypt-pbkdf": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/bcrypt-pbkdf/-/bcrypt-pbkdf-1.0.2.tgz", - "integrity": "sha1-pDAdOJtqQ/m2f/PKEaP2Y342Dp4=", - "requires": { - "tweetnacl": "^0.14.3" - } - }, "binary-extensions": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/binary-extensions/-/binary-extensions-2.0.0.tgz", @@ -449,11 +422,6 @@ "integrity": "sha512-L28STB170nwWS63UjtlEOE3dldQApaJXZkOI1uMFfzf3rRuPegHaHesyee+YxQ+W6SvRDQV6UrdOdRiR153wJg==", "dev": true }, - "caseless": { - "version": "0.12.0", - "resolved": "https://registry.npmjs.org/caseless/-/caseless-0.12.0.tgz", - "integrity": "sha1-G2gcIf+EAzyCZUMJBolCDRhxUdw=" - }, "chalk": { "version": "2.4.2", "resolved": "https://registry.npmjs.org/chalk/-/chalk-2.4.2.tgz", @@ -567,14 +535,6 @@ "integrity": "sha1-p9BVi9icQveV3UIyj3QIMcpTvCU=", "dev": true }, - "combined-stream": { - "version": "1.0.8", - "resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz", - "integrity": "sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==", - "requires": { - "delayed-stream": "~1.0.0" - } - }, "concat-map": { "version": "0.0.1", "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", @@ -587,11 +547,6 @@ "integrity": "sha1-/ozxhP9mcLa67wGp1IYaXL7EEgo=", "dev": true }, - "core-util-is": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.2.tgz", - "integrity": "sha1-tf1UIgqivFq1eqtxQMlAdUUDwac=" - }, "cross-spawn": { "version": "6.0.5", "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-6.0.5.tgz", @@ -605,14 +560,6 @@ "which": "^1.2.9" } }, - "dashdash": { - "version": "1.14.1", - "resolved": "https://registry.npmjs.org/dashdash/-/dashdash-1.14.1.tgz", - "integrity": "sha1-hTz6D3y+L+1d4gMmuN1YEDX24vA=", - "requires": { - "assert-plus": "^1.0.0" - } - }, "debug": { "version": "3.2.6", "resolved": "https://registry.npmjs.org/debug/-/debug-3.2.6.tgz", @@ -644,11 +591,6 @@ "object-keys": "^1.0.8" } }, - "delayed-stream": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz", - "integrity": "sha1-3zrhmayt+31ECqrgsp4icrJOxhk=" - }, "diff": { "version": "3.5.0", "resolved": "https://registry.npmjs.org/diff/-/diff-3.5.0.tgz", @@ -664,15 +606,6 @@ "esutils": "^2.0.2" } }, - "ecc-jsbn": { - "version": "0.1.2", - "resolved": "https://registry.npmjs.org/ecc-jsbn/-/ecc-jsbn-0.1.2.tgz", - "integrity": "sha1-OoOpBOVDUyh4dMVkt1SThoSamMk=", - "requires": { - "jsbn": "~0.1.0", - "safer-buffer": "^2.1.0" - } - }, "emoji-regex": { "version": "7.0.3", "resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-7.0.3.tgz", @@ -1121,11 +1054,6 @@ "tmatch": "^2.0.1" } }, - "extend": { - "version": "3.0.2", - "resolved": "https://registry.npmjs.org/extend/-/extend-3.0.2.tgz", - "integrity": "sha512-fjquC59cD7CyW6urNXK0FBufkZcoiGG80wTuPujX590cB5Ttln20E2UB4S/WARVqhXffZl2LNgS+gQdPIIim/g==" - }, "external-editor": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/external-editor/-/external-editor-3.1.0.tgz", @@ -1137,20 +1065,17 @@ "tmp": "^0.0.33" } }, - "extsprintf": { - "version": "1.3.0", - "resolved": "https://registry.npmjs.org/extsprintf/-/extsprintf-1.3.0.tgz", - "integrity": "sha1-lpGEQOMEGnpBT4xS48V06zw+HgU=" - }, "fast-deep-equal": { "version": "3.1.1", "resolved": "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-3.1.1.tgz", - "integrity": "sha512-8UEa58QDLauDNfpbrX55Q9jrGHThw2ZMdOky5Gl1CDtVeJDPVrG4Jxx1N8jw2gkWaff5UUuX1KJd+9zGe2B+ZA==" + "integrity": "sha512-8UEa58QDLauDNfpbrX55Q9jrGHThw2ZMdOky5Gl1CDtVeJDPVrG4Jxx1N8jw2gkWaff5UUuX1KJd+9zGe2B+ZA==", + "dev": true }, "fast-json-stable-stringify": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/fast-json-stable-stringify/-/fast-json-stable-stringify-2.0.0.tgz", - "integrity": "sha1-1RQsDK7msRifh9OnYREGT4bIu/I=" + "integrity": "sha1-1RQsDK7msRifh9OnYREGT4bIu/I=", + "dev": true }, "fast-levenshtein": { "version": "2.0.6", @@ -1220,27 +1145,35 @@ "integrity": "sha512-r5wGx7YeOwNWNlCA0wQ86zKyDLMQr+/RB8xy74M4hTphfmjlijTSSXGuH8rnvKZnfT9i+75zmd8jcKdMR4O6jA==", "dev": true }, + "follow-redirects": { + "version": "1.5.10", + "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.5.10.tgz", + "integrity": "sha512-0V5l4Cizzvqt5D44aTXbFZz+FtyXV1vrDN6qrelxtfYQKW0KO0W2T/hkE8xvGa/540LkZlkaUjO4ailYTFtHVQ==", + "requires": { + "debug": "=3.1.0" + }, + "dependencies": { + "debug": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/debug/-/debug-3.1.0.tgz", + "integrity": "sha512-OX8XqP7/1a9cqkxYw2yXss15f26NKWBpDXQd0/uK/KPqdQhxbPa994hnzjcE2VqQpDslf55723cKPUOGSmMY3g==", + "requires": { + "ms": "2.0.0" + } + }, + "ms": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", + "integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g=" + } + } + }, "foreach": { "version": "2.0.5", "resolved": "https://registry.npmjs.org/foreach/-/foreach-2.0.5.tgz", "integrity": "sha1-C+4AUBiusmDQo6865ljdATbsG5k=", "dev": true }, - "forever-agent": { - "version": "0.6.1", - "resolved": "https://registry.npmjs.org/forever-agent/-/forever-agent-0.6.1.tgz", - "integrity": "sha1-+8cfDEGt6zf5bFd60e1C2P2sypE=" - }, - "form-data": { - "version": "2.3.3", - "resolved": "https://registry.npmjs.org/form-data/-/form-data-2.3.3.tgz", - "integrity": "sha512-1lLKB2Mu3aGP1Q/2eCOx0fNbRMe7XdwktwOruhfqqd0rIJWwN4Dh+E3hrPSlDCXnSR7UtZ1N38rVXm+6+MEhJQ==", - "requires": { - "asynckit": "^0.4.0", - "combined-stream": "^1.0.6", - "mime-types": "^2.1.12" - } - }, "fs.realpath": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", @@ -1278,14 +1211,6 @@ "integrity": "sha512-jp4tHawyV7+fkkSKyvjuLZswblUtz+SQKzSWnBbii16BuZksJlU1wuBYXY75r+duh/llF1ur6oNwi+2ZzjKZ7g==", "dev": true }, - "getpass": { - "version": "0.1.7", - "resolved": "https://registry.npmjs.org/getpass/-/getpass-0.1.7.tgz", - "integrity": "sha1-Xv+OPmhNVprkyysSgmBOi6YhSfo=", - "requires": { - "assert-plus": "^1.0.0" - } - }, "glob": { "version": "7.1.3", "resolved": "https://registry.npmjs.org/glob/-/glob-7.1.3.tgz", @@ -1330,20 +1255,6 @@ "integrity": "sha512-qBr4OuELkhPenW6goKVXiv47US3clb3/IbuWF9KNKEijAy9oeHxU9IgzjvJhHkUzhaj7rOUD7+YGWqUjLp5oSA==", "dev": true }, - "har-schema": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/har-schema/-/har-schema-2.0.0.tgz", - "integrity": "sha1-qUwiJOvKwEeCoNkDVSHyRzW37JI=" - }, - "har-validator": { - "version": "5.1.3", - "resolved": "https://registry.npmjs.org/har-validator/-/har-validator-5.1.3.tgz", - "integrity": "sha512-sNvOCzEQNr/qrvJgc3UG/kD4QtlHycrzwS+6mfTrrSq97BvaYcPZZI1ZSqGSPR73Cxn4LKTD4PttRwfU7jWq5g==", - "requires": { - "ajv": "^6.5.5", - "har-schema": "^2.0.0" - } - }, "has": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/has/-/has-1.0.1.tgz", @@ -1377,16 +1288,6 @@ "integrity": "sha512-f/wzC2QaWBs7t9IYqB4T3sR1xviIViXJRJTWBlx2Gf3g0Xi5vI7Yy4koXQ1c9OYDGHN9sBy1DQ2AB8fqZBWhUg==", "dev": true }, - "http-signature": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/http-signature/-/http-signature-1.2.0.tgz", - "integrity": "sha1-muzZJRFHcvPZW2WmCruPfBj7rOE=", - "requires": { - "assert-plus": "^1.0.0", - "jsprim": "^1.2.2", - "sshpk": "^1.7.0" - } - }, "iconv-lite": { "version": "0.4.24", "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.24.tgz", @@ -1678,11 +1579,6 @@ "integrity": "sha1-PMWfAAJRlLarLjjbrmaJJWtmBXI=", "dev": true }, - "is-typedarray": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/is-typedarray/-/is-typedarray-1.0.0.tgz", - "integrity": "sha1-5HnICFjfDBsR3dppQPlgEfzaSpo=" - }, "isarray": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz", @@ -1695,11 +1591,6 @@ "integrity": "sha1-6PvzdNxVb/iUehDcsFctYz8s+hA=", "dev": true }, - "isstream": { - "version": "0.1.2", - "resolved": "https://registry.npmjs.org/isstream/-/isstream-0.1.2.tgz", - "integrity": "sha1-R+Y/evVa+m+S4VAOaQ64uFKcCZo=" - }, "js-tokens": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-4.0.0.tgz", @@ -1716,20 +1607,11 @@ "esprima": "^4.0.0" } }, - "jsbn": { - "version": "0.1.1", - "resolved": "https://registry.npmjs.org/jsbn/-/jsbn-0.1.1.tgz", - "integrity": "sha1-peZUwuWi3rXyAdls77yoDA7y9RM=" - }, - "json-schema": { - "version": "0.2.3", - "resolved": "https://registry.npmjs.org/json-schema/-/json-schema-0.2.3.tgz", - "integrity": "sha1-tIDIkuWaLwWVTOcnvT8qTogvnhM=" - }, "json-schema-traverse": { "version": "0.4.1", "resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-0.4.1.tgz", - "integrity": "sha512-xbbCH5dCYU5T8LcEhhuh7HJ88HXuW3qsI3Y0zOZFKfZEHcpWiHU/Jxzk629Brsab/mMiHQti9wMP+845RPe3Vg==" + "integrity": "sha512-xbbCH5dCYU5T8LcEhhuh7HJ88HXuW3qsI3Y0zOZFKfZEHcpWiHU/Jxzk629Brsab/mMiHQti9wMP+845RPe3Vg==", + "dev": true }, "json-stable-stringify-without-jsonify": { "version": "1.0.1", @@ -1737,22 +1619,6 @@ "integrity": "sha1-nbe1lJatPzz+8wp1FC0tkwrXJlE=", "dev": true }, - "json-stringify-safe": { - "version": "5.0.1", - "resolved": "https://registry.npmjs.org/json-stringify-safe/-/json-stringify-safe-5.0.1.tgz", - "integrity": "sha1-Epai1Y/UXxmg9s4B1lcB4sc1tus=" - }, - "jsprim": { - "version": "1.4.1", - "resolved": "https://registry.npmjs.org/jsprim/-/jsprim-1.4.1.tgz", - "integrity": "sha1-MT5mvB5cwG5Di8G3SZwuXFastqI=", - "requires": { - "assert-plus": "1.0.0", - "extsprintf": "1.3.0", - "json-schema": "0.2.3", - "verror": "1.10.0" - } - }, "levn": { "version": "0.3.0", "resolved": "https://registry.npmjs.org/levn/-/levn-0.3.0.tgz", @@ -1799,19 +1665,6 @@ "chalk": "^2.4.2" } }, - "mime-db": { - "version": "1.43.0", - "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.43.0.tgz", - "integrity": "sha512-+5dsGEEovYbT8UY9yD7eE4XTc4UwJ1jBYlgaQQF38ENsKR3wj/8q8RFZrF9WIZpB2V1ArTVFUva8sAul1NzRzQ==" - }, - "mime-types": { - "version": "2.1.26", - "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.26.tgz", - "integrity": "sha512-01paPWYgLrkqAyrlDorC1uDwl2p3qZT7yl806vW7DvDoxwXi46jsjFbg+WdwotBIk6/MbEhO/dh5aZ5sNj/dWQ==", - "requires": { - "mime-db": "1.43.0" - } - }, "mimic-fn": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/mimic-fn/-/mimic-fn-2.1.0.tgz", @@ -1933,11 +1786,6 @@ "integrity": "sha512-6eZs5Ls3WtCisHWp9S2GUy8dqkpGi4BVSz3GaqiE6ezub0512ESztXUwUB6C6IKbQkY2Pnb/mD4WYojCRwcwLA==", "dev": true }, - "oauth-sign": { - "version": "0.9.0", - "resolved": "https://registry.npmjs.org/oauth-sign/-/oauth-sign-0.9.0.tgz", - "integrity": "sha512-fexhUFFPTGV8ybAtSIGbV6gOkSv8UtRbDBnAyLQw4QPKkgNlsH2ByPGtMUqdWkos6YCRmAqViwgZrJc/mRDzZQ==" - }, "object-inspect": { "version": "1.5.0", "resolved": "https://registry.npmjs.org/object-inspect/-/object-inspect-1.5.0.tgz", @@ -2281,11 +2129,6 @@ "pify": "^2.0.0" } }, - "performance-now": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/performance-now/-/performance-now-2.1.0.tgz", - "integrity": "sha1-Ywn04OX6kT7BxpMHrjZLSzd8nns=" - }, "picomatch": { "version": "2.2.2", "resolved": "https://registry.npmjs.org/picomatch/-/picomatch-2.2.2.tgz", @@ -2364,20 +2207,11 @@ "integrity": "sha512-7PiHtLll5LdnKIMw100I+8xJXR5gW2QwWYkT6iJva0bXitZKa/XMrSbdmg3r2Xnaidz9Qumd0VPaMrZlF9V9sA==", "dev": true }, - "psl": { - "version": "1.1.29", - "resolved": "https://registry.npmjs.org/psl/-/psl-1.1.29.tgz", - "integrity": "sha512-AeUmQ0oLN02flVHXWh9sSJF7mcdFq0ppid/JkErufc3hGIV/AMa8Fo9VgDo/cT2jFdOWoFvHp90qqBH54W+gjQ==" - }, "punycode": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/punycode/-/punycode-2.1.1.tgz", - "integrity": "sha512-XRsRjdf+j5ml+y/6GKHPZbrF/8p2Yga0JPtdqTIY2Xe5ohJPD9saDJJLPvp9+NSBprVvevdXZybnj2cv8OEd0A==" - }, - "qs": { - "version": "6.5.2", - "resolved": "https://registry.npmjs.org/qs/-/qs-6.5.2.tgz", - "integrity": "sha512-N5ZAX4/LxJmF+7wN74pUD6qAh9/wnvdQcjq9TZjevvXzSUo7bfmw91saqMjzGS2xq91/odN2dW/WOl7qQHNDGA==" + "integrity": "sha512-XRsRjdf+j5ml+y/6GKHPZbrF/8p2Yga0JPtdqTIY2Xe5ohJPD9saDJJLPvp9+NSBprVvevdXZybnj2cv8OEd0A==", + "dev": true }, "read-pkg": { "version": "2.0.0", @@ -2460,62 +2294,6 @@ "integrity": "sha512-lv0M6+TkDVniA3aD1Eg0DVpfU/booSu7Eev3TDO/mZKHBfVjgCGTV4t4buppESEYDtkArYFOxTJWv6S5C+iaNw==", "dev": true }, - "request": { - "version": "2.88.2", - "resolved": "https://registry.npmjs.org/request/-/request-2.88.2.tgz", - "integrity": "sha512-MsvtOrfG9ZcrOwAW+Qi+F6HbD0CWXEh9ou77uOb7FM2WPhwT7smM833PzanhJLsgXjN89Ir6V2PczXNnMpwKhw==", - "requires": { - "aws-sign2": "~0.7.0", - "aws4": "^1.8.0", - "caseless": "~0.12.0", - "combined-stream": "~1.0.6", - "extend": "~3.0.2", - "forever-agent": "~0.6.1", - "form-data": "~2.3.2", - "har-validator": "~5.1.3", - "http-signature": "~1.2.0", - "is-typedarray": "~1.0.0", - "isstream": "~0.1.2", - "json-stringify-safe": "~5.0.1", - "mime-types": "~2.1.19", - "oauth-sign": "~0.9.0", - "performance-now": "^2.1.0", - "qs": "~6.5.2", - "safe-buffer": "^5.1.2", - "tough-cookie": "~2.5.0", - "tunnel-agent": "^0.6.0", - "uuid": "^3.3.2" - }, - "dependencies": { - "tough-cookie": { - "version": "2.5.0", - "resolved": "https://registry.npmjs.org/tough-cookie/-/tough-cookie-2.5.0.tgz", - "integrity": "sha512-nlLsUzgm1kfLXSXfRZMc1KLAugd4hqJHDTvc2hDIwS3mZAfMEuMbc03SujMF+GEcpaX/qboeycw6iO8JwVv2+g==", - "requires": { - "psl": "^1.1.28", - "punycode": "^2.1.1" - } - } - } - }, - "request-promise-core": { - "version": "1.1.3", - "resolved": "https://registry.npmjs.org/request-promise-core/-/request-promise-core-1.1.3.tgz", - "integrity": "sha512-QIs2+ArIGQVp5ZYbWD5ZLCY29D5CfWizP8eWnm8FoGD1TX61veauETVQbrV60662V0oFBkrDOuaBI8XgtuyYAQ==", - "requires": { - "lodash": "^4.17.15" - } - }, - "request-promise-native": { - "version": "1.0.8", - "resolved": "https://registry.npmjs.org/request-promise-native/-/request-promise-native-1.0.8.tgz", - "integrity": "sha512-dapwLGqkHtwL5AEbfenuzjTYg35Jd6KPytsC2/TLkVMz8rm+tNt72MGUWT1RP/aYawMpN6HqbNGBQaRcBtjQMQ==", - "requires": { - "request-promise-core": "1.1.3", - "stealthy-require": "^1.1.1", - "tough-cookie": "^2.3.3" - } - }, "require-directory": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/require-directory/-/require-directory-2.1.1.tgz", @@ -2579,15 +2357,11 @@ "tslib": "^1.9.0" } }, - "safe-buffer": { - "version": "5.2.0", - "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.0.tgz", - "integrity": "sha512-fZEwUGbVl7kouZs1jCdMLdt95hdIv0ZeHg6L7qPeciMZhZ+/gdesW4wgTARkrFWEpspjEATAzUGPG8N2jJiwbg==" - }, "safer-buffer": { "version": "2.1.2", "resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz", - "integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==" + "integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==", + "dev": true }, "semver": { "version": "5.7.1", @@ -2671,27 +2445,6 @@ "integrity": "sha1-BOaSb2YolTVPPdAVIDYzuFcpfiw=", "dev": true }, - "sshpk": { - "version": "1.16.1", - "resolved": "https://registry.npmjs.org/sshpk/-/sshpk-1.16.1.tgz", - "integrity": "sha512-HXXqVUq7+pcKeLqqZj6mHFUMvXtOJt1uoUx09pFW6011inTMxqI8BA8PM95myrIyyKwdnzjdFjLiE6KBPVtJIg==", - "requires": { - "asn1": "~0.2.3", - "assert-plus": "^1.0.0", - "bcrypt-pbkdf": "^1.0.0", - "dashdash": "^1.12.0", - "ecc-jsbn": "~0.1.1", - "getpass": "^0.1.1", - "jsbn": "~0.1.0", - "safer-buffer": "^2.0.2", - "tweetnacl": "~0.14.0" - } - }, - "stealthy-require": { - "version": "1.1.1", - "resolved": "https://registry.npmjs.org/stealthy-require/-/stealthy-require-1.1.1.tgz", - "integrity": "sha1-NbCYdbT/SfJqd35QmzCQoyJr8ks=" - }, "string-width": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/string-width/-/string-width-2.1.1.tgz", @@ -3203,40 +2956,11 @@ "is-number": "^7.0.0" } }, - "tough-cookie": { - "version": "2.4.3", - "resolved": "https://registry.npmjs.org/tough-cookie/-/tough-cookie-2.4.3.tgz", - "integrity": "sha512-Q5srk/4vDM54WJsJio3XNn6K2sCG+CQ8G5Wz6bZhRZoAe/+TxjWB/GlFAnYEbkYVlON9FMk/fE3h2RLpPXo4lQ==", - "requires": { - "psl": "^1.1.24", - "punycode": "^1.4.1" - }, - "dependencies": { - "punycode": { - "version": "1.4.1", - "resolved": "https://registry.npmjs.org/punycode/-/punycode-1.4.1.tgz", - "integrity": "sha1-wNWmOycYgArY4esPpSachN1BhF4=" - } - } - }, "tslib": { "version": "1.11.1", "resolved": "https://registry.npmjs.org/tslib/-/tslib-1.11.1.tgz", "integrity": "sha512-aZW88SY8kQbU7gpV19lN24LtXh/yD4ZZg6qieAJDDg+YBsJcSmLGK9QpnUjAKVG/xefmvJGd1WUmfpT/g6AJGA==" }, - "tunnel-agent": { - "version": "0.6.0", - "resolved": "https://registry.npmjs.org/tunnel-agent/-/tunnel-agent-0.6.0.tgz", - "integrity": "sha1-J6XeoGs2sEoKmWZ3SykIaPD8QP0=", - "requires": { - "safe-buffer": "^5.0.1" - } - }, - "tweetnacl": { - "version": "0.14.5", - "resolved": "https://registry.npmjs.org/tweetnacl/-/tweetnacl-0.14.5.tgz", - "integrity": "sha1-WuaBd/GS1EViadEIr6k/+HQ/T2Q=" - }, "type-check": { "version": "0.3.2", "resolved": "https://registry.npmjs.org/type-check/-/type-check-0.3.2.tgz", @@ -3256,15 +2980,11 @@ "version": "4.2.2", "resolved": "https://registry.npmjs.org/uri-js/-/uri-js-4.2.2.tgz", "integrity": "sha512-KY9Frmirql91X2Qgjry0Wd4Y+YTdrdZheS8TFwvkbLWf/G5KNJDCh6pKL5OZctEW4+0Baa5idK2ZQuELRwPznQ==", + "dev": true, "requires": { "punycode": "^2.1.0" } }, - "uuid": { - "version": "3.4.0", - "resolved": "https://registry.npmjs.org/uuid/-/uuid-3.4.0.tgz", - "integrity": "sha512-HjSDRw6gZE5JMggctHBcjVak08+KEVhSIiDzFnT9S9aegmp85S/bReBVTb4QTFaRNptJ9kuYaNhnbNEOkbKb/A==" - }, "v8-compile-cache": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/v8-compile-cache/-/v8-compile-cache-2.1.0.tgz", @@ -3281,16 +3001,6 @@ "spdx-expression-parse": "^3.0.0" } }, - "verror": { - "version": "1.10.0", - "resolved": "https://registry.npmjs.org/verror/-/verror-1.10.0.tgz", - "integrity": "sha1-OhBcoXBTr1XW4nDB+CiGguGNpAA=", - "requires": { - "assert-plus": "^1.0.0", - "core-util-is": "1.0.2", - "extsprintf": "^1.2.0" - } - }, "which": { "version": "1.3.1", "resolved": "https://registry.npmjs.org/which/-/which-1.3.1.tgz", diff --git a/package.json b/package.json index 7eab032..7b57136 100644 --- a/package.json +++ b/package.json @@ -39,10 +39,9 @@ }, "dependencies": { "@hapi/joi": "^17.1.1", + "axios": "^0.19.2", "lodash": "^4.17.15", "minimist": "^1.2.5", - "request": "^2.88.2", - "request-promise-native": "^1.0.8", "rxjs": "^6.5.5" }, "keywords": [ diff --git a/test/api.mocha.js b/test/api.mocha.js index f7bc49e..8c1189e 100644 --- a/test/api.mocha.js +++ b/test/api.mocha.js @@ -15,11 +15,11 @@ const expect = require('expect-legacy'); temp.track(); // cleanup files on exit -describe('api', function() { +describe('api', function () { this.timeout(3000); var httpServer = null; - afterEach(function(done) { + afterEach(function (done) { if (httpServer) { httpServer.close(); httpServer = null; @@ -27,73 +27,119 @@ describe('api', function() { done(); }); - it('should succeed when file resources are available', function(done) { - temp.mkdir({}, function(err, dirPath) { + it('should succeed when file resources are available', function (done) { + temp.mkdir({}, function (err, dirPath) { if (err) return done(err); var 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])); fs.writeFileSync(opts.resources[1], 'data2'); - waitOn(opts, function(err) { + waitOn(opts, function (err) { expect(err).toNotExist(); done(); }); }); }); - it('should succeed when file resources are become available later', function(done) { - temp.mkdir({}, function(err, dirPath) { + it('should succeed when file resources are become available later', function (done) { + temp.mkdir({}, function (err, dirPath) { if (err) return done(err); var 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() { - fs.writeFile(opts.resources[0], 'data1', function() {}); + setTimeout(function () { + fs.writeFile(opts.resources[0], 'data1', function () {}); mkdirp.sync(path.dirname(opts.resources[1])); - fs.writeFile(opts.resources[1], 'data2', function() {}); + fs.writeFile(opts.resources[1], 'data2', function () {}); }, 300); - waitOn(opts, function(err) { + waitOn(opts, function (err) { expect(err).toNotExist(); done(); }); }); }); - it('should succeed when http resources are become available later', function(done) { + it('should succeed when http resources are become available later', function (done) { var opts = { - resources: ['http://localhost:3000', 'http://localhost:3000/foo'] + resources: ['http://localhost:3000', 'http://localhost:3000/foo'], }; - setTimeout(function() { - httpServer = http.createServer().on('request', function(req, res) { + setTimeout(function () { + httpServer = http.createServer().on('request', function (req, res) { res.end('data'); }); httpServer.listen(3000, 'localhost'); }, 300); - waitOn(opts, function(err) { + waitOn(opts, function (err) { + expect(err).toNotExist(); + done(); + }); + }); + + it('should succeed when http resource become available later via redirect', function (done) { + var opts = { + // followRedirect: true // default is true + resources: ['http://localhost:3000'], + }; + + setTimeout(function () { + httpServer = http.createServer().on('request', function (req, res) { + const pathname = req.url; + if (pathname === '/') { + res.writeHead(302, { Location: 'http://localhost:3000/foo' }); + } + res.end('data'); + }); + httpServer.listen(3000, 'localhost'); + }, 300); + + waitOn(opts, function (err) { expect(err).toNotExist(); done(); }); }); - it('should succeed when http GET resources become available later', function(done) { + it('should succeed when http GET resources become available later', function (done) { var opts = { - resources: ['http-get://localhost:3011', 'http-get://localhost:3011/foo'] + resources: ['http-get://localhost:3011', 'http-get://localhost:3011/foo'], }; - setTimeout(function() { - httpServer = http.createServer().on('request', function(req, res) { + setTimeout(function () { + httpServer = http.createServer().on('request', function (req, res) { res.end('data'); }); httpServer.listen(3011, 'localhost'); }, 300); - waitOn(opts, function(err) { + waitOn(opts, function (err) { + expect(err).toNotExist(); + done(); + }); + }); + + it('should succeed when http GET resource become available later via redirect', function (done) { + var opts = { + // followRedirect: true, // default is true + resources: ['http-get://localhost:3000'], + }; + + setTimeout(function () { + httpServer = http.createServer().on('request', function (req, res) { + const pathname = req.url; + if (pathname === '/') { + res.writeHead(302, { Location: 'http://localhost:3000/foo' }); + } + res.end('data'); + }); + httpServer.listen(3000, 'localhost'); + }, 300); + + waitOn(opts, function (err) { expect(err).toNotExist(); done(); }); @@ -127,85 +173,85 @@ describe('api', function() { }); */ - it('should succeed when a service is listening to tcp port', function(done) { + it('should succeed when a service is listening to tcp port', function (done) { var opts = { - resources: ['tcp:localhost:3001', 'tcp:3001'] + resources: ['tcp:localhost:3001', 'tcp:3001'], }; - setTimeout(function() { - httpServer = http.createServer().on('request', function(req, res) { + setTimeout(function () { + httpServer = http.createServer().on('request', function (req, res) { res.end('data'); }); httpServer.listen(3001, 'localhost'); }, 300); - waitOn(opts, function(err) { + waitOn(opts, function (err) { expect(err).toNotExist(); done(); }); }); - it('should succeed when a service is listening to a socket', function(done) { + it('should succeed when a service is listening to a socket', function (done) { var socketPath; - temp.mkdir({}, function(err, dirPath) { + temp.mkdir({}, function (err, dirPath) { if (err) return done(err); socketPath = path.resolve(dirPath, 'sock'); var opts = { - resources: ['socket:' + socketPath] + resources: ['socket:' + socketPath], }; - setTimeout(function() { + setTimeout(function () { httpServer = http.createServer(); httpServer.listen(socketPath); }, 300); - waitOn(opts, function(err) { + waitOn(opts, function (err) { expect(err).toNotExist(); done(); }); }); }); - it('should succeed when a http service is listening to a socket', function(done) { + it('should succeed when a http service is listening to a socket', function (done) { var socketPath; - temp.mkdir({}, function(err, dirPath) { + temp.mkdir({}, function (err, dirPath) { if (err) return done(err); socketPath = path.resolve(dirPath, 'sock'); var opts = { - resources: ['http://unix:' + socketPath + ':/', 'http://unix:' + socketPath + ':/foo'] + resources: ['http://unix:' + socketPath + ':/', 'http://unix:' + socketPath + ':/foo'], }; - setTimeout(function() { - httpServer = http.createServer().on('request', function(req, res) { + setTimeout(function () { + httpServer = http.createServer().on('request', function (req, res) { res.end('data'); }); httpServer.listen(socketPath); }, 300); - waitOn(opts, function(err) { + waitOn(opts, function (err) { expect(err).toNotExist(); done(); }); }); }); - it('should succeed when a http GET service is listening to a socket', function(done) { + it('should succeed when a http GET service is listening to a socket', function (done) { var socketPath; - temp.mkdir({}, function(err, dirPath) { + temp.mkdir({}, function (err, dirPath) { if (err) return done(err); socketPath = path.resolve(dirPath, 'sock'); var opts = { - resources: ['http-get://unix:' + socketPath + ':/', 'http-get://unix:' + socketPath + ':/foo'] + resources: ['http-get://unix:' + socketPath + ':/', 'http-get://unix:' + socketPath + ':/foo'], }; - setTimeout(function() { - httpServer = http.createServer().on('request', function(req, res) { + setTimeout(function () { + httpServer = http.createServer().on('request', function (req, res) { res.end('data'); }); httpServer.listen(socketPath); }, 300); - waitOn(opts, function(err) { + waitOn(opts, function (err) { expect(err).toNotExist(); done(); }); @@ -214,435 +260,483 @@ describe('api', function() { // Error situations - it('should timeout when all resources are not available and timout option is specified', function(done) { - temp.mkdir({}, function(err, dirPath) { + it('should timeout when all resources are not available and timout option is specified', function (done) { + temp.mkdir({}, function (err, dirPath) { if (err) return done(err); var opts = { resources: [path.resolve(dirPath, 'foo')], - timeout: 1000 + timeout: 1000, }; - waitOn(opts, function(err) { + waitOn(opts, function (err) { expect(err).toExist(); done(); }); }); }); - it('should timeout when some resources are not available and timout option is specified', function(done) { - temp.mkdir({}, function(err, dirPath) { + it('should timeout when some resources are not available and timout option is specified', function (done) { + temp.mkdir({}, function (err, dirPath) { if (err) return done(err); var 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) { + fs.writeFile(opts.resources[0], 'data', function () {}); + waitOn(opts, function (err) { expect(err).toExist(); done(); }); }); }); - it('should timeout when an http resource returns 404', function(done) { + it('should timeout when an http resource returns 404', function (done) { var opts = { resources: ['http://localhost:3002'], timeout: 1000, interval: 100, - window: 100 + window: 100, }; - setTimeout(function() { - httpServer = http.createServer().on('request', function(req, res) { + setTimeout(function () { + httpServer = http.createServer().on('request', function (req, res) { res.statusCode = 404; res.end('data'); }); httpServer.listen(3002, 'localhost'); }, 300); - waitOn(opts, function(err) { + waitOn(opts, function (err) { expect(err).toExist(); done(); }); }); - it('should timeout when an http resource is not available', function(done) { + it('should timeout when an http resource is not available', function (done) { var opts = { resources: ['http://localhost:3010'], timeout: 1000, interval: 100, - window: 100 + window: 100, }; - waitOn(opts, function(err) { + waitOn(opts, function (err) { expect(err).toExist(); done(); }); }); - it('should timeout when an http resource does not respond before httpTimeout', function(done) { + it('should timeout when an http resource does not respond before httpTimeout', function (done) { var opts = { resources: ['http://localhost:8125'], timeout: 1000, interval: 100, window: 100, - httpTimeout: 70 + httpTimeout: 70, }; - httpServer = http.createServer().on('request', function(req, res) { + httpServer = http.createServer().on('request', function (req, res) { // make it a slow response, longer than the httpTimeout - setTimeout(function() { + setTimeout(function () { res.end('data'); }, 90); }); httpServer.listen(8125, 'localhost'); - waitOn(opts, function(err) { + waitOn(opts, function (err) { expect(err).toExist(); done(); }); }); - it('should timeout when an http GET resource is not available', function(done) { + it('should timeout when followRedirect is false and http resource redirects', function (done) { + var opts = { + timeout: 1000, + interval: 100, + window: 100, + followRedirect: false, + resources: ['http://localhost:3000'], + }; + + httpServer = http.createServer().on('request', function (req, res) { + const pathname = req.url; + if (pathname === '/') { + res.writeHead(302, { Location: 'http://localhost:3000/foo' }); + } + res.end('data'); + }); + httpServer.listen(3000, 'localhost'); + + waitOn(opts, function (err) { + expect(err).toExist(); + done(); + }); + }); + + it('should timeout when an http GET resource is not available', function (done) { var opts = { resources: ['http-get://localhost:3010'], timeout: 1000, interval: 100, - window: 100 + window: 100, }; - waitOn(opts, function(err) { + waitOn(opts, function (err) { expect(err).toExist(); done(); }); }); - it('should timeout when an https resource is not available', function(done) { + it('should timeout when an https resource is not available', function (done) { var opts = { resources: ['https://localhost:3010/foo/bar'], timeout: 1000, interval: 100, - window: 100 + window: 100, }; - waitOn(opts, function(err) { + waitOn(opts, function (err) { expect(err).toExist(); done(); }); }); - it('should timeout when an https GET resource is not available', function(done) { + it('should timeout when an https GET resource is not available', function (done) { var opts = { resources: ['https-get://localhost:3010/foo/bar'], timeout: 1000, interval: 100, - window: 100 + window: 100, }; - waitOn(opts, function(err) { + waitOn(opts, function (err) { expect(err).toExist(); done(); }); }); - it('should timeout when a service is not listening to tcp port', function(done) { + it('should timeout when followRedirect is false and http GET resource redirects', function (done) { + var opts = { + timeout: 1000, + interval: 100, + window: 100, + followRedirect: false, + resources: ['http-get://localhost:3000'], + }; + + httpServer = http.createServer().on('request', function (req, res) { + const pathname = req.url; + if (pathname === '/') { + res.writeHead(302, { Location: 'http://localhost:3000/foo' }); + } + res.end('data'); + }); + httpServer.listen(3000, 'localhost'); + + waitOn(opts, function (err) { + expect(err).toExist(); + done(); + }); + }); + + it('should timeout when a service is not listening to tcp port', function (done) { var opts = { resources: ['tcp:localhost:3010'], - timeout: 1000 + timeout: 1000, }; - waitOn(opts, function(err) { + waitOn(opts, function (err) { expect(err).toExist(); done(); }); }); - it('should timeout when a service is not listening to a socket', function(done) { + it('should timeout when a service is not listening to a socket', function (done) { var socketPath; - temp.mkdir({}, function(err, dirPath) { + temp.mkdir({}, function (err, dirPath) { if (err) return done(err); socketPath = path.resolve(dirPath, 'sock'); var opts = { resources: ['socket:' + socketPath], timeout: 1000, interval: 100, - window: 100 + window: 100, }; - waitOn(opts, function(err) { + waitOn(opts, function (err) { expect(err).toExist(); done(); }); }); }); - it('should timeout when a service host is unreachable', function(done) { + it('should timeout when a service host is unreachable', function (done) { var opts = { resources: ['tcp:256.0.0.1:1234'], timeout: 1000, - tcpTimeout: 1000 + tcpTimeout: 1000, }; - waitOn(opts, function(err) { + waitOn(opts, function (err) { expect(err).toExist(); done(); }); }); - it('should timeout when an http service listening to a socket returns 404', function(done) { + it('should timeout when an http service listening to a socket returns 404', function (done) { var socketPath; - temp.mkdir({}, function(err, dirPath) { + temp.mkdir({}, function (err, dirPath) { if (err) return done(err); socketPath = path.resolve(dirPath, 'sock'); var opts = { resources: ['http://unix:' + socketPath + ':/', 'http://unix:' + socketPath + ':/foo'], timeout: 1000, interval: 100, - window: 100 + window: 100, }; - setTimeout(function() { - httpServer = http.createServer().on('request', function(req, res) { + setTimeout(function () { + httpServer = http.createServer().on('request', function (req, res) { res.statusCode = 404; res.end('data'); }); httpServer.listen(socketPath); }, 300); - waitOn(opts, function(err) { + waitOn(opts, function (err) { expect(err).toExist(); done(); }); }); }); - it('should timeout when an http service listening to a socket is too slow', function(done) { + it('should timeout when an http service listening to a socket is too slow', function (done) { var socketPath; - temp.mkdir({}, function(err, dirPath) { + temp.mkdir({}, function (err, dirPath) { if (err) return done(err); socketPath = path.resolve(dirPath, 'sock'); var opts = { 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) { - setTimeout(function() { + httpServer = http.createServer().on('request', function (req, res) { + setTimeout(function () { // res.statusCode = 404; res.end('data'); }, 1100); }); httpServer.listen(socketPath); - waitOn(opts, function(err) { + waitOn(opts, function (err) { expect(err).toExist(); done(); }); }); }); - it('should succeed when a service host is unreachable in reverse mode', function(done) { + it('should succeed when a service host is unreachable in reverse mode', function (done) { var opts = { resources: ['tcp:256.0.0.1:1234'], interval: 100, timeout: 1000, tcpTimeout: 1000, reverse: true, - window: 100 + window: 100, }; - waitOn(opts, function(err) { + waitOn(opts, function (err) { if (err) return done(err); expect(err).toNotExist(); done(); }); }); - it('should succeed when file resources are not available in reverse mode', function(done) { - temp.mkdir({}, function(err, dirPath) { + it('should succeed when file resources are not available in reverse mode', function (done) { + temp.mkdir({}, function (err, dirPath) { if (err) return done(err); var opts = { resources: [path.resolve(dirPath, 'foo'), path.resolve(dirPath, 'bar')], - reverse: true + reverse: true, }; - waitOn(opts, function(err) { + waitOn(opts, function (err) { expect(err).toNotExist(); done(); }); }); }); - it('should succeed when file resources are not available later in reverse mode', function(done) { - temp.mkdir({}, function(err, dirPath) { + it('should succeed when file resources are not available later in reverse mode', function (done) { + temp.mkdir({}, function (err, dirPath) { if (err) return done(err); var 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'); - setTimeout(function() { + setTimeout(function () { fs.unlinkSync(opts.resources[0]); fs.unlinkSync(opts.resources[1]); }, 300); - waitOn(opts, function(err) { + waitOn(opts, function (err) { expect(err).toNotExist(); done(); }); }); }); - it('should timeout when file resources are available in reverse mode', function(done) { - temp.mkdir({}, function(err, dirPath) { + it('should timeout when file resources are available in reverse mode', function (done) { + temp.mkdir({}, function (err, dirPath) { if (err) return done(err); var 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'); - waitOn(opts, function(err) { + waitOn(opts, function (err) { expect(err).toExist(); done(); }); }); }); - describe('promise support', function() { - it('should succeed when file resources are available', function(done) { - temp.mkdir({}, function(err, dirPath) { + describe('promise support', function () { + it('should succeed when file resources are available', function (done) { + temp.mkdir({}, function (err, dirPath) { if (err) return done(err); var 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'); waitOn(opts) - .then(function() { + .then(function () { done(); }) - .catch(function(err) { + .catch(function (err) { done(err); }); }); }); - it('should succeed when file resources are become available later', function(done) { - temp.mkdir({}, function(err, dirPath) { + it('should succeed when file resources are become available later', function (done) { + temp.mkdir({}, function (err, dirPath) { if (err) return done(err); var opts = { - resources: [path.resolve(dirPath, 'foo'), path.resolve(dirPath, 'bar')] + resources: [path.resolve(dirPath, 'foo'), path.resolve(dirPath, 'bar')], }; - setTimeout(function() { - fs.writeFile(opts.resources[0], 'data1', function() {}); - fs.writeFile(opts.resources[1], 'data2', function() {}); + setTimeout(function () { + fs.writeFile(opts.resources[0], 'data1', function () {}); + fs.writeFile(opts.resources[1], 'data2', function () {}); }, 300); waitOn(opts) - .then(function() { + .then(function () { done(); }) - .catch(function(err) { + .catch(function (err) { done(err); }); }); }); - it('should timeout when all resources are not available and timout option is specified', function(done) { - temp.mkdir({}, function(err, dirPath) { + it('should timeout when all resources are not available and timout option is specified', function (done) { + temp.mkdir({}, function (err, dirPath) { if (err) return done(err); var opts = { resources: [path.resolve(dirPath, 'foo')], - timeout: 1000 + timeout: 1000, }; waitOn(opts) - .then(function() { + .then(function () { done(new Error('Should not be resolved')); }) - .catch(function(err) { + .catch(function (err) { expect(err).toExist(); done(); }); }); }); - it('should timeout when some resources are not available and timout option is specified', function(done) { - temp.mkdir({}, function(err, dirPath) { + it('should timeout when some resources are not available and timout option is specified', function (done) { + temp.mkdir({}, function (err, dirPath) { if (err) return done(err); var opts = { resources: [path.resolve(dirPath, 'foo'), path.resolve(dirPath, 'bar')], - timeout: 1000 + timeout: 1000, }; - fs.writeFile(opts.resources[0], 'data', function() {}); + fs.writeFile(opts.resources[0], 'data', function () {}); waitOn(opts) - .then(function() { + .then(function () { done(new Error('Should not be resolved')); }) - .catch(function(err) { + .catch(function (err) { expect(err).toExist(); done(); }); }); }); - it('should succeed when file resources are not available in reverse mode', function(done) { - temp.mkdir({}, function(err, dirPath) { + it('should succeed when file resources are not available in reverse mode', function (done) { + temp.mkdir({}, function (err, dirPath) { if (err) return done(err); var opts = { resources: [path.resolve(dirPath, 'foo'), path.resolve(dirPath, 'bar')], - reverse: true + reverse: true, }; waitOn(opts) - .then(function() { + .then(function () { done(); }) - .catch(function(err) { + .catch(function (err) { done(err); }); }); }); - it('should succeed when file resources are not available later in reverse mode', function(done) { - temp.mkdir({}, function(err, dirPath) { + it('should succeed when file resources are not available later in reverse mode', function (done) { + temp.mkdir({}, function (err, dirPath) { if (err) return done(err); var 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'); - setTimeout(function() { + setTimeout(function () { fs.unlinkSync(opts.resources[0]); fs.unlinkSync(opts.resources[1]); }, 300); waitOn(opts) - .then(function() { + .then(function () { done(); }) - .catch(function(err) { + .catch(function (err) { done(err); }); }); }); - it('should timeout when file resources are available in reverse mode', function(done) { - temp.mkdir({}, function(err, dirPath) { + it('should timeout when file resources are available in reverse mode', function (done) { + temp.mkdir({}, function (err, dirPath) { if (err) return done(err); var 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'); waitOn(opts) - .then(function() { + .then(function () { done(new Error('Should not be resolved')); }) - .catch(function(err) { + .catch(function (err) { expect(err).toExist(); done(); }); diff --git a/test/cli.mocha.js b/test/cli.mocha.js index 27d74e4..ba5e9c4 100644 --- a/test/cli.mocha.js +++ b/test/cli.mocha.js @@ -24,11 +24,11 @@ function execCLI(args, options) { var FAST_OPTS = '-t 1000 -i 100 -w 100'.split(' '); -describe('cli', function() { +describe('cli', function () { this.timeout(3000); var httpServer = null; - afterEach(function(done) { + afterEach(function (done) { if (httpServer) { httpServer.close(); httpServer = null; @@ -36,74 +36,118 @@ describe('cli', function() { done(); }); - it('should succeed when file resources are available', function(done) { - temp.mkdir({}, function(err, dirPath) { + it('should succeed when file resources are available', function (done) { + temp.mkdir({}, function (err, dirPath) { if (err) return done(err); var 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])); fs.writeFileSync(opts.resources[1], 'data2'); - execCLI(opts.resources.concat(FAST_OPTS), {}).on('exit', function(code) { + execCLI(opts.resources.concat(FAST_OPTS), {}).on('exit', function (code) { expect(code).toBe(0); done(); }); }); }); - it('should succeed when file resources are become available later', function(done) { - temp.mkdir({}, function(err, dirPath) { + it('should succeed when file resources are become available later', function (done) { + temp.mkdir({}, function (err, dirPath) { if (err) return done(err); var 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() { - fs.writeFile(opts.resources[0], 'data1', function() {}); + setTimeout(function () { + fs.writeFile(opts.resources[0], 'data1', function () {}); mkdirp.sync(path.dirname(opts.resources[1])); - fs.writeFile(opts.resources[1], 'data2', function() {}); + fs.writeFile(opts.resources[1], 'data2', function () {}); }, 300); - execCLI(opts.resources.concat(FAST_OPTS), {}).on('exit', function(code) { + execCLI(opts.resources.concat(FAST_OPTS), {}).on('exit', function (code) { expect(code).toBe(0); done(); }); }); }); - it('should succeed when http resources become available later', function(done) { + it('should succeed when http resources become available later', function (done) { var opts = { - resources: ['http://localhost:8123', 'http://localhost:8123/foo'] + resources: ['http://localhost:8123', 'http://localhost:8123/foo'], }; - setTimeout(function() { - httpServer = http.createServer().on('request', function(req, res) { + setTimeout(function () { + httpServer = http.createServer().on('request', function (req, res) { res.end('data'); }); httpServer.listen(8123, 'localhost'); }, 300); - execCLI(opts.resources.concat(FAST_OPTS), {}).on('exit', function(code) { + execCLI(opts.resources.concat(FAST_OPTS), {}).on('exit', function (code) { expect(code).toBe(0); done(); }); }); - it('should succeed when http GET resources become available later', function(done) { + it('should succeed when http resources become available later via redirect', function (done) { var opts = { - resources: ['http-get://localhost:8124', 'http-get://localhost:8124/foo'] + resources: ['http://localhost:8123'], }; - setTimeout(function() { - httpServer = http.createServer().on('request', function(req, res) { + setTimeout(function () { + httpServer = http.createServer().on('request', function (req, res) { + const pathname = req.url; + if (pathname === '/') { + res.writeHead(302, { Location: 'http://localhost:8123/foo' }); + } + res.end('data'); + }); + httpServer.listen(8123, 'localhost'); + }, 300); + + execCLI(opts.resources.concat(FAST_OPTS), {}).on('exit', function (code) { + expect(code).toBe(0); + done(); + }); + }); + + it('should succeed when http GET resources become available later', function (done) { + var opts = { + resources: ['http-get://localhost:8124', 'http-get://localhost:8124/foo'], + }; + + setTimeout(function () { + httpServer = http.createServer().on('request', function (req, res) { res.end('data'); }); httpServer.listen(8124, 'localhost'); }, 300); - execCLI(opts.resources.concat(FAST_OPTS), {}).on('exit', function(code) { + execCLI(opts.resources.concat(FAST_OPTS), {}).on('exit', function (code) { + expect(code).toBe(0); + done(); + }); + }); + + it('should succeed when http GET resources become available later via redirect', function (done) { + var opts = { + resources: ['http-get://localhost:8124'], + }; + + setTimeout(function () { + httpServer = http.createServer().on('request', function (req, res) { + const pathname = req.url; + if (pathname === '/') { + res.writeHead(302, { Location: 'http://localhost:8124/foo' }); + } + res.end('data'); + }); + httpServer.listen(8124, 'localhost'); + }, 300); + + execCLI(opts.resources.concat(FAST_OPTS), {}).on('exit', function (code) { expect(code).toBe(0); done(); }); @@ -125,85 +169,85 @@ describe('cli', function() { }); */ - it('should succeed when a service is listening to tcp port', function(done) { + it('should succeed when a service is listening to tcp port', function (done) { var opts = { - resources: ['tcp:localhost:3030', 'tcp:3030'] + resources: ['tcp:localhost:3030', 'tcp:3030'], }; - setTimeout(function() { - httpServer = http.createServer().on('request', function(req, res) { + setTimeout(function () { + httpServer = http.createServer().on('request', function (req, res) { res.end('data'); }); httpServer.listen(3030, 'localhost'); }, 300); - execCLI(opts.resources.concat(FAST_OPTS), {}).on('exit', function(code) { + execCLI(opts.resources.concat(FAST_OPTS), {}).on('exit', function (code) { expect(code).toBe(0); done(); }); }); - it('should succeed when a service is listening to a socket', function(done) { + it('should succeed when a service is listening to a socket', function (done) { var socketPath; - temp.mkdir({}, function(err, dirPath) { + temp.mkdir({}, function (err, dirPath) { if (err) return done(err); socketPath = path.resolve(dirPath, 'sock'); var opts = { - resources: ['socket:' + socketPath] + resources: ['socket:' + socketPath], }; - setTimeout(function() { + setTimeout(function () { httpServer = http.createServer(); httpServer.listen(socketPath); }, 300); - execCLI(opts.resources.concat(FAST_OPTS), {}).on('exit', function(code) { + execCLI(opts.resources.concat(FAST_OPTS), {}).on('exit', function (code) { expect(code).toBe(0); done(); }); }); }); - it('should succeed when a http service is listening to a socket', function(done) { + it('should succeed when a http service is listening to a socket', function (done) { var socketPath; - temp.mkdir({}, function(err, dirPath) { + temp.mkdir({}, function (err, dirPath) { if (err) return done(err); socketPath = path.resolve(dirPath, 'sock'); var opts = { - resources: ['http://unix:' + socketPath + ':/', 'http://unix:' + socketPath + ':/foo'] + resources: ['http://unix:' + socketPath + ':/', 'http://unix:' + socketPath + ':/foo'], }; - setTimeout(function() { - httpServer = http.createServer().on('request', function(req, res) { + setTimeout(function () { + httpServer = http.createServer().on('request', function (req, res) { res.end('data'); }); httpServer.listen(socketPath); }, 300); - execCLI(opts.resources.concat(FAST_OPTS), {}).on('exit', function(code) { + execCLI(opts.resources.concat(FAST_OPTS), {}).on('exit', function (code) { expect(code).toBe(0); done(); }); }); }); - it('should succeed when a http GET service is listening to a socket', function(done) { + it('should succeed when a http GET service is listening to a socket', function (done) { var socketPath; - temp.mkdir({}, function(err, dirPath) { + temp.mkdir({}, function (err, dirPath) { if (err) return done(err); socketPath = path.resolve(dirPath, 'sock'); var opts = { - resources: ['http-get://unix:' + socketPath + ':/', 'http-get://unix:' + socketPath + ':/foo'] + resources: ['http-get://unix:' + socketPath + ':/', 'http-get://unix:' + socketPath + ':/foo'], }; - setTimeout(function() { - httpServer = http.createServer().on('request', function(req, res) { + setTimeout(function () { + httpServer = http.createServer().on('request', function (req, res) { res.end('data'); }); httpServer.listen(socketPath); }, 300); - execCLI(opts.resources.concat(FAST_OPTS), {}).on('exit', function(code) { + execCLI(opts.resources.concat(FAST_OPTS), {}).on('exit', function (code) { expect(code).toBe(0); done(); }); @@ -212,86 +256,86 @@ describe('cli', function() { // Error situations - it('should timeout when all resources are not available and timout option is specified', function(done) { - temp.mkdir({}, function(err, dirPath) { + it('should timeout when all resources are not available and timout option is specified', function (done) { + temp.mkdir({}, function (err, dirPath) { if (err) return done(err); var 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) { + execCLI(opts.resources.concat(FAST_OPTS), {}).on('exit', function (code) { expect(code).toNotBe(0); done(); }); }); }); - it('should timeout when some resources are not available and timout option is specified', function(done) { - temp.mkdir({}, function(err, dirPath) { + it('should timeout when some resources are not available and timout option is specified', function (done) { + temp.mkdir({}, function (err, dirPath) { if (err) return done(err); var opts = { resources: [path.resolve(dirPath, 'foo'), path.resolve(dirPath, 'bar')], - timeout: 1000 + timeout: 1000, }; - fs.writeFile(opts.resources[0], 'data', function() {}); + fs.writeFile(opts.resources[0], 'data', function () {}); // timeout is in FAST_OPTS - execCLI(opts.resources.concat(FAST_OPTS), {}).on('exit', function(code) { + execCLI(opts.resources.concat(FAST_OPTS), {}).on('exit', function (code) { expect(code).toNotBe(0); done(); }); }); }); - it('should timeout when an http resource returns 404', function(done) { + it('should timeout when an http resource returns 404', function (done) { var opts = { resources: ['http://localhost:3998'], timeout: 1000, interval: 100, - window: 100 + window: 100, }; - setTimeout(function() { - httpServer = http.createServer().on('request', function(req, res) { + setTimeout(function () { + httpServer = http.createServer().on('request', function (req, res) { res.statusCode = 404; res.end('data'); }); httpServer.listen(3998, 'localhost'); }, 300); // timeout, interval, window are in FAST_OPTS - execCLI(opts.resources.concat(FAST_OPTS), {}).on('exit', function(code) { + execCLI(opts.resources.concat(FAST_OPTS), {}).on('exit', function (code) { expect(code).toNotBe(0); done(); }); }); - it('should timeout when an http resource is not available', function(done) { + it('should timeout when an http resource is not available', function (done) { var opts = { resources: ['http://localhost:3999'], timeout: 1000, interval: 100, - window: 100 + window: 100, }; // timeout is in FAST_OPTS - execCLI(opts.resources.concat(FAST_OPTS), {}).on('exit', function(code) { + execCLI(opts.resources.concat(FAST_OPTS), {}).on('exit', function (code) { expect(code).toNotBe(0); done(); }); }); - it('should timeout when an http resource does not respond before httpTimeout', function(done) { + it('should timeout when an http resource does not respond before httpTimeout', function (done) { var opts = { resources: ['http://localhost:8125'], timeout: 1000, interval: 100, window: 100, - httpTimeout: 70 + httpTimeout: 70, }; - httpServer = http.createServer().on('request', function(req, res) { + httpServer = http.createServer().on('request', function (req, res) { // make it a slow response, longer than the httpTimeout - setTimeout(function() { + setTimeout(function () { res.end('data'); }, 90); }); @@ -299,119 +343,119 @@ describe('cli', function() { var addOpts = '--httpTimeout 70'.split(' '); // timeout, interval, and window are in FAST_OPTS - execCLI(opts.resources.concat(FAST_OPTS).concat(addOpts), {}).on('exit', function(code) { + execCLI(opts.resources.concat(FAST_OPTS).concat(addOpts), {}).on('exit', function (code) { expect(code).toNotBe(0); done(); }); }); - it('should timeout when an http GET resource is not available', function(done) { + it('should timeout when an http GET resource is not available', function (done) { var opts = { resources: ['http-get://localhost:3999'], timeout: 1000, interval: 100, - window: 100 + window: 100, }; // timeout, interval, window are in FAST_OPTS - execCLI(opts.resources.concat(FAST_OPTS), {}).on('exit', function(code) { + execCLI(opts.resources.concat(FAST_OPTS), {}).on('exit', function (code) { expect(code).toNotBe(0); done(); }); }); - it('should timeout when an https resource is not available', function(done) { + it('should timeout when an https resource is not available', function (done) { var opts = { resources: ['https://localhost:3010/foo/bar'], timeout: 1000, interval: 100, - window: 100 + window: 100, }; // timeout, interval, window are in FAST_OPTS - execCLI(opts.resources.concat(FAST_OPTS), {}).on('exit', function(code) { + execCLI(opts.resources.concat(FAST_OPTS), {}).on('exit', function (code) { expect(code).toNotBe(0); done(); }); }); - it('should timeout when an https GET resource is not available', function(done) { + it('should timeout when an https GET resource is not available', function (done) { var opts = { resources: ['https-get://localhost:3010/foo/bar'], timeout: 1000, interval: 100, - window: 100 + window: 100, }; // timeout, interval, window are in FAST_OPTS - execCLI(opts.resources.concat(FAST_OPTS), {}).on('exit', function(code) { + execCLI(opts.resources.concat(FAST_OPTS), {}).on('exit', function (code) { expect(code).toNotBe(0); done(); }); }); - it('should timeout when a service is not listening to tcp port', function(done) { + it('should timeout when a service is not listening to tcp port', function (done) { var opts = { resources: ['tcp:localhost:3010'], - timeout: 1000 + timeout: 1000, }; // timeout is in FAST_OPTS - execCLI(opts.resources.concat(FAST_OPTS), {}).on('exit', function(code) { + execCLI(opts.resources.concat(FAST_OPTS), {}).on('exit', function (code) { expect(code).toNotBe(0); done(); }); }); - it('should timeout when a service host is unreachable', function(done) { + it('should timeout when a service host is unreachable', function (done) { var opts = { resources: ['tcp:256.0.0.1:1234'], timeout: 1000, - tcpTimeout: 1000 + tcpTimeout: 1000, }; var addOpts = '--tcpTimeout 1000'.split(' '); // timeout is in FAST_OPTS - execCLI(opts.resources.concat(FAST_OPTS).concat(addOpts), {}).on('exit', function(code) { + execCLI(opts.resources.concat(FAST_OPTS).concat(addOpts), {}).on('exit', function (code) { expect(code).toNotBe(0); done(); }); }); - it('should timeout when a service is not listening to a socket', function(done) { + it('should timeout when a service is not listening to a socket', function (done) { var socketPath; - temp.mkdir({}, function(err, dirPath) { + temp.mkdir({}, function (err, dirPath) { if (err) return done(err); socketPath = path.resolve(dirPath, 'sock'); var opts = { resources: ['socket:' + socketPath], timeout: 1000, interval: 100, - window: 100 + window: 100, }; // timeout, interval, window are in FAST_OPTS - execCLI(opts.resources.concat(FAST_OPTS), {}).on('exit', function(code) { + execCLI(opts.resources.concat(FAST_OPTS), {}).on('exit', function (code) { expect(code).toNotBe(0); done(); }); }); }); - it('should timeout when an http service listening to a socket returns 404', function(done) { + it('should timeout when an http service listening to a socket returns 404', function (done) { var socketPath; - temp.mkdir({}, function(err, dirPath) { + temp.mkdir({}, function (err, dirPath) { if (err) return done(err); socketPath = path.resolve(dirPath, 'sock'); var opts = { resources: ['http://unix:' + socketPath + ':/', 'http://unix:' + socketPath + ':/foo'], timeout: 1000, interval: 100, - window: 100 + window: 100, }; - setTimeout(function() { - httpServer = http.createServer().on('request', function(req, res) { + setTimeout(function () { + httpServer = http.createServer().on('request', function (req, res) { res.statusCode = 404; res.end('data'); }); @@ -419,72 +463,72 @@ describe('cli', function() { }, 300); // timeout, interval, window are in FAST_OPTS - execCLI(opts.resources.concat(FAST_OPTS), {}).on('exit', function(code) { + execCLI(opts.resources.concat(FAST_OPTS), {}).on('exit', function (code) { expect(code).toNotBe(0); done(); }); }); }); - it('should succeed when file resources are not available in reverse mode', function(done) { - temp.mkdir({}, function(err, dirPath) { + it('should succeed when file resources are not available in reverse mode', function (done) { + temp.mkdir({}, function (err, dirPath) { if (err) return done(err); var opts = { - resources: [path.resolve(dirPath, 'foo'), path.resolve(dirPath, 'bar')] + resources: [path.resolve(dirPath, 'foo'), path.resolve(dirPath, 'bar')], }; var OPTS = FAST_OPTS.concat(['-r']); - execCLI(opts.resources.concat(OPTS), {}).on('exit', function(code) { + execCLI(opts.resources.concat(OPTS), {}).on('exit', function (code) { expect(code).toBe(0); done(); }); }); }); - it('should succeed when file resources are not available later in reverse mode', function(done) { - temp.mkdir({}, function(err, dirPath) { + it('should succeed when file resources are not available later in reverse mode', function (done) { + temp.mkdir({}, function (err, dirPath) { if (err) return done(err); var 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'); - setTimeout(function() { + setTimeout(function () { fs.unlinkSync(opts.resources[0]); fs.unlinkSync(opts.resources[1]); }, 300); var OPTS = FAST_OPTS.concat(['-r']); - execCLI(opts.resources.concat(OPTS), {}).on('exit', function(code) { + execCLI(opts.resources.concat(OPTS), {}).on('exit', function (code) { expect(code).toBe(0); done(); }); }); }); - it('should timeout when file resources are available in reverse mode', function(done) { - temp.mkdir({}, function(err, dirPath) { + it('should timeout when file resources are available in reverse mode', function (done) { + temp.mkdir({}, function (err, dirPath) { if (err) return done(err); var 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'); var OPTS = FAST_OPTS.concat(['-r']); - execCLI(opts.resources.concat(OPTS), {}).on('exit', function(code) { + execCLI(opts.resources.concat(OPTS), {}).on('exit', function (code) { expect(code).toNotBe(0); done(); }); }); }); - it('should succeed when a service host is unreachable in reverse mode', function(done) { + it('should succeed when a service host is unreachable in reverse mode', function (done) { var opts = { resources: ['tcp:256.0.0.1:1234'], timeout: 1000, - tcpTimeout: 1000 + tcpTimeout: 1000, }; // timeout is in FAST_OPTS var OPTS = FAST_OPTS.concat(['-r', '--tcpTimeout', '1000']); - execCLI(opts.resources.concat(OPTS), {}).on('exit', function(code) { + execCLI(opts.resources.concat(OPTS), {}).on('exit', function (code) { expect(code).toBe(0); done(); });