From 4967736160964a63c8296cd038ffb8767ef998b8 Mon Sep 17 00:00:00 2001 From: Lance Ball Date: Mon, 29 Apr 2019 15:08:40 -0400 Subject: [PATCH] build: switch to standardx for linting --- .eslintrc.json | 12 +- index.js | 52 ++++----- lib/circuit.js | 3 +- lib/status.js | 5 +- package-lock.json | 202 +++++++++++++++++----------------- package.json | 4 +- test/common.js | 2 + test/error-filter-test.js | 1 - test/test.js | 18 +-- test/volume-threshold-test.js | 6 +- 10 files changed, 165 insertions(+), 140 deletions(-) diff --git a/.eslintrc.json b/.eslintrc.json index 6ad1967a..95e9bbad 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -1,5 +1,9 @@ { - "extends": "semistandard", + "extends": "eslint:recommended", + "env": { + "es6": true, + "node": true + }, "rules": { "standard/no-callback-literal": "off", "arrow-spacing": "error", @@ -7,6 +11,12 @@ "arrow-body-style": ["error", "as-needed"], "prefer-template": "error", "max-len": ["warn", { "code": 80 }], + "no-unused-vars": ["warn", { + "argsIgnorePattern": "^_$|^e$|^reject$|^resolve$" + }], + "no-console": ["error", { + "allow": ["warn", "error"] + }], "valid-jsdoc": "error" } diff --git a/index.js b/index.js index 02164c12..58382842 100644 --- a/index.js +++ b/index.js @@ -15,34 +15,37 @@ const defaults = { * @param {Object} options Options for the {@link CircuitBreaker} * @param {Number} options.timeout The time in milliseconds that action should * be allowed to execute before timing out. Default 10000 (10 seconds) - * @param {Number} options.maxFailures The number of times the circuit can fail before - * opening. Default 10. - * @param {Number} options.resetTimeout The time in milliseconds to wait before setting - * the breaker to `halfOpen` state, and trying the action again. - * @param {Number} options.rollingCountTimeout Sets the duration of the statistical rolling - * window, in milliseconds. This is how long Opossum keeps metrics for the circuit - * breaker to use and for publishing. Default: 10000 - * @param {Number} options.rollingCountBuckets Sets the number of buckets the rolling - * statistical window is divided into. So, if options.rollingCountTimeout is - * 10000, and options.rollingCountBuckets is 10, then the statistical window will - * be 1000 1 second snapshots in the statistical window. Default: 10 + * @param {Number} options.maxFailures The number of times the circuit can fail + * before opening. Default 10. + * @param {Number} options.resetTimeout The time in milliseconds to wait before + * setting the breaker to `halfOpen` state, and trying the action again. + * @param {Number} options.rollingCountTimeout Sets the duration of the + * statistical rolling window, in milliseconds. This is how long Opossum keeps + * metrics for the circuit breaker to use and for publishing. Default: 10000 + * @param {Number} options.rollingCountBuckets Sets the number of buckets the + * rolling statistical window is divided into. So, if + * options.rollingCountTimeout is 10000, and options.rollingCountBuckets is 10, + * then the statistical window will be 1000 1 second snapshots in the + * statistical window. Default: 10 * @param {String} options.name the circuit name to use when reporting stats - * @param {boolean} options.rollingPercentilesEnabled This property indicates whether - * execution latencies should be tracked and calculated as percentiles. If they - * are disabled, all summary statistics (mean, percentiles) are returned as -1. - * Default: false - * @param {Number} options.capacity the number of concurrent requests allowed. If the number - * currently executing function calls is equal to options.capacity, further calls - * to `fire()` are rejected until at least one of the current requests completes. - * @param {Number} options.errorThresholdPercentage the error percentage at which to open the - * circuit and start short-circuiting requests to fallback. - * @param {boolean} options.enabled whether this circuit is enabled upon construction. Default: true + * @param {boolean} options.rollingPercentilesEnabled This property indicates + * whether execution latencies should be tracked and calculated as percentiles. + * If they are disabled, all summary statistics (mean, percentiles) are + * returned as -1. Default: false + * @param {Number} options.capacity the number of concurrent requests allowed. + * If the number currently executing function calls is equal to + * options.capacity, further calls to `fire()` are rejected until at least one + * of the current requests completes. + * @param {Number} options.errorThresholdPercentage the error percentage at + * which to open the circuit and start short-circuiting requests to fallback. + * @param {boolean} options.enabled whether this circuit is enabled upon + * construction. Default: true * @param {boolean} options.allowWarmUp determines whether to allow failures * without opening the circuit during a brief warmup period (this is the * `rollingCountDuration` property). Default: false - * allow before enabling the circuit. This can help in situations where no matter - * what your `errorThresholdPercentage` is, if the first execution times out or - * fails, the circuit immediately opens. Default: 0 + * allow before enabling the circuit. This can help in situations where no + * matter what your `errorThresholdPercentage` is, if the first execution + * times out or fails, the circuit immediately opens. Default: 0 * @param {Number} options.volumeThreshold the minimum number of requests within * the rolling statistical window that must exist before the circuit breaker * can open. This is similar to `options.allowWarmUp` in that no matter how many @@ -68,7 +71,6 @@ function factory (action, options) { * @function factory.promisify * * @param {Function} action A Node.js-like asynchronous function - * @return {Function} The `action` wrapped in a promise API. * @example * const fs = require('fs'); * const readFilePromised = circuitBreaker.promisify(fs.readFile); diff --git a/lib/circuit.js b/lib/circuit.js index 3e468955..5836f940 100644 --- a/lib/circuit.js +++ b/lib/circuit.js @@ -586,7 +586,8 @@ function handleError (error, circuit, timeout, args, latency, resolve, reject) { function fallback (circuit, err, args) { if (circuit[FALLBACK_FUNCTION]) { const result = - circuit[FALLBACK_FUNCTION].apply(circuit[FALLBACK_FUNCTION], [...args, err]); + circuit[FALLBACK_FUNCTION] + .apply(circuit[FALLBACK_FUNCTION], [...args, err]); /** * Emitted when the circuit breaker executes a fallback function * @event CircuitBreaker#fallback diff --git a/lib/status.js b/lib/status.js index 4f51fc95..e6176249 100644 --- a/lib/status.js +++ b/lib/status.js @@ -26,9 +26,10 @@ const EventEmitter = require('events').EventEmitter; * @class Status * @extends EventEmitter * @param {Object} options for the status window - * @param {Number} options.rollingCountBuckets the number of buckets in the window + * @param {Number} options.rollingCountBuckets number of buckets in the window * @param {Number} options.rollingCountTimeout the duration of the window - * @param {Boolean} options.rollingPercentilesEnabled whether to calculate percentiles + * @param {Boolean} options.rollingPercentilesEnabled whether to calculate + * percentiles * @example * // Creates a 1 second window consisting of ten time slices, * // each 100ms long. diff --git a/package-lock.json b/package-lock.json index 9950e050..5ea5725d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1454,9 +1454,9 @@ "dev": true }, "ansi-escapes": { - "version": "3.1.0", - "resolved": "https://registry.npmjs.org/ansi-escapes/-/ansi-escapes-3.1.0.tgz", - "integrity": "sha512-UgAb8H9D41AQnu/PbWlCofQVcnV4Gs2bBJi9eZPxfU/hgglFh3SMDMENRIqdr7H6XFnXdoknctFByVsCOotTVw==", + "version": "3.2.0", + "resolved": "https://registry.npmjs.org/ansi-escapes/-/ansi-escapes-3.2.0.tgz", + "integrity": "sha512-cBhpre4ma+U0T1oM5fXg7Dy1Jw7zzwv7lt/GoCpr+hDQJoYnKVPLL4dCvSEFMmQurOQvSrwT7SL/DAlhBI97RQ==", "dev": true }, "ansi-html": { @@ -3221,23 +3221,23 @@ "dev": true }, "deglob": { - "version": "3.1.0", - "resolved": "https://registry.npmjs.org/deglob/-/deglob-3.1.0.tgz", - "integrity": "sha512-al10l5QAYaM/PeuXkAr1Y9AQz0LCtWsnJG23pIgh44hDxHFOj36l6qvhfjnIWBYwZOqM1fXUFV9tkjL7JPdGvw==", + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/deglob/-/deglob-2.1.1.tgz", + "integrity": "sha512-2kjwuGGonL7gWE1XU4Fv79+vVzpoQCl0V+boMwWtOQJV2AGDabCwez++nB1Nli/8BabAfZQ/UuHPlp6AymKdWw==", "dev": true, "requires": { "find-root": "^1.0.0", "glob": "^7.0.5", - "ignore": "^5.0.0", + "ignore": "^3.0.9", "pkg-config": "^1.1.0", "run-parallel": "^1.1.2", "uniq": "^1.0.1" }, "dependencies": { "ignore": { - "version": "5.0.4", - "resolved": "https://registry.npmjs.org/ignore/-/ignore-5.0.4.tgz", - "integrity": "sha512-WLsTMEhsQuXpCiG173+f3aymI43SXa+fB1rSfbzyP4GkPP+ZFVuO0/3sFUGNBtifisPeDcl/uD/Y2NxZ7xFq4g==", + "version": "3.3.10", + "resolved": "https://registry.npmjs.org/ignore/-/ignore-3.3.10.tgz", + "integrity": "sha512-Pgs951kaMm5GXP7MOvxERINe3gsaVjUWFm+UZPSq9xYriQAksyhg0csnS0KXSNRD5NmNdapXEpjxG49+AKh/ug==", "dev": true } } @@ -3879,19 +3879,6 @@ "supports-color": "^5.3.0" } }, - "cross-spawn": { - "version": "6.0.5", - "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-6.0.5.tgz", - "integrity": "sha512-eTVLrBSt7fjbDygz805pMnstIs2VTBNkRm0qxZd+M7A5XDdxVRWO5MxGBXZhjY4cqLYLdtrGqRf8mBPmzwSpWQ==", - "dev": true, - "requires": { - "nice-try": "^1.0.4", - "path-key": "^2.0.1", - "semver": "^5.5.0", - "shebang-command": "^1.2.0", - "which": "^1.2.9" - } - }, "debug": { "version": "3.2.6", "resolved": "https://registry.npmjs.org/debug/-/debug-3.2.6.tgz", @@ -3908,9 +3895,9 @@ "dev": true }, "semver": { - "version": "5.6.0", - "resolved": "https://registry.npmjs.org/semver/-/semver-5.6.0.tgz", - "integrity": "sha512-RS9R6R35NYgQn++fkDWaOmqGoj4Ek9gGs+DPxNUZKuwE183xjJroKvyo1IzVFeXvUrvmALy6FWD5xrdJT25gMg==", + "version": "5.7.0", + "resolved": "https://registry.npmjs.org/semver/-/semver-5.7.0.tgz", + "integrity": "sha512-Ya52jSX2u7QKghxeoFGpLwCtGlt7j0oY9DYb5apt9nPlJ42ID+ulTXESnt/qAQcoSERyZ5sl3LDIOw0nAn/5DA==", "dev": true }, "strip-ansi": { @@ -3933,12 +3920,6 @@ } } }, - "eslint-config-semistandard": { - "version": "13.0.0", - "resolved": "https://registry.npmjs.org/eslint-config-semistandard/-/eslint-config-semistandard-13.0.0.tgz", - "integrity": "sha512-ZuImKnf/9LeZjr6dtRJ0zEdQbjBwXu0PJR3wXJXoQeMooICMrYPyD70O1tIA9Ng+wutgLjB7UXvZOKYPvzHg+w==", - "dev": true - }, "eslint-config-standard": { "version": "12.0.0", "resolved": "https://registry.npmjs.org/eslint-config-standard/-/eslint-config-standard-12.0.0.tgz", @@ -3962,9 +3943,9 @@ } }, "eslint-module-utils": { - "version": "2.3.0", - "resolved": "https://registry.npmjs.org/eslint-module-utils/-/eslint-module-utils-2.3.0.tgz", - "integrity": "sha512-lmDJgeOOjk8hObTysjqH7wyMi+nsHwwvfBykwfhjR1LNdd7C2uFJBvx4OpWYpXOw4df1yE1cDEVd1yLHitk34w==", + "version": "2.4.0", + "resolved": "https://registry.npmjs.org/eslint-module-utils/-/eslint-module-utils-2.4.0.tgz", + "integrity": "sha512-14tltLm38Eu3zS+mt0KvILC3q8jyIAH518MlG+HO0p+yK885Lb1UHTY/UgR91eOyGdmxAPb+OLoW4znqIT6Ndw==", "dev": true, "requires": { "debug": "^2.6.8", @@ -4026,9 +4007,9 @@ }, "dependencies": { "semver": { - "version": "5.6.0", - "resolved": "https://registry.npmjs.org/semver/-/semver-5.6.0.tgz", - "integrity": "sha512-RS9R6R35NYgQn++fkDWaOmqGoj4Ek9gGs+DPxNUZKuwE183xjJroKvyo1IzVFeXvUrvmALy6FWD5xrdJT25gMg==", + "version": "5.7.0", + "resolved": "https://registry.npmjs.org/semver/-/semver-5.7.0.tgz", + "integrity": "sha512-Ya52jSX2u7QKghxeoFGpLwCtGlt7j0oY9DYb5apt9nPlJ42ID+ulTXESnt/qAQcoSERyZ5sl3LDIOw0nAn/5DA==", "dev": true } } @@ -6748,9 +6729,9 @@ } }, "jsx-ast-utils": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/jsx-ast-utils/-/jsx-ast-utils-2.0.1.tgz", - "integrity": "sha1-6AGxs5mF4g//yHtA43SAgOLcrH8=", + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/jsx-ast-utils/-/jsx-ast-utils-2.1.0.tgz", + "integrity": "sha512-yDGDG2DS4JcqhA6blsuYbtsT09xL8AoLuUR2Gb5exrw7UEM19sBcOTq+YBBhrNbl0PUC4R4LnFu+dHg2HKeVvA==", "dev": true, "requires": { "array-includes": "^3.0.3" @@ -7293,9 +7274,9 @@ } }, "mimic-fn": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/mimic-fn/-/mimic-fn-1.1.0.tgz", - "integrity": "sha1-5md4PZLonb00KBi1IwudYqZyrRg=", + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/mimic-fn/-/mimic-fn-1.2.0.tgz", + "integrity": "sha512-jf84uxzwiuiIVKiOLpfYk7N46TSy8ubTonmneY9vrpHNAnp0QBt2BxWV9dO3/j+BoVAb+a5G6YDPW3M5HOdMWQ==", "dev": true }, "minimalistic-assert": { @@ -8392,15 +8373,6 @@ "load-json-file": "^4.0.0" }, "dependencies": { - "find-up": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/find-up/-/find-up-2.1.0.tgz", - "integrity": "sha1-RdG35QbHF93UgndaK3eSCjwMV6c=", - "dev": true, - "requires": { - "locate-path": "^2.0.0" - } - }, "load-json-file": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/load-json-file/-/load-json-file-4.0.0.tgz", @@ -8449,17 +8421,6 @@ "dev": true, "requires": { "find-up": "^2.1.0" - }, - "dependencies": { - "find-up": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/find-up/-/find-up-2.1.0.tgz", - "integrity": "sha1-RdG35QbHF93UgndaK3eSCjwMV6c=", - "dev": true, - "requires": { - "locate-path": "^2.0.0" - } - } } }, "plur": { @@ -8545,13 +8506,14 @@ "dev": true }, "prop-types": { - "version": "15.6.2", - "resolved": "https://registry.npmjs.org/prop-types/-/prop-types-15.6.2.tgz", - "integrity": "sha512-3pboPvLiWD7dkI3qf3KbUe6hKFKa52w+AE0VCqECtf+QHAKgOL37tTaNCnuX1nAAQ4ZhyP+kYVKf8rLmJ/feDQ==", + "version": "15.7.2", + "resolved": "https://registry.npmjs.org/prop-types/-/prop-types-15.7.2.tgz", + "integrity": "sha512-8QQikdH7//R2vurIJSutZ1smHYTcLpRWEOlHnzcWHmBYrOGUysKwSsrC89BCiFj3CbrfJ/nXFdJepOVrY1GCHQ==", "dev": true, "requires": { - "loose-envify": "^1.3.1", - "object-assign": "^4.1.1" + "loose-envify": "^1.4.0", + "object-assign": "^4.1.1", + "react-is": "^16.8.1" } }, "property-information": { @@ -8731,6 +8693,12 @@ "integrity": "sha1-+p4xn/3u6zWycpbvDz03TawvUqc=", "dev": true }, + "react-is": { + "version": "16.8.6", + "resolved": "https://registry.npmjs.org/react-is/-/react-is-16.8.6.tgz", + "integrity": "sha512-aUk3bHfZ2bRSVFFbbeVS4i+lNPZr3/WM5jT2J5omUVV1zzcs1nAaf3l51ctA5FFvCRbhrH0bdAsRRQddFJZPtA==", + "dev": true + }, "read-pkg": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/read-pkg/-/read-pkg-2.0.0.tgz", @@ -8750,17 +8718,6 @@ "requires": { "find-up": "^2.0.0", "read-pkg": "^2.0.0" - }, - "dependencies": { - "find-up": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/find-up/-/find-up-2.1.0.tgz", - "integrity": "sha1-RdG35QbHF93UgndaK3eSCjwMV6c=", - "dev": true, - "requires": { - "locate-path": "^2.0.0" - } - } } }, "readable-stream": { @@ -9337,24 +9294,6 @@ "ajv-keywords": "^3.1.0" } }, - "semistandard": { - "version": "13.0.1", - "resolved": "https://registry.npmjs.org/semistandard/-/semistandard-13.0.1.tgz", - "integrity": "sha512-2GkuX4BsoMEYoufJYRz8/ERbYDfgOO3yP29IBaoXtxl202azlkV1MsFyoSFiM6GBUfL7MSUxSy38KfM9oDAE2g==", - "dev": true, - "requires": { - "eslint": "~5.4.0", - "eslint-config-semistandard": "13.0.0", - "eslint-config-standard": "12.0.0", - "eslint-config-standard-jsx": "6.0.2", - "eslint-plugin-import": "~2.14.0", - "eslint-plugin-node": "~7.0.1", - "eslint-plugin-promise": "~4.0.0", - "eslint-plugin-react": "~7.11.1", - "eslint-plugin-standard": "~4.0.0", - "standard-engine": "~10.0.0" - } - }, "semver": { "version": "5.3.0", "resolved": "https://registry.npmjs.org/semver/-/semver-5.3.0.tgz", @@ -9721,6 +9660,43 @@ "figgy-pudding": "^3.5.1" } }, + "standard": { + "version": "12.0.1", + "resolved": "https://registry.npmjs.org/standard/-/standard-12.0.1.tgz", + "integrity": "sha512-UqdHjh87OG2gUrNCSM4QRLF5n9h3TFPwrCNyVlkqu31Hej0L/rc8hzKqVvkb2W3x0WMq7PzZdkLfEcBhVOR6lg==", + "dev": true, + "requires": { + "eslint": "~5.4.0", + "eslint-config-standard": "12.0.0", + "eslint-config-standard-jsx": "6.0.2", + "eslint-plugin-import": "~2.14.0", + "eslint-plugin-node": "~7.0.1", + "eslint-plugin-promise": "~4.0.0", + "eslint-plugin-react": "~7.11.1", + "eslint-plugin-standard": "~4.0.0", + "standard-engine": "~9.0.0" + }, + "dependencies": { + "get-stdin": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/get-stdin/-/get-stdin-6.0.0.tgz", + "integrity": "sha512-jp4tHawyV7+fkkSKyvjuLZswblUtz+SQKzSWnBbii16BuZksJlU1wuBYXY75r+duh/llF1ur6oNwi+2ZzjKZ7g==", + "dev": true + }, + "standard-engine": { + "version": "9.0.0", + "resolved": "https://registry.npmjs.org/standard-engine/-/standard-engine-9.0.0.tgz", + "integrity": "sha512-ZfNfCWZ2Xq67VNvKMPiVMKHnMdvxYzvZkf1AH8/cw2NLDBm5LRsxMqvEJpsjLI/dUosZ3Z1d6JlHDp5rAvvk2w==", + "dev": true, + "requires": { + "deglob": "^2.1.0", + "get-stdin": "^6.0.0", + "minimist": "^1.1.0", + "pkg-conf": "^2.0.0" + } + } + } + }, "standard-engine": { "version": "10.0.0", "resolved": "https://registry.npmjs.org/standard-engine/-/standard-engine-10.0.0.tgz", @@ -9733,11 +9709,31 @@ "pkg-conf": "^2.0.0" }, "dependencies": { + "deglob": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/deglob/-/deglob-3.1.0.tgz", + "integrity": "sha512-al10l5QAYaM/PeuXkAr1Y9AQz0LCtWsnJG23pIgh44hDxHFOj36l6qvhfjnIWBYwZOqM1fXUFV9tkjL7JPdGvw==", + "dev": true, + "requires": { + "find-root": "^1.0.0", + "glob": "^7.0.5", + "ignore": "^5.0.0", + "pkg-config": "^1.1.0", + "run-parallel": "^1.1.2", + "uniq": "^1.0.1" + } + }, "get-stdin": { "version": "6.0.0", "resolved": "https://registry.npmjs.org/get-stdin/-/get-stdin-6.0.0.tgz", "integrity": "sha512-jp4tHawyV7+fkkSKyvjuLZswblUtz+SQKzSWnBbii16BuZksJlU1wuBYXY75r+duh/llF1ur6oNwi+2ZzjKZ7g==", "dev": true + }, + "ignore": { + "version": "5.1.1", + "resolved": "https://registry.npmjs.org/ignore/-/ignore-5.1.1.tgz", + "integrity": "sha512-DWjnQIFLenVrwyRCKZT+7a7/U4Cqgar4WG8V++K3hw+lrW1hc/SIwdiGmtxKCVACmHULTuGeBbHJmbwW7/sAvA==", + "dev": true } } }, @@ -9801,6 +9797,16 @@ } } }, + "standardx": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/standardx/-/standardx-3.0.1.tgz", + "integrity": "sha512-HU4c9V/F6TAKAokrnClUIzuETYyVpO3iYs77stT29YRJu8HR0CQ7ypM2sgW1Qmn3+VPB6/eSy4aPMt8NYPtl3A==", + "dev": true, + "requires": { + "standard": "^12.0.1", + "standard-engine": "^10.0.0" + } + }, "state-toggle": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/state-toggle/-/state-toggle-1.0.1.tgz", diff --git a/package.json b/package.json index 12d233ba..0dcf8dee 100644 --- a/package.json +++ b/package.json @@ -23,7 +23,7 @@ "ci": "npm run build && npm run test && npm run test:headless && npm run coverage", "prerelease": "npm run test:ci", "release": "standard-version -s", - "lint": "semistandard test/*.js index.js lib/*.js", + "lint": "standardx test/*.js index.js lib/*.js", "clean": "rm -rf node_modules dist/*.js test/browser/webpack-test.js" }, "repository": { @@ -49,8 +49,8 @@ "http-server": "~0.11.0", "nyc": "~14.0.0", "opener": "1.5.1", - "semistandard": "~13.0.1", "standard-version": "5.0.2", + "standardx": "^3.0.1", "tap-spec": "~5.0.0", "tape": "~4.10.1", "webpack": "~4.29.0", diff --git a/test/common.js b/test/common.js index 59565ba8..a9310487 100644 --- a/test/common.js +++ b/test/common.js @@ -6,6 +6,7 @@ */ /* eslint prefer-promise-reject-errors: "off" */ + function passFail (x) { return new Promise((resolve, reject) => { setTimeout(() => { @@ -17,6 +18,7 @@ function passFail (x) { /** * A function returning a promise that resolves * after 1 second. + * @return {Promise} always returns a promise that resolves 'done' */ function slowFunction () { return timedFunction(10000); diff --git a/test/error-filter-test.js b/test/error-filter-test.js index ae00b1c9..f5ec1c1f 100644 --- a/test/error-filter-test.js +++ b/test/error-filter-test.js @@ -52,7 +52,6 @@ test('Increments failure stats if no filter is provided', t => { .then(t.fail) .catch(err => { t.equal(err.statusCode, 500); - console.log(breaker.stats); t.equal(breaker.stats.failures, 1); t.ok(breaker.open); t.end(); diff --git a/test/test.js b/test/test.js index 866953f2..b5912c01 100644 --- a/test/test.js +++ b/test/test.js @@ -212,7 +212,8 @@ test('Breaker resets after a configurable amount of time', t => { t.plan(1); const fails = -1; const resetTimeout = 100; - const breaker = circuit(passFail, { errorThresholdPercentage: 1, resetTimeout }); + const breaker = circuit(passFail, + { errorThresholdPercentage: 1, resetTimeout }); breaker.fire(fails) .catch(() => { @@ -242,7 +243,8 @@ test('Breaker resets for circuits with a fallback function', t => { t.plan(2); const fails = -1; const resetTimeout = 100; - const breaker = circuit(passFail, { errorThresholdPercentage: 1, resetTimeout }); + const breaker = circuit(passFail, + { errorThresholdPercentage: 1, resetTimeout }); breaker.fallback(x => x * 2); breaker.on('fallback', result => { @@ -284,7 +286,8 @@ test('Passes error as last argument to the fallback function', t => { const fails = -1; const breaker = circuit(passFail, { errorThresholdPercentage: 1 }); breaker.on('fallback', result => { - t.equals(result, `Error: ${fails} is < 0`, 'fallback received error as last parameter'); + t.equals(result, + `Error: ${fails} is < 0`, 'fallback received error as last parameter'); breaker.shutdown(); t.end(); }); @@ -292,11 +295,12 @@ test('Passes error as last argument to the fallback function', t => { breaker.fire(fails).catch(t.fail); }); -test('Fallback is not called twice for the same execution when action fails after timing out', t => { +test('Fallback called once for the same execution when timing out', t => { t.plan(1); const actionDuration = 200; - const breaker = circuit(timedFailingFunction, { timeout: actionDuration / 2 }); + const breaker = circuit(timedFailingFunction, + { timeout: actionDuration / 2 }); breaker.fallback((ms, err) => { t.ok(err); @@ -304,7 +308,7 @@ test('Fallback is not called twice for the same execution when action fails afte }); breaker.fire(actionDuration) - .catch((err) => noop(err)) + .catch(err => noop(err)) .then(_ => breaker.shutdown()); // keep this test alive until action finishes @@ -808,7 +812,7 @@ test('Circuit Breaker timeout with semaphore released', t => { t.plan(1); const breaker = circuit(slowFunction, { timeout: 10, capacity: 2 }); - breaker.on('timeout', result => { + breaker.on('timeout', _ => { t.equal(breaker.semaphore.count, breaker.options.capacity); breaker.shutdown(); t.end(); diff --git a/test/volume-threshold-test.js b/test/volume-threshold-test.js index f4e451be..4f74c2d6 100644 --- a/test/volume-threshold-test.js +++ b/test/volume-threshold-test.js @@ -45,9 +45,9 @@ test('Has a volume threshold before tripping when option is provided', t => { .then(t.fail) .catch(e => { t.notOk(breaker.opened, - 'should not be open before volume threshold has been reached'); + 'not open before volume threshold has been reached'); t.notOk(breaker.pendingClose, - 'should not be pending close before volume threshold has been reached'); + 'not pending close before volume threshold has been reached'); }) .then(_ => { breaker.fire(-1) @@ -85,7 +85,7 @@ test('volume threshold does not affect halfOpen state', t => { }).then(_ => { setTimeout(_ => { // ensure that we have entered the halfOpen state t.ok(breaker.halfOpen, 'breaker should be in halfOpen state'); - t.ok(breaker.stats.fires === 0, 'statistical window should be cleared'); + t.ok(breaker.stats.fires === 0, 'statistical window cleared'); // now fail again and ensure that we reenter the open state breaker.fire(-1) .then(t.fail)