From 15d91fddde123043af53409ba79f36947b2a395e Mon Sep 17 00:00:00 2001 From: Jon Ursenbach Date: Tue, 19 Nov 2019 16:46:06 -0800 Subject: [PATCH] chore: loading @readme/eslint-config and resolving issues --- .eslintrc | 6 +- cmds/swagger.js | 2 +- package-lock.json | 482 +++++++++++++++++++++++++++++++++++++ package.json | 10 +- test/.eslintrc | 15 ++ test/cli.test.js | 111 +++++---- test/cmds/docs.test.js | 84 ++++--- test/cmds/login.test.js | 48 ++-- test/cmds/logout.test.js | 38 +-- test/cmds/open.test.js | 17 +- test/cmds/swagger.test.js | 10 +- test/cmds/versions.test.js | 105 ++++---- test/cmds/whoami.test.js | 20 +- test/lib/commands.test.js | 78 ++---- test/lib/prompts.test.js | 27 +-- 15 files changed, 753 insertions(+), 300 deletions(-) diff --git a/.eslintrc b/.eslintrc index 5c1e14b58..6067825fd 100644 --- a/.eslintrc +++ b/.eslintrc @@ -1,7 +1,7 @@ { - "extends": ["airbnb-base", "prettier"], + "extends": ["@readme/eslint-config"], + "root": true, "rules": { - "no-console": 0, - "func-names": ["error", "never"], + "no-console": "off" } } diff --git a/cmds/swagger.js b/cmds/swagger.js index 7506dcc31..b12bc4aee 100644 --- a/cmds/swagger.js +++ b/cmds/swagger.js @@ -72,7 +72,7 @@ exports.run = async function(opts) { ${ `rdme swagger FILE --key=${key} --id=${ - // eslint-disable-next-line + // eslint-disable-next-line no-underscore-dangle JSON.parse(data.body)._id }`.green } diff --git a/package-lock.json b/package-lock.json index 402268a20..f22032da9 100644 --- a/package-lock.json +++ b/package-lock.json @@ -502,6 +502,22 @@ "@types/yargs": "^13.0.0" } }, + "@readme/eslint-config": { + "version": "1.3.1", + "resolved": "https://registry.npmjs.org/@readme/eslint-config/-/eslint-config-1.3.1.tgz", + "integrity": "sha512-3EZayI3nU6PlCMgFRqx7i8t9MV73sUGcCji2tvQhju+ZrH9HZYjYBORp9d3FibuGQ52zya5tT6ljTESmUeRZuA==", + "dev": true, + "requires": { + "eslint-config-airbnb-base": "^14.0.0", + "eslint-config-prettier": "^6.5.0", + "eslint-plugin-eslint-comments": "^3.1.2", + "eslint-plugin-import": "^2.18.2", + "eslint-plugin-node": "^10.0.0", + "eslint-plugin-prettier": "^3.1.1", + "eslint-plugin-sonarjs": "^0.5.0", + "eslint-plugin-unicorn": "^13.0.0" + } + }, "@types/babel__core": { "version": "7.1.2", "resolved": "https://registry.npmjs.org/@types/babel__core/-/babel__core-7.1.2.tgz", @@ -568,6 +584,18 @@ "@types/istanbul-lib-report": "*" } }, + "@types/json-schema": { + "version": "7.0.3", + "resolved": "https://registry.npmjs.org/@types/json-schema/-/json-schema-7.0.3.tgz", + "integrity": "sha512-Il2DtDVRGDcqjDtE+rF8iqg1CArehSK84HZJCT7AMITlyXRBpuPhqGLDQMowraqqu1coEaimg4ZOqggt6L6L+A==", + "dev": true + }, + "@types/normalize-package-data": { + "version": "2.4.0", + "resolved": "https://registry.npmjs.org/@types/normalize-package-data/-/normalize-package-data-2.4.0.tgz", + "integrity": "sha512-f5j5b/Gf71L+dbqxIpQ4Z2WlmI/mPJ0fOkGGmFgtb6sAu97EPczzbS3/tJKxmcYDj55OX6ssqwDAWOHIYDRDGA==", + "dev": true + }, "@types/stack-utils": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/@types/stack-utils/-/stack-utils-1.0.1.tgz", @@ -589,6 +617,63 @@ "integrity": "sha512-wBlsw+8n21e6eTd4yVv8YD/E3xq0O6nNnJIquutAsFGE7EyMKz7W6RNT6BRu1SmdgmlCZ9tb0X+j+D6HGr8pZw==", "dev": true }, + "@typescript-eslint/experimental-utils": { + "version": "2.8.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/experimental-utils/-/experimental-utils-2.8.0.tgz", + "integrity": "sha512-jZ05E4SxCbbXseQGXOKf3ESKcsGxT8Ucpkp1jiVp55MGhOvZB2twmWKf894PAuVQTCgbPbJz9ZbRDqtUWzP8xA==", + "dev": true, + "requires": { + "@types/json-schema": "^7.0.3", + "@typescript-eslint/typescript-estree": "2.8.0", + "eslint-scope": "^5.0.0" + } + }, + "@typescript-eslint/typescript-estree": { + "version": "2.8.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-2.8.0.tgz", + "integrity": "sha512-ksvjBDTdbAQ04cR5JyFSDX113k66FxH1tAXmi+dj6hufsl/G0eMc/f1GgLjEVPkYClDbRKv+rnBFuE5EusomUw==", + "dev": true, + "requires": { + "debug": "^4.1.1", + "eslint-visitor-keys": "^1.1.0", + "glob": "^7.1.6", + "is-glob": "^4.0.1", + "lodash.unescape": "4.0.1", + "semver": "^6.3.0", + "tsutils": "^3.17.1" + }, + "dependencies": { + "debug": { + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/debug/-/debug-4.1.1.tgz", + "integrity": "sha512-pYAIzeRo8J6KPEaJ0VWOh5Pzkbw/RetuzehGM7QRRX5he4fPHx2rdKMB256ehJCkX+XRQm16eZLqLNS8RSZXZw==", + "dev": true, + "requires": { + "ms": "^2.1.1" + } + }, + "glob": { + "version": "7.1.6", + "resolved": "https://registry.npmjs.org/glob/-/glob-7.1.6.tgz", + "integrity": "sha512-LwaxwyZ72Lk7vZINtNNrywX0ZuLyStrdDtabefZKAY5ZGJhVtgdznluResxNmPitE0SAO+O26sWTHeKSI2wMBA==", + "dev": true, + "requires": { + "fs.realpath": "^1.0.0", + "inflight": "^1.0.4", + "inherits": "2", + "minimatch": "^3.0.4", + "once": "^1.3.0", + "path-is-absolute": "^1.0.0" + } + }, + "ms": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", + "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==", + "dev": true + } + } + }, "abab": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/abab/-/abab-2.0.0.tgz", @@ -1200,6 +1285,15 @@ } } }, + "clean-regexp": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/clean-regexp/-/clean-regexp-1.0.0.tgz", + "integrity": "sha1-jffHquUf02h06PjQW5GAvBGj/tc=", + "dev": true, + "requires": { + "escape-string-regexp": "^1.0.5" + } + }, "cli-cursor": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/cli-cursor/-/cli-cursor-1.0.2.tgz", @@ -2039,6 +2133,16 @@ } } }, + "eslint-ast-utils": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/eslint-ast-utils/-/eslint-ast-utils-1.1.0.tgz", + "integrity": "sha512-otzzTim2/1+lVrlH19EfQQJEhVJSu0zOb9ygb3iapN6UlyaDtyRq4b5U1FuW0v1lRa9Fp/GJyHkSwm6NqABgCA==", + "dev": true, + "requires": { + "lodash.get": "^4.4.2", + "lodash.zip": "^4.2.0" + } + }, "eslint-config-airbnb-base": { "version": "14.0.0", "resolved": "https://registry.npmjs.org/eslint-config-airbnb-base/-/eslint-config-airbnb-base-14.0.0.tgz", @@ -2079,6 +2183,42 @@ "pkg-dir": "^2.0.0" } }, + "eslint-plugin-es": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/eslint-plugin-es/-/eslint-plugin-es-2.0.0.tgz", + "integrity": "sha512-f6fceVtg27BR02EYnBhgWLFQfK6bN4Ll0nQFrBHOlCsAyxeZkn0NHns5O0YZOPrV1B3ramd6cgFwaoFLcSkwEQ==", + "dev": true, + "requires": { + "eslint-utils": "^1.4.2", + "regexpp": "^3.0.0" + }, + "dependencies": { + "regexpp": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/regexpp/-/regexpp-3.0.0.tgz", + "integrity": "sha512-Z+hNr7RAVWxznLPuA7DIh8UNX1j9CDrUQxskw9IrBE1Dxue2lyXT+shqEIeLUjrokxIP8CMy1WkjgG3rTsd5/g==", + "dev": true + } + } + }, + "eslint-plugin-eslint-comments": { + "version": "3.1.2", + "resolved": "https://registry.npmjs.org/eslint-plugin-eslint-comments/-/eslint-plugin-eslint-comments-3.1.2.tgz", + "integrity": "sha512-QexaqrNeteFfRTad96W+Vi4Zj1KFbkHHNMMaHZEYcovKav6gdomyGzaxSDSL3GoIyUOo078wRAdYlu1caiauIQ==", + "dev": true, + "requires": { + "escape-string-regexp": "^1.0.5", + "ignore": "^5.0.5" + }, + "dependencies": { + "ignore": { + "version": "5.1.4", + "resolved": "https://registry.npmjs.org/ignore/-/ignore-5.1.4.tgz", + "integrity": "sha512-MzbUSahkTW1u7JpKKjY7LCARd1fU5W2rLdxlM4kdkayuCwZImjkpluF9CM1aLewYJguPDqewLam18Y6AU69A8A==", + "dev": true + } + } + }, "eslint-plugin-import": { "version": "2.18.2", "resolved": "https://registry.npmjs.org/eslint-plugin-import/-/eslint-plugin-import-2.18.2.tgz", @@ -2134,6 +2274,241 @@ } } }, + "eslint-plugin-jest": { + "version": "23.0.4", + "resolved": "https://registry.npmjs.org/eslint-plugin-jest/-/eslint-plugin-jest-23.0.4.tgz", + "integrity": "sha512-OaP8hhT8chJNodUPvLJ6vl8gnalcsU/Ww1t9oR3HnGdEWjm/DdCCUXLOral+IPGAeWu/EwgVQCK/QtxALpH1Yw==", + "dev": true, + "requires": { + "@typescript-eslint/experimental-utils": "^2.5.0" + } + }, + "eslint-plugin-node": { + "version": "10.0.0", + "resolved": "https://registry.npmjs.org/eslint-plugin-node/-/eslint-plugin-node-10.0.0.tgz", + "integrity": "sha512-1CSyM/QCjs6PXaT18+zuAXsjXGIGo5Rw630rSKwokSs2jrYURQc4R5JZpoanNCqwNmepg+0eZ9L7YiRUJb8jiQ==", + "dev": true, + "requires": { + "eslint-plugin-es": "^2.0.0", + "eslint-utils": "^1.4.2", + "ignore": "^5.1.1", + "minimatch": "^3.0.4", + "resolve": "^1.10.1", + "semver": "^6.1.0" + }, + "dependencies": { + "ignore": { + "version": "5.1.4", + "resolved": "https://registry.npmjs.org/ignore/-/ignore-5.1.4.tgz", + "integrity": "sha512-MzbUSahkTW1u7JpKKjY7LCARd1fU5W2rLdxlM4kdkayuCwZImjkpluF9CM1aLewYJguPDqewLam18Y6AU69A8A==", + "dev": true + }, + "path-parse": { + "version": "1.0.6", + "resolved": "https://registry.npmjs.org/path-parse/-/path-parse-1.0.6.tgz", + "integrity": "sha512-GSmOT2EbHrINBf9SR7CDELwlJ8AENk3Qn7OikK4nFYAu3Ote2+JYNVvkpAEQm3/TLNEJFD/xZJjzyxg3KBWOzw==", + "dev": true + }, + "resolve": { + "version": "1.12.0", + "resolved": "https://registry.npmjs.org/resolve/-/resolve-1.12.0.tgz", + "integrity": "sha512-B/dOmuoAik5bKcD6s6nXDCjzUKnaDvdkRyAk6rsmsKLipWj4797iothd7jmmUhWTfinVMU+wc56rYKsit2Qy4w==", + "dev": true, + "requires": { + "path-parse": "^1.0.6" + } + } + } + }, + "eslint-plugin-prettier": { + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/eslint-plugin-prettier/-/eslint-plugin-prettier-3.1.1.tgz", + "integrity": "sha512-A+TZuHZ0KU0cnn56/9mfR7/KjUJ9QNVXUhwvRFSR7PGPe0zQR6PTkmyqg1AtUUEOzTqeRsUwyKFh0oVZKVCrtA==", + "dev": true, + "requires": { + "prettier-linter-helpers": "^1.0.0" + } + }, + "eslint-plugin-sonarjs": { + "version": "0.5.0", + "resolved": "https://registry.npmjs.org/eslint-plugin-sonarjs/-/eslint-plugin-sonarjs-0.5.0.tgz", + "integrity": "sha512-XW5MnzlRjhXpIdbULC/qAdJYHWw3rRLws/DyawdlPU/IdVr9AmRK1r2LaCvabwKOAW2XYYSo3kDX58E4MrB7PQ==", + "dev": true + }, + "eslint-plugin-unicorn": { + "version": "13.0.0", + "resolved": "https://registry.npmjs.org/eslint-plugin-unicorn/-/eslint-plugin-unicorn-13.0.0.tgz", + "integrity": "sha512-9CQk0v74vQpETMt6iqNgjf3IbWEFhrT0sjaLnjkl9SF3rJH6ZL9f7H42BXJ6LPENQR97QzhrIvB8VG0nD05wxQ==", + "dev": true, + "requires": { + "ci-info": "^2.0.0", + "clean-regexp": "^1.0.0", + "eslint-ast-utils": "^1.1.0", + "eslint-template-visitor": "^1.1.0", + "import-modules": "^2.0.0", + "lodash.camelcase": "^4.3.0", + "lodash.defaultsdeep": "^4.6.1", + "lodash.kebabcase": "^4.1.1", + "lodash.snakecase": "^4.1.1", + "lodash.topairs": "^4.3.0", + "lodash.upperfirst": "^4.3.1", + "read-pkg-up": "^7.0.0", + "regexpp": "^3.0.0", + "reserved-words": "^0.1.2", + "safe-regex": "^2.1.1", + "semver": "^6.3.0" + }, + "dependencies": { + "find-up": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/find-up/-/find-up-4.1.0.tgz", + "integrity": "sha512-PpOwAdQ/YlXQ2vj8a3h8IipDuYRi3wceVQQGYWxNINccq40Anw7BlsEXCMbt1Zt+OLA6Fq9suIpIWD0OsnISlw==", + "dev": true, + "requires": { + "locate-path": "^5.0.0", + "path-exists": "^4.0.0" + } + }, + "locate-path": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/locate-path/-/locate-path-5.0.0.tgz", + "integrity": "sha512-t7hw9pI+WvuwNJXwk5zVHpyhIqzg2qTlklJOf0mVxGSbe3Fp2VieZcduNYjaLDoy6p9uGpQEGWG87WpMKlNq8g==", + "dev": true, + "requires": { + "p-locate": "^4.1.0" + } + }, + "normalize-package-data": { + "version": "2.5.0", + "resolved": "https://registry.npmjs.org/normalize-package-data/-/normalize-package-data-2.5.0.tgz", + "integrity": "sha512-/5CMN3T0R4XTj4DcGaexo+roZSdSFW/0AOOTROrjxzCG1wrWXEsGbRKevjlIL+ZDE4sZlJr5ED4YW0yqmkK+eA==", + "dev": true, + "requires": { + "hosted-git-info": "^2.1.4", + "resolve": "^1.10.0", + "semver": "2 || 3 || 4 || 5", + "validate-npm-package-license": "^3.0.1" + }, + "dependencies": { + "semver": { + "version": "5.7.1", + "resolved": "https://registry.npmjs.org/semver/-/semver-5.7.1.tgz", + "integrity": "sha512-sauaDf/PZdVgrLTNYHRtpXa1iRiKcaebiKQ1BJdpQlWH2lCvexQdX55snPFyK7QzpudqbCI0qXFfOasHdyNDGQ==", + "dev": true + } + } + }, + "p-limit": { + "version": "2.2.1", + "resolved": "https://registry.npmjs.org/p-limit/-/p-limit-2.2.1.tgz", + "integrity": "sha512-85Tk+90UCVWvbDavCLKPOLC9vvY8OwEX/RtKF+/1OADJMVlFfEHOiMTPVyxg7mk/dKa+ipdHm0OUkTvCpMTuwg==", + "dev": true, + "requires": { + "p-try": "^2.0.0" + } + }, + "p-locate": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/p-locate/-/p-locate-4.1.0.tgz", + "integrity": "sha512-R79ZZ/0wAxKGu3oYMlz8jy/kbhsNrS7SKZ7PxEHBgJ5+F2mtFW2fK2cOtBh1cHYkQsbzFV7I+EoRKe6Yt0oK7A==", + "dev": true, + "requires": { + "p-limit": "^2.2.0" + } + }, + "p-try": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/p-try/-/p-try-2.2.0.tgz", + "integrity": "sha512-R4nPAVTAU0B9D35/Gk3uJf/7XYbQcyohSKdvAxIRSNghFl4e71hVoGnBNQz9cWaXxO2I10KTC+3jMdvvoKw6dQ==", + "dev": true + }, + "parse-json": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/parse-json/-/parse-json-5.0.0.tgz", + "integrity": "sha512-OOY5b7PAEFV0E2Fir1KOkxchnZNCdowAJgQ5NuxjpBKTRP3pQhwkrkxqQjeoKJ+fO7bCpmIZaogI4eZGDMEGOw==", + "dev": true, + "requires": { + "@babel/code-frame": "^7.0.0", + "error-ex": "^1.3.1", + "json-parse-better-errors": "^1.0.1", + "lines-and-columns": "^1.1.6" + } + }, + "path-exists": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/path-exists/-/path-exists-4.0.0.tgz", + "integrity": "sha512-ak9Qy5Q7jYb2Wwcey5Fpvg2KoAc/ZIhLSLOSBmRmygPsGwkVVt0fZa0qrtMz+m6tJTAHfZQ8FnmB4MG4LWy7/w==", + "dev": true + }, + "path-parse": { + "version": "1.0.6", + "resolved": "https://registry.npmjs.org/path-parse/-/path-parse-1.0.6.tgz", + "integrity": "sha512-GSmOT2EbHrINBf9SR7CDELwlJ8AENk3Qn7OikK4nFYAu3Ote2+JYNVvkpAEQm3/TLNEJFD/xZJjzyxg3KBWOzw==", + "dev": true + }, + "read-pkg": { + "version": "5.2.0", + "resolved": "https://registry.npmjs.org/read-pkg/-/read-pkg-5.2.0.tgz", + "integrity": "sha512-Ug69mNOpfvKDAc2Q8DRpMjjzdtrnv9HcSMX+4VsZxD1aZ6ZzrIE7rlzXBtWTyhULSMKg076AW6WR5iZpD0JiOg==", + "dev": true, + "requires": { + "@types/normalize-package-data": "^2.4.0", + "normalize-package-data": "^2.5.0", + "parse-json": "^5.0.0", + "type-fest": "^0.6.0" + }, + "dependencies": { + "type-fest": { + "version": "0.6.0", + "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-0.6.0.tgz", + "integrity": "sha512-q+MB8nYR1KDLrgr4G5yemftpMC7/QLqVndBmEEdqzmNj5dcFOO4Oo8qlwZE3ULT3+Zim1F8Kq4cBnikNhlCMlg==", + "dev": true + } + } + }, + "read-pkg-up": { + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/read-pkg-up/-/read-pkg-up-7.0.0.tgz", + "integrity": "sha512-t2ODkS/vTTcRlKwZiZsaLGb5iwfx9Urp924aGzVyboU6+7Z2i6eGr/G1Z4mjvwLLQV3uFOBKobNRGM3ux2PD/w==", + "dev": true, + "requires": { + "find-up": "^4.1.0", + "read-pkg": "^5.2.0", + "type-fest": "^0.8.1" + } + }, + "regexpp": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/regexpp/-/regexpp-3.0.0.tgz", + "integrity": "sha512-Z+hNr7RAVWxznLPuA7DIh8UNX1j9CDrUQxskw9IrBE1Dxue2lyXT+shqEIeLUjrokxIP8CMy1WkjgG3rTsd5/g==", + "dev": true + }, + "resolve": { + "version": "1.12.0", + "resolved": "https://registry.npmjs.org/resolve/-/resolve-1.12.0.tgz", + "integrity": "sha512-B/dOmuoAik5bKcD6s6nXDCjzUKnaDvdkRyAk6rsmsKLipWj4797iothd7jmmUhWTfinVMU+wc56rYKsit2Qy4w==", + "dev": true, + "requires": { + "path-parse": "^1.0.6" + } + }, + "safe-regex": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/safe-regex/-/safe-regex-2.1.1.tgz", + "integrity": "sha512-rx+x8AMzKb5Q5lQ95Zoi6ZbJqwCLkqi3XuJXp5P3rT8OEc6sZCJG5AE5dU3lsgRr/F4Bs31jSlVN+j5KrsGu9A==", + "dev": true, + "requires": { + "regexp-tree": "~0.1.1" + } + }, + "type-fest": { + "version": "0.8.1", + "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-0.8.1.tgz", + "integrity": "sha512-4dbzIzqvjtgiM5rw1k5rEHtBANKmdudhGyBEajN01fEyhaAIhsoKNy6y7+IN93IfpFtwY9iqi7kD+xwKhQsNJA==", + "dev": true + } + } + }, "eslint-scope": { "version": "5.0.0", "resolved": "https://registry.npmjs.org/eslint-scope/-/eslint-scope-5.0.0.tgz", @@ -2144,6 +2519,17 @@ "estraverse": "^4.1.1" } }, + "eslint-template-visitor": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/eslint-template-visitor/-/eslint-template-visitor-1.1.0.tgz", + "integrity": "sha512-Lmy6QVlmFiIGl5fPi+8ACnov3sare+0Ouf7deJAGGhmUfeWJ5fVarELUxZRpsZ9sHejiJUq8626d0dn9uvcZTw==", + "dev": true, + "requires": { + "eslint-visitor-keys": "^1.1.0", + "espree": "^6.1.1", + "multimap": "^1.0.2" + } + }, "eslint-utils": { "version": "1.4.3", "resolved": "https://registry.npmjs.org/eslint-utils/-/eslint-utils-1.4.3.tgz", @@ -2410,6 +2796,12 @@ "resolved": "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-1.1.0.tgz", "integrity": "sha1-wFNHeBfIa1HaqFPIHgWbcz0CNhQ=" }, + "fast-diff": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/fast-diff/-/fast-diff-1.2.0.tgz", + "integrity": "sha512-xJuoT5+L99XlZ8twedaRf6Ax2TgQVxvgZOYoPKqZufmJib0tL2tegPBOZb1pVNgIhlqDlA0eO0c3wBvQcmzx4w==", + "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", @@ -3467,6 +3859,12 @@ } } }, + "import-modules": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/import-modules/-/import-modules-2.0.0.tgz", + "integrity": "sha512-iczM/v9drffdNnABOKwj0f9G3cFDon99VcG1mxeBsdqnbd+vnQ5c2uAiCHNQITqFTOPaEvwg3VjoWCur0uHLEw==", + "dev": true + }, "imurmurhash": { "version": "0.1.4", "resolved": "https://registry.npmjs.org/imurmurhash/-/imurmurhash-0.1.4.tgz", @@ -4663,6 +5061,12 @@ "resolved": "https://registry.npmjs.org/line-counter/-/line-counter-1.1.0.tgz", "integrity": "sha1-EN8sBGrTVG5yT7pV+nLN4YpqAfM=" }, + "lines-and-columns": { + "version": "1.1.6", + "resolved": "https://registry.npmjs.org/lines-and-columns/-/lines-and-columns-1.1.6.tgz", + "integrity": "sha1-HADHQ7QzzQpOgHWPe2SldEDZ/wA=", + "dev": true + }, "load-json-file": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/load-json-file/-/load-json-file-2.0.0.tgz", @@ -4701,6 +5105,12 @@ "resolved": "https://registry.npmjs.org/lodash.camelcase/-/lodash.camelcase-4.3.0.tgz", "integrity": "sha1-soqmKIorn8ZRA1x3EfZathkDMaY=" }, + "lodash.defaultsdeep": { + "version": "4.6.1", + "resolved": "https://registry.npmjs.org/lodash.defaultsdeep/-/lodash.defaultsdeep-4.6.1.tgz", + "integrity": "sha512-3j8wdDzYuWO3lM3Reg03MuQR957t287Rpcxp1njpEa8oDrikb+FwGdW3n+FELh/A6qib6yPit0j/pv9G/yeAqA==", + "dev": true + }, "lodash.get": { "version": "4.4.2", "resolved": "https://registry.npmjs.org/lodash.get/-/lodash.get-4.4.2.tgz", @@ -4711,12 +5121,48 @@ "resolved": "https://registry.npmjs.org/lodash.isequal/-/lodash.isequal-4.5.0.tgz", "integrity": "sha1-QVxEePK8wwEgwizhDtMib30+GOA=" }, + "lodash.kebabcase": { + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/lodash.kebabcase/-/lodash.kebabcase-4.1.1.tgz", + "integrity": "sha1-hImxyw0p/4gZXM7KRI/21swpXDY=", + "dev": true + }, + "lodash.snakecase": { + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/lodash.snakecase/-/lodash.snakecase-4.1.1.tgz", + "integrity": "sha1-OdcUo1NXFHg3rv1ktdy7Fr7Nj40=", + "dev": true + }, "lodash.sortby": { "version": "4.7.0", "resolved": "https://registry.npmjs.org/lodash.sortby/-/lodash.sortby-4.7.0.tgz", "integrity": "sha1-7dFMgk4sycHgsKG0K7UhBRakJDg=", "dev": true }, + "lodash.topairs": { + "version": "4.3.0", + "resolved": "https://registry.npmjs.org/lodash.topairs/-/lodash.topairs-4.3.0.tgz", + "integrity": "sha1-O23qo31g+xFnE8RsXxfqGQ7EjWQ=", + "dev": true + }, + "lodash.unescape": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/lodash.unescape/-/lodash.unescape-4.0.1.tgz", + "integrity": "sha1-vyJJiGzlFM2hEvrpIYzcBlIR/Jw=", + "dev": true + }, + "lodash.upperfirst": { + "version": "4.3.1", + "resolved": "https://registry.npmjs.org/lodash.upperfirst/-/lodash.upperfirst-4.3.1.tgz", + "integrity": "sha1-E2Xt9DFIBIHvDRxolXpe2Z1J984=", + "dev": true + }, + "lodash.zip": { + "version": "4.2.0", + "resolved": "https://registry.npmjs.org/lodash.zip/-/lodash.zip-4.2.0.tgz", + "integrity": "sha1-7GZi5IlkCO1KtsVCo5kLcswIACA=", + "dev": true + }, "loose-envify": { "version": "1.4.0", "resolved": "https://registry.npmjs.org/loose-envify/-/loose-envify-1.4.0.tgz", @@ -4934,6 +5380,12 @@ "quotemeta": "0.0.0" } }, + "multimap": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/multimap/-/multimap-1.1.0.tgz", + "integrity": "sha512-0ZIR9PasPxGXmRsEF8jsDzndzHDj7tIav+JUmvIFB/WHswliFnquxECT/De7GR4yg99ky/NlRKJT82G1y271bw==", + "dev": true + }, "mute-stream": { "version": "0.0.6", "resolved": "https://registry.npmjs.org/mute-stream/-/mute-stream-0.0.6.tgz", @@ -5646,6 +6098,15 @@ "integrity": "sha512-YsdAD29M0+WY2xXZk3i0PA16olY9qZss+AuODxglXcJ+2ZBwFv+6k5tE8GS8/HKAthaajlS/WqhdgcjumOrPlg==", "dev": true }, + "prettier-linter-helpers": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/prettier-linter-helpers/-/prettier-linter-helpers-1.0.0.tgz", + "integrity": "sha512-GbK2cP9nraSSUF9N2XwUwqfzlAFlMNYYl+ShE/V+H8a9uNl/oUqB1w2EL54Jh0OlyRSd8RfWYJ3coVS4TROP2w==", + "dev": true, + "requires": { + "fast-diff": "^1.1.2" + } + }, "pretty-format": { "version": "24.9.0", "resolved": "https://registry.npmjs.org/pretty-format/-/pretty-format-24.9.0.tgz", @@ -5836,6 +6297,12 @@ "safe-regex": "^1.1.0" } }, + "regexp-tree": { + "version": "0.1.16", + "resolved": "https://registry.npmjs.org/regexp-tree/-/regexp-tree-0.1.16.tgz", + "integrity": "sha512-nXWhGJLTWLNdhWF1uqoXQgAOgv8mQGpgXTOk8BWp08YMOKCtn74VoyOJ+AXZ68Dj50Myd+msYs+aGRBzWJ5dJA==", + "dev": true + }, "regexpp": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/regexpp/-/regexpp-2.0.1.tgz", @@ -5941,6 +6408,12 @@ "resolved": "https://registry.npmjs.org/require-main-filename/-/require-main-filename-1.0.1.tgz", "integrity": "sha1-l/cXtp1IeE9fUmpsWqj/3aBVpNE=" }, + "reserved-words": { + "version": "0.1.2", + "resolved": "https://registry.npmjs.org/reserved-words/-/reserved-words-0.1.2.tgz", + "integrity": "sha1-AKCUD5jNUBrqqsMWQR2a3FKzGrE=", + "dev": true + }, "resolve": { "version": "1.7.1", "resolved": "https://registry.npmjs.org/resolve/-/resolve-1.7.1.tgz", @@ -7165,6 +7638,15 @@ "integrity": "sha512-qOebF53frne81cf0S9B41ByenJ3/IuH8yJKngAX35CmiZySA0khhkovshKK+jGCaMnVomla7gVlIcc3EvKPbTQ==", "dev": true }, + "tsutils": { + "version": "3.17.1", + "resolved": "https://registry.npmjs.org/tsutils/-/tsutils-3.17.1.tgz", + "integrity": "sha512-kzeQ5B8H3w60nFY2g8cJIuH7JDpsALXySGtwGJ0p2LSjLgay3NdIpqq5SoOBe46bKDW2iq25irHCr8wjomUS2g==", + "dev": true, + "requires": { + "tslib": "^1.8.1" + } + }, "tunnel-agent": { "version": "0.6.0", "resolved": "https://registry.npmjs.org/tunnel-agent/-/tunnel-agent-0.6.0.tgz", diff --git a/package.json b/package.json index 574105664..95ee28ec9 100644 --- a/package.json +++ b/package.json @@ -46,18 +46,16 @@ "table-layout": "^1.0.0" }, "devDependencies": { + "@readme/eslint-config": "^1.3.1", "eslint": "^6.2.0", - "eslint-config-airbnb-base": "^14.0.0", - "eslint-config-prettier": "^6.0.0", - "eslint-plugin-import": "^2.11.0", + "eslint-plugin-jest": "^23.0.4", "jest": "^24.7.1", "nock": "^11.3.3", "prettier": "^1.12.1" }, "scripts": { - "lint": "eslint -f unix .", - "prettier": "prettier --list-different \"./**/**.js\"", - "prettier:write": "prettier --write \"./**/**.js\"", + "lint": "eslint .", + "prettier": "prettier --list-different --write \"./**/**.js\"", "pretest": "npm run lint && npm run prettier", "test": "jest --coverage --silent" }, diff --git a/test/.eslintrc b/test/.eslintrc index 55f121d15..ede75ad83 100644 --- a/test/.eslintrc +++ b/test/.eslintrc @@ -1,5 +1,20 @@ { + "extends": ["@readme/eslint-config/testing"], "env": { "jest": true + }, + "rules": { + "jest/expect-expect": [ + "warn", + { + "assertFunctionNames": [ + "expect", + + // This rule doesn't recognize nock assertions. + // https://github.com/jest-community/eslint-plugin-jest/issues/471 + "nock" + ] + } + ] } } diff --git a/test/cli.test.js b/test/cli.test.js index 79a5a898a..da97c0966 100644 --- a/test/cli.test.js +++ b/test/cli.test.js @@ -1,6 +1,5 @@ require('colors'); -const assert = require('assert'); const nock = require('nock'); const cli = require('../cli'); const { version } = require('../package.json'); @@ -8,88 +7,91 @@ const conf = require('../lib/configstore'); const swaggerCmd = require('../cmds/swagger'); describe('cli', () => { - it('command not found', done => - cli('notARealCommand').catch(e => { - assert.equal(e.message.includes('Command not found'), true); - return done(); - })); + it('command not found', () => { + expect.assertions(1); + return cli('notARealCommand').catch(e => { + expect(e.message).toContain('Command not found'); + }); + }); describe('--version', () => { it('should return version from package.json', () => - cli(['--version']).then(v => assert.equal(v, version))); + cli(['--version']).then(v => expect(v).toBe(version))); it('should return version if the `-V` alias is supplied', () => - cli(['-V']).then(v => assert.equal(v, version))); + cli(['-V']).then(v => expect(v).toBe(version))); it('should return version from package.json for help command', () => - cli(['help', '--version']).then(v => assert.equal(v, version))); + cli(['help', '--version']).then(v => expect(v).toBe(version))); // This is necessary because we use --version for other commands like `docs` - it('should only return version if no command', () => - cli(['no-such-command', '--version']) - .then(() => { - throw new Error('Should not get here'); - }) - .catch(() => { - // This can be ignored as it's just going to be - // a command not found error - })); + it('should only return version if no command', () => { + expect.assertions(1); + + return cli(['no-such-command', '--version']).catch(err => { + // This can be ignored as it's just going to be a command not found error + expect(err.message).toBe('Command not found.'); + }); + }); it('should not be returned if `--version` is being used on a subcommand', () => { + expect.assertions(1); nock.disableNetConnect(); - cli(['docs:edit', 'getting-started', '--version', '1.0.0', '--key=abcdef']).catch(e => { - assert.notEqual(e.message, 'No project version provided. Please use `--version`.'); - }); + return cli(['docs:edit', 'getting-started', '--version', '1.0.0', '--key=abcdef']).catch( + e => { + expect(e.message).not.toBe('No project version provided. Please use `--version`.'); + }, + ); }); }); describe('--help', () => { it('should print help', () => cli(['--help']).then(output => { - assert.notEqual(output, version); + expect(output).not.toBe(version); })); it('should print help for the `-H` alias', () => cli(['-H']).then(output => { - assert.notEqual(output, version); + expect(output).not.toBe(version); })); it('should print usage for a given command', () => { - cli(['swagger', '--help']).then(output => { - assert.ok(output.indexOf(swaggerCmd.description) !== -1); - assert.ok(output.indexOf(swaggerCmd.usage) !== -1); - assert.ok(output.indexOf('--key') !== -1); - assert.ok(output.indexOf('--help') !== -1); + return cli(['swagger', '--help']).then(output => { + expect(output.indexOf(swaggerCmd.description) !== -1).toBeTruthy(); + expect(output.indexOf(swaggerCmd.usage) !== -1).toBeTruthy(); + expect(output.indexOf('--key') !== -1).toBeTruthy(); + expect(output.indexOf('--help') !== -1).toBeTruthy(); }); }); it('should print usage for a given command if supplied as `help `', () => { - cli(['help', 'swagger']).then(output => { - assert.ok(output.indexOf(swaggerCmd.description) !== -1); - assert.ok(output.indexOf(swaggerCmd.usage) !== -1); - assert.ok(output.indexOf('--key') !== -1); - assert.ok(output.indexOf('--help') !== -1); + return cli(['help', 'swagger']).then(output => { + expect(output.indexOf(swaggerCmd.description) !== -1).toBeTruthy(); + expect(output.indexOf(swaggerCmd.usage) !== -1).toBeTruthy(); + expect(output.indexOf('--key') !== -1).toBeTruthy(); + expect(output.indexOf('--help') !== -1).toBeTruthy(); }); }); it('should not surface args that are designated as hidden', () => { - cli(['swagger', '--help']).then(output => { - assert.ok(output.indexOf('---token') === -1); - assert.ok(output.indexOf('---spec') === -1); + return cli(['swagger', '--help']).then(output => { + expect(output.indexOf('---token') === -1).toBeTruthy(); + expect(output.indexOf('---spec') === -1).toBeTruthy(); }); }); it('should show related commands for a subcommands help menu', () => { - cli(['versions', '--help']).then(output => { - assert.ok(output.indexOf('Related commands') !== -1); - assert.ok(output.indexOf('versions:create') !== -1); + return cli(['versions', '--help']).then(output => { + expect(output.indexOf('Related commands') !== -1).toBeTruthy(); + expect(output.indexOf('versions:create') !== -1).toBeTruthy(); }); }); it('should not show related commands on commands that have none', () => { - cli(['swagger', '--help']).then(output => { - assert.ok(output.indexOf('Related commands') === -1); + return cli(['swagger', '--help']).then(output => { + expect(output.indexOf('Related commands') === -1).toBeTruthy(); }); }); }); @@ -98,29 +100,32 @@ describe('cli', () => { // docs:edit will make a backend connection beforeAll(() => nock.disableNetConnect()); - it('should load subcommands from the folder', () => - cli(['docs:edit', 'getting-started', '--version=1.0.0', '--key=abcdef']).catch(e => { - assert.notEqual(e.message, 'Command not found.'); - })); + it('should load subcommands from the folder', () => { + expect.assertions(1); + return cli(['docs:edit', 'getting-started', '--version=1.0.0', '--key=abcdef']).catch(e => { + expect(e.message).not.toBe('Command not found.'); + }); + }); }); - it('should not error with undefined cmd', () => - cli([]).catch(() => { - // This can be ignored as it's just going to be - // a command not found error - })); + it('should not error with undefined cmd', () => { + return cli([]).then(resp => { + expect(resp).toContain('Available commands'); + }); + }); it('should add stored apiKey to opts', () => { + expect.assertions(1); conf.set('apiKey', '123456'); return cli(['docs']).catch(err => { conf.delete('apiKey'); - assert.equal(err.message, 'No project version provided. Please use `--version`.'); + expect(err.message).toBe('No project version provided. Please use `--version`.'); }); }); it('should not error with oas arguments passed in', () => { - return assert.doesNotReject(() => { + expect(() => { return cli(['oas', 'init']); - }); + }).not.toThrow(); }); }); diff --git a/test/cmds/docs.test.js b/test/cmds/docs.test.js index 0b49e1a4c..fdd2f9949 100644 --- a/test/cmds/docs.test.js +++ b/test/cmds/docs.test.js @@ -1,6 +1,5 @@ const nock = require('nock'); const config = require('config'); -const assert = require('assert'); const fs = require('fs'); const path = require('path'); const crypto = require('crypto'); @@ -17,20 +16,26 @@ describe('rdme docs', () => { beforeAll(() => nock.disableNetConnect()); afterAll(() => nock.cleanAll()); - it('should error if no api key provided', () => - docs.run({}).catch(err => { - assert.equal(err.message, 'No project API key provided. Please use `--key`.'); - })); + it('should error if no api key provided', () => { + expect.assertions(1); + return docs.run({}).catch(err => { + expect(err.message).toBe('No project API key provided. Please use `--key`.'); + }); + }); - it('should error if no version provided', () => - docs.run({ key }).catch(err => { - assert.equal(err.message, 'No project version provided. Please use `--version`.'); - })); + it('should error if no version provided', () => { + expect.assertions(1); + return docs.run({ key }).catch(err => { + expect(err.message).toBe('No project version provided. Please use `--version`.'); + }); + }); - it('should error if no folder provided', () => - docs.run({ key, version: '1.0.0' }).catch(err => { - assert.equal(err.message, 'No folder provided. Usage `rdme docs [options]`.'); - })); + it('should error if no folder provided', () => { + expect.assertions(1); + return docs.run({ key, version: '1.0.0' }).catch(err => { + expect(err.message).toBe('No folder provided. Usage `rdme docs [options]`.'); + }); + }); it.todo('should error if the argument isnt a folder'); it.todo('should error if the folder contains no markdown files'); @@ -75,6 +80,7 @@ describe('rdme docs', () => { }); it('should not send requests for docs that have not changed', () => { + expect.assertions(1); const slug = 'simple-doc'; const hash = crypto .createHash('sha1') @@ -93,7 +99,7 @@ describe('rdme docs', () => { return docs .run({ folder: './test/fixtures/existing-docs', key, version }) .then(([message]) => { - assert.equal(message, '`simple-doc` not updated. No changes.'); + expect(message).toBe('`simple-doc` not updated. No changes.'); getMock.done(); }); }); @@ -138,22 +144,29 @@ describe('rdme docs', () => { }); describe('rdme docs:edit', () => { - it('should error if no api key provided', () => - docsEdit.run({}).catch(err => { - assert.equal(err.message, 'No project API key provided. Please use `--key`.'); - })); + it('should error if no api key provided', () => { + expect.assertions(1); + return docsEdit.run({}).catch(err => { + expect(err.message).toBe('No project API key provided. Please use `--key`.'); + }); + }); - it('should error if no version provided', () => - docsEdit.run({ key }).catch(err => { - assert.equal(err.message, 'No project version provided. Please use `--version`.'); - })); + it('should error if no version provided', () => { + expect.assertions(1); + return docsEdit.run({ key }).catch(err => { + expect(err.message).toBe('No project version provided. Please use `--version`.'); + }); + }); - it('should error if no slug provided', () => - docsEdit.run({ key, version: '1.0.0' }).catch(err => { - assert.equal(err.message, 'No slug provided. Usage `rdme docs:edit [options]`.'); - })); + it('should error if no slug provided', () => { + expect.assertions(1); + return docsEdit.run({ key, version: '1.0.0' }).catch(err => { + expect(err.message).toBe('No slug provided. Usage `rdme docs:edit [options]`.'); + }); + }); it('should fetch the doc from the api', () => { + expect.assertions(3); const slug = 'getting-started'; const body = 'abcdef'; const edits = 'ghijkl'; @@ -181,19 +194,20 @@ describe('rdme docs:edit', () => { .reply(200); function mockEditor(filename, cb) { - assert.equal(filename, `${slug}.md`); - assert.equal(fs.existsSync(filename), true); + expect(filename).toBe(`${slug}.md`); + expect(fs.existsSync(filename)).toBe(true); fs.appendFile(filename, edits, cb.bind(null, 0)); } return docsEdit.run({ slug, key, version: '1.0.0', mockEditor }).then(() => { getMock.done(); putMock.done(); - assert.equal(fs.existsSync(`${slug}.md`), false); + expect(fs.existsSync(`${slug}.md`)).toBe(false); }); }); it('should error if remote doc does not exist', () => { + expect.assertions(2); const slug = 'no-such-doc'; const getMock = nock(config.host) @@ -202,12 +216,13 @@ describe('rdme docs:edit', () => { return docsEdit.run({ slug, key, version: '1.0.0' }).catch(err => { getMock.done(); - assert.equal(err.error, 'Not Found'); - assert.equal(err.description, 'No doc found with that slug'); + expect(err.error).toBe('Not Found'); + expect(err.description).toBe('No doc found with that slug'); }); }); it('should error if doc fails validation', () => { + expect.assertions(2); const slug = 'getting-started'; const getMock = nock(config.host) @@ -223,15 +238,16 @@ describe('rdme docs:edit', () => { } return docsEdit.run({ slug, key, version: '1.0.0', mockEditor }).catch(err => { - assert.equal(err.error, 'Bad Request'); + expect(err.error).toBe('Bad Request'); getMock.done(); putMock.done(); - assert.equal(fs.existsSync(`${slug}.md`), true); + expect(fs.existsSync(`${slug}.md`)).toBe(true); fs.unlinkSync(`${slug}.md`); }); }); it('should handle error if $EDITOR fails', () => { + expect.assertions(1); const slug = 'getting-started'; nock(config.host) .get(`/api/v1/docs/${slug}`) @@ -242,7 +258,7 @@ describe('rdme docs:edit', () => { } return docsEdit.run({ slug, key, version: '1.0.0', mockEditor }).catch(err => { - assert.equal(err.message, 'Non zero exit code from $EDITOR'); + expect(err.message).toBe('Non zero exit code from $EDITOR'); fs.unlinkSync(`${slug}.md`); }); }); diff --git a/test/cmds/login.test.js b/test/cmds/login.test.js index 08cf6d38f..e817fb15b 100644 --- a/test/cmds/login.test.js +++ b/test/cmds/login.test.js @@ -1,6 +1,5 @@ const nock = require('nock'); const config = require('config'); -const assert = require('assert'); const configStore = require('../../lib/configstore'); const cmd = require('../../cmds/login'); @@ -9,19 +8,22 @@ describe('rdme login', () => { afterAll(() => nock.cleanAll()); afterEach(() => configStore.clear()); - it('should error if no project provided', done => - cmd.run({}).catch(err => { - assert.equal(err.message, 'No project subdomain provided. Please use `--project`.'); - return done(); - })); + it('should error if no project provided', () => { + expect.assertions(1); + return cmd.run({}).catch(err => { + expect(err.message).toBe('No project subdomain provided. Please use `--project`.'); + }); + }); - it('should error if email is invalid', done => - cmd.run({ project: 'subdomain', email: 'this-is-not-an-email' }).catch(err => { - assert.equal(err.message, 'You must provide a valid email address.'); - return done(); - })); + it('should error if email is invalid', () => { + expect.assertions(1); + return cmd.run({ project: 'subdomain', email: 'this-is-not-an-email' }).catch(err => { + expect(err.message).toBe('You must provide a valid email address.'); + }); + }); it('should post to /login on the API', () => { + expect.assertions(3); const email = 'dom@readme.io'; const password = '123456'; const project = 'subdomain'; @@ -33,14 +35,15 @@ describe('rdme login', () => { return cmd.run({ email, password, project }).then(() => { mock.done(); - assert.equal(configStore.get('apiKey'), apiKey); - assert.equal(configStore.get('email'), email); - assert.equal(configStore.get('project'), project); + expect(configStore.get('apiKey')).toBe(apiKey); + expect(configStore.get('email')).toBe(email); + expect(configStore.get('project')).toBe(project); configStore.clear(); }); }); - it('should error if invalid credentials are given', done => { + it('should error if invalid credentials are given', () => { + expect.assertions(2); const email = 'dom@readme.io'; const password = '123456'; const project = 'subdomain'; @@ -54,13 +57,13 @@ describe('rdme login', () => { return cmd.run({ email, password, project }).catch(err => { mock.done(); - assert.equal(err.error, 'Bad Request'); - assert.equal(err.description, 'Invalid email/password'); - return done(); + expect(err.error).toBe('Bad Request'); + expect(err.description).toBe('Invalid email/password'); }); }); - it('should error if missing two factor token', done => { + it('should error if missing two factor token', () => { + expect.assertions(2); const email = 'dom@readme.io'; const password = '123456'; const project = 'subdomain'; @@ -74,9 +77,8 @@ describe('rdme login', () => { return cmd.run({ email, password, project }).catch(err => { mock.done(); - assert.equal(err.error, 'Bad Request'); - assert.equal(err.description, 'You must provide a Two Factor Code'); - return done(); + expect(err.error).toBe('Bad Request'); + expect(err.description).toBe('You must provide a Two Factor Code'); }); }); @@ -95,5 +97,5 @@ describe('rdme login', () => { }); }); - it('should error if trying to access a project that is not yours', () => {}); + it.todo('should error if trying to access a project that is not yours'); }); diff --git a/test/cmds/logout.test.js b/test/cmds/logout.test.js index 9cdd6fbbc..1200ae473 100644 --- a/test/cmds/logout.test.js +++ b/test/cmds/logout.test.js @@ -1,43 +1,27 @@ -const assert = require('assert'); const config = require('config'); const configStore = require('../../lib/configstore'); const cmd = require('../../cmds/logout'); const loginCmd = require('../../cmds/login'); describe('rdme logout', () => { - it("should report the user as logged out if they aren't logged in", done => { + it("should report the user as logged out if they aren't logged in", () => { configStore.delete('email'); configStore.delete('project'); - cmd - .run({}) - .then(msg => { - assert.equal( - msg, - `You have logged out of Readme. Please use \`${config.cli} ${loginCmd.command}\` to login again.`, - ); - return done(); - }) - .catch(err => { - assert.ok(false, err); - return done(); - }); + return cmd.run({}).then(msg => { + expect(msg).toBe( + `You have logged out of Readme. Please use \`${config.cli} ${loginCmd.command}\` to login again.`, + ); + }); }); - it('should log the user out', done => { + it('should log the user out', () => { configStore.set('email', 'email@example.com'); configStore.set('project', 'subdomain'); - cmd - .run({}) - .then(() => { - assert.equal(configStore.get('email'), undefined, 'config was not destroyed'); - assert.equal(configStore.get('project'), undefined, 'config was not destroyed'); - return done(); - }) - .catch(err => { - assert.ok(false, err); - return done(); - }); + return cmd.run({}).then(() => { + expect(configStore.get('email')).toBeUndefined(); + expect(configStore.get('project')).toBeUndefined(); + }); }); }); diff --git a/test/cmds/open.test.js b/test/cmds/open.test.js index 74a5cfad1..1349c490a 100644 --- a/test/cmds/open.test.js +++ b/test/cmds/open.test.js @@ -1,28 +1,27 @@ -const assert = require('assert'); const config = require('config'); const configStore = require('../../lib/configstore'); const cmd = require('../../cmds/open'); const loginCmd = require('../../cmds/login'); describe('rdme open', () => { - it('should error if no project provided', done => { + it('should error if no project provided', () => { + expect.assertions(1); configStore.delete('project'); - cmd.run({}).catch(err => { - assert.equal(err.message, `Please login using \`${config.cli} ${loginCmd.command}\`.`); - return done(); + return cmd.run({}).catch(err => { + expect(err.message).toBe(`Please login using \`${config.cli} ${loginCmd.command}\`.`); }); }); - it('should open the project', done => { + it('should open the project', () => { + expect.assertions(1); configStore.set('project', 'subdomain'); function mockOpen(url) { - assert.equal(url, 'https://subdomain.readme.io'); - done(); + expect(url).toBe('https://subdomain.readme.io'); return Promise.resolve(); } - cmd.run({ mockOpen }); + return cmd.run({ mockOpen }); }); }); diff --git a/test/cmds/swagger.test.js b/test/cmds/swagger.test.js index 15024dd31..8c072f9c5 100644 --- a/test/cmds/swagger.test.js +++ b/test/cmds/swagger.test.js @@ -97,7 +97,7 @@ describe('rdme swagger', () => { .then(() => mock.done()); }); - it('should return a 404 if version flag not found', () => {}); + it.todo('should return a 404 if version flag not found'); it('should request a version list if version is not found', () => { promptHandler.generatePrompts.mockResolvedValue({ @@ -148,13 +148,13 @@ describe('rdme swagger', () => { .then(() => mock.done()); }); - it('should error if no api key provided', () => { - expect(swagger.run({ spec: './test/fixtures/swagger.json' })).rejects.toThrow( + it('should error if no api key provided', async () => { + await expect(swagger.run({ spec: './test/fixtures/swagger.json' })).rejects.toThrow( 'No project API key provided. Please use `--key`.', ); }); - it('should error if no file was provided or able to be discovered', () => { - expect(swagger.run({ key })).rejects.toThrowError(); + it('should error if no file was provided or able to be discovered', async () => { + await expect(swagger.run({ key })).rejects.toThrow(); }); }); diff --git a/test/cmds/versions.test.js b/test/cmds/versions.test.js index 97a32f748..997b1fff1 100644 --- a/test/cmds/versions.test.js +++ b/test/cmds/versions.test.js @@ -1,6 +1,5 @@ const nock = require('nock'); const config = require('config'); -const assert = require('assert'); const promptHandler = require('../../lib/prompts'); const versions = require('../../cmds/versions/index'); @@ -40,8 +39,8 @@ describe('rdme versions*', () => { describe('rdme versions', () => { it('should error if no api key provided', () => { - versions.run({}).catch(err => { - assert.equal(err.message, 'No project API key provided. Please use `--key`.'); + return versions.run({}).catch(err => { + expect(err.message).toBe('No project API key provided. Please use `--key`.'); }); }); @@ -52,8 +51,8 @@ describe('rdme versions*', () => { .reply(200, [versionPayload, version2Payload]); const table = await versions.run({ key }); - assert.ok(table.indexOf(version) !== -1); - assert.ok(table.indexOf(version2) !== -1); + expect(table.indexOf(version) !== -1).toBeTruthy(); + expect(table.indexOf(version2) !== -1).toBeTruthy(); mockRequest.done(); }); @@ -64,7 +63,7 @@ describe('rdme versions*', () => { .reply(200, [versionPayload, version2Payload]); const response = await versions.run({ key, raw: true }); - assert.deepEqual(response, [versionPayload, version2Payload]); + expect(response).toStrictEqual([versionPayload, version2Payload]); mockRequest.done(); }); @@ -74,10 +73,11 @@ describe('rdme versions*', () => { .basicAuth({ user: key }) .reply(200, versionPayload); - const table = await versions.run({ key, version }); - assert.ok(table.indexOf(version) !== -1); - assert.ok(table.indexOf(version2) === -1); - mockRequest.done(); + return versions.run({ key, version }).then(table => { + expect(table.indexOf(version) !== -1).toBeTruthy(); + expect(table.indexOf(version2) === -1).toBeTruthy(); + mockRequest.done(); + }); }); it('should get a specific version object if version flag provided and return it in a raw format', async () => { @@ -86,23 +86,25 @@ describe('rdme versions*', () => { .basicAuth({ user: key }) .reply(200, versionPayload); - const response = await versions.run({ key, version, raw: true }); - assert.deepEqual(response, versionPayload); - mockRequest.done(); + return versions.run({ key, version, raw: true }).then(response => { + expect(response).toStrictEqual(versionPayload); + mockRequest.done(); + }); }); }); describe('rdme versions:create', () => { it('should error if no api key provided', () => { - createVersion.run({}).catch(err => { - assert.equal(err.message, 'No project API key provided. Please use `--key`.'); + expect.assertions(1); + return createVersion.run({}).catch(err => { + expect(err.message).toBe('No project API key provided. Please use `--key`.'); }); }); it('should error if no version provided', () => { - createVersion.run({ key }).catch(err => { - assert.equal( - err.message, + expect.assertions(1); + return createVersion.run({ key }).catch(err => { + expect(err.message).toBe( 'Please specify a semantic version. See `rdme help versions:create` for help.', ); }); @@ -123,11 +125,13 @@ describe('rdme versions*', () => { .basicAuth({ user: key }) .reply(201, { version }); - await createVersion.run({ key, version }); - mockRequest.done(); + return createVersion.run({ key, version }).then(() => { + mockRequest.done(); + }); }); it('should catch any post request errors', async () => { + expect.assertions(1); promptHandler.createVersionPrompt.mockResolvedValue({ is_stable: false, is_beta: false, @@ -138,27 +142,25 @@ describe('rdme versions*', () => { .basicAuth({ user: key }) .reply(400); - await createVersion.run({ key, version, fork: '0.0.5' }).catch(err => { - assert.equal( - err.message, - 'Failed to create a new version using your specified parameters.', - ); + return createVersion.run({ key, version, fork: '0.0.5' }).catch(err => { + expect(err.message).toBe('Failed to create a new version using your specified parameters.'); + mockRequest.done(); }); - mockRequest.done(); }); }); describe('rdme versions:delete', () => { it('should error if no api key provided', () => { - deleteVersion.run({}).catch(err => { - assert.equal(err.message, 'No project API key provided. Please use `--key`.'); + expect.assertions(1); + return deleteVersion.run({}).catch(err => { + expect(err.message).toBe('No project API key provided. Please use `--key`.'); }); }); it('should error if no version provided', () => { - deleteVersion.run({ key }).catch(err => { - assert.equal( - err.message, + expect.assertions(1); + return deleteVersion.run({ key }).catch(err => { + expect(err.message).toBe( 'Please specify a semantic version. See `rdme help versions:delete` for help.', ); }); @@ -170,8 +172,9 @@ describe('rdme versions*', () => { .basicAuth({ user: key }) .reply(200); - await deleteVersion.run({ key, version }); - mockRequest.done(); + return deleteVersion.run({ key, version }).then(() => { + mockRequest.done(); + }); }); it('should catch any request errors', async () => { @@ -180,24 +183,25 @@ describe('rdme versions*', () => { .basicAuth({ user: key }) .reply(400); - await deleteVersion.run({ key, version }).catch(err => { - assert.equal(err.message, 'Failed to delete target version.'); + return deleteVersion.run({ key, version }).catch(err => { + expect(err.message).toBe('Failed to delete target version.'); + mockRequest.done(); }); - mockRequest.done(); }); }); describe('rdme versions:update', () => { it('should error if no api key provided', () => { - updateVersion.run({}).catch(err => { - assert.equal(err.message, 'No project API key provided. Please use `--key`.'); + expect.assertions(1); + return updateVersion.run({}).catch(err => { + expect(err.message).toBe('No project API key provided. Please use `--key`.'); }); }); it('should error if no version provided', () => { - updateVersion.run({ key }).catch(err => { - assert.equal( - err.message, + expect.assertions(1); + return updateVersion.run({ key }).catch(err => { + expect(err.message).toBe( 'Please specify a semantic version. See `rdme help versions:update` for help.', ); }); @@ -218,11 +222,13 @@ describe('rdme versions*', () => { .basicAuth({ user: key }) .reply(201, { version }); - await updateVersion.run({ key, version }); - mockRequest.done(); + return updateVersion.run({ key, version }).then(() => { + mockRequest.done(); + }); }); it('should catch any put request errors', async () => { + expect.assertions(1); promptHandler.createVersionPrompt.mockResolvedValue({ is_stable: false, is_beta: false, @@ -236,15 +242,10 @@ describe('rdme versions*', () => { .basicAuth({ user: key }) .reply(400); - await updateVersion - .run({ key, version }) - .then(() => { - assert.ok(false, 'error handling was not properly thrown on a bad request!'); - }) - .catch(() => { - assert.ok(true); - }); - mockRequest.done(); + return updateVersion.run({ key, version }).catch(err => { + expect(err.message).toBe('400 - undefined'); + mockRequest.done(); + }); }); }); }); diff --git a/test/cmds/whoami.test.js b/test/cmds/whoami.test.js index 1484fcc0f..701e9044f 100644 --- a/test/cmds/whoami.test.js +++ b/test/cmds/whoami.test.js @@ -1,38 +1,34 @@ -const assert = require('assert'); const config = require('config'); const configStore = require('../../lib/configstore'); const cmd = require('../../cmds/whoami'); const loginCmd = require('../../cmds/login'); describe('rdme whoami', () => { - it('should error if user is not authenticated', done => { + it('should error if user is not authenticated', () => { configStore.delete('email'); configStore.delete('project'); - cmd + return cmd .run({}) .then(() => { - assert.ok(false, 'unauthenticated error message not displayed'); + throw new Error('unauthenticated error message not displayed'); }) .catch(err => { - assert.equal(err.message, `Please login using \`${config.cli} ${loginCmd.command}\`.`); - return done(); + expect(err.message).toBe(`Please login using \`${config.cli} ${loginCmd.command}\`.`); }); }); - it('should return the authenticated user', done => { + it('should return the authenticated user', () => { configStore.set('email', 'email@example.com'); configStore.set('project', 'subdomain'); - cmd + return cmd .run({}) .then(() => { - assert.ok(true); - return done(); + expect(true).toBe(true); }) .catch(err => { - assert.ok(false, err); - return done(); + throw new Error(err); }); }); }); diff --git a/test/lib/commands.test.js b/test/lib/commands.test.js index 4a80eb7dd..b3835c3f8 100644 --- a/test/lib/commands.test.js +++ b/test/lib/commands.test.js @@ -1,84 +1,44 @@ -const assert = require('assert'); const commands = require('../../lib/commands').list(); describe('utils', () => { describe('#getCommands', () => { - it('should have commands returned', done => { - assert.notEqual(commands.length, 0); - done(); + it('should have commands returned', () => { + expect(commands).not.toHaveLength(0); }); describe('commands', () => { - it('should be configured properly', done => { + it('should be configured properly', () => { commands.forEach(c => { - const { file } = c; const cmd = c.command; - assert.ok( - typeof cmd.command === 'string' && cmd.command.length !== 0, - `${file} does not have a command name`, - ); - - assert.ok( - typeof cmd.usage === 'string' && cmd.usage.length !== 0, - `${file} does not have a described usage`, - ); - - assert.ok( - typeof cmd.description === 'string' && cmd.usage.description !== 0, - `${file} does not have a description`, - ); - - assert.ok( - typeof cmd.category === 'string' && cmd.usage.category !== 0, - `${file} does not have a category`, - ); - - assert.ok( - typeof cmd.position === 'number' && cmd.usage.position !== 0, - `${file} does not have a position`, - ); - - assert.ok(Array.isArray(cmd.args), `${file} does not have an args array defined`); - assert.ok(typeof cmd.run === 'function', `${file} does not have a callable runner`); + expect(typeof cmd.command === 'string' && cmd.command.length !== 0).toBeTruthy(); + expect(typeof cmd.usage === 'string' && cmd.usage.length !== 0).toBeTruthy(); + expect(typeof cmd.description === 'string' && cmd.usage.description !== 0).toBeTruthy(); + expect(typeof cmd.category === 'string' && cmd.usage.category !== 0).toBeTruthy(); + expect(typeof cmd.position === 'number' && cmd.usage.position !== 0).toBeTruthy(); + expect(Array.isArray(cmd.args)).toBeTruthy(); + expect(typeof cmd.run === 'function').toBeTruthy(); if (cmd.args.length > 0) { cmd.args.forEach(arg => { - assert.ok( - typeof arg.name === 'string' && arg.name.length !== 0, - `${file} has an arg without a name`, - ); - assert.ok(typeof arg.type !== 'undefined', `${file} has an arg without a type`); + expect(typeof arg.name === 'string' && arg.name.length !== 0).toBeTruthy(); + expect(typeof arg.type !== 'undefined').toBeTruthy(); }); } - assert.ok( - cmd.usage.indexOf(cmd.command) !== -1, - `the configured usage in ${file} does not contain ${cmd.command}`, - ); + expect(cmd.usage.indexOf(cmd.command) !== -1).toBeTruthy(); }); - - done(); }); - it('should abide by our cli standards', done => { + it('should abide by our cli standards', () => { commands.forEach(c => { - const { file } = c; const cmd = c.command; - assert.equal( - cmd.description[cmd.description.length - 1], - '.', - `the description for ${file} does not end in a period`, - ); + expect(cmd.description[cmd.description.length - 1]).toBe('.'); cmd.args.forEach(arg => { if (arg.name === 'key') { - assert.equal( - arg.description, - 'Project API key', - `the \`key\` arg in ${file} does not have our consistent description`, - ); + expect(arg.description).toBe('Project API key'); } else if (arg.name === 'version') { // If `version` is a hidden argument on the command, it won't have a description so // we don't need to bother with this test case. @@ -86,18 +46,14 @@ describe('utils', () => { return; } - assert.equal( - arg.description, + expect(arg.description).toBe( cmd.command !== 'versions' ? 'Project version' : 'A specific project version to view', - `the \`version\` arg in ${file} does not have our consistent description`, ); } }); }); - - done(); }); }); }); diff --git a/test/lib/prompts.test.js b/test/lib/prompts.test.js index 1d6030364..5c60c2ded 100644 --- a/test/lib/prompts.test.js +++ b/test/lib/prompts.test.js @@ -1,4 +1,3 @@ -const assert = require('assert'); const Enquirer = require('enquirer'); const promptHandler = require('../../lib/prompts'); @@ -38,11 +37,11 @@ describe('prompt test bed', () => { } if (prompt.name === 'versionSelection') { - assert.equal(await prompt.skip(), true); + expect(await prompt.skip()).toBe(true); } if (prompt.name === 'newVersion') { - // eslint-disable-next-line + // eslint-disable-next-line require-atomic-updates, no-param-reassign prompt.value = '1.2.1'; await prompt.submit(); } @@ -60,7 +59,7 @@ describe('prompt test bed', () => { }); const answer = await enquirer.prompt(promptHandler.generatePrompts(versionlist)); - assert.equal(answer.versionSelection, '1'); + expect(answer.versionSelection).toBe('1'); }); }); @@ -72,8 +71,8 @@ describe('prompt test bed', () => { }); const answer = await enquirer.prompt(promptHandler.createOasPrompt([{}])); - assert.equal(answer.option, 'create'); - assert.equal(answer.specId, ''); + expect(answer.option).toBe('create'); + expect(answer.specId).toBe(''); }); it('should return specId if user chooses to update file', async () => { @@ -85,8 +84,8 @@ describe('prompt test bed', () => { }); const answer = await enquirer.prompt(promptHandler.createOasPrompt(specList)); - assert.equal(answer.option, 'update'); - assert.equal(answer.specId, 'spec1'); + expect(answer.option).toBe('update'); + expect(answer.specId).toBe('spec1'); }); }); @@ -99,7 +98,7 @@ describe('prompt test bed', () => { await prompt.keypress(null, { name: 'up' }); await prompt.submit(); if (prompt.name === 'newVersion') { - // eslint-disable-next-line + // eslint-disable-next-line require-atomic-updates, no-param-reassign prompt.value = '1.2.1'; await prompt.submit(); } @@ -107,8 +106,8 @@ describe('prompt test bed', () => { const answer = await enquirer.prompt( promptHandler.createVersionPrompt(versionlist, opts, false), ); - assert.equal(answer.is_hidden, false); - assert.equal(answer.from, '1'); + expect(answer.is_hidden).toBe(false); + expect(answer.from).toBe('1'); }); it('should skip fork prompt if value passed', async () => { @@ -123,7 +122,7 @@ describe('prompt test bed', () => { enquirer.on('prompt', async prompt => { if (prompt.name === 'newVersion') { - // eslint-disable-next-line + // eslint-disable-next-line no-param-reassign prompt.value = '1.2.1'; await prompt.submit(); } @@ -134,8 +133,8 @@ describe('prompt test bed', () => { const answer = await enquirer.prompt( promptHandler.createVersionPrompt(versionlist, opts, true), ); - assert.equal(answer.is_hidden, false); - assert.equal(answer.from, ''); + expect(answer.is_hidden).toBe(false); + expect(answer.from).toBe(''); }); }); });