diff --git a/docs/lib/content/commands/npm-doctor.md b/docs/lib/content/commands/npm-doctor.md index 3abb1e29a24e2..5682f20b4cb5b 100644 --- a/docs/lib/content/commands/npm-doctor.md +++ b/docs/lib/content/commands/npm-doctor.md @@ -31,8 +31,10 @@ Also, in addition to this, there are also very many issue reports due to using old versions of npm. Since npm is constantly improving, running `npm@latest` is better than an old version. -`npm doctor` verifies the following items in your environment, and if there -are any recommended changes, it will display them. +`npm doctor` verifies the following items in your environment, and if +there are any recommended changes, it will display them. By default npm +runs all of these checks. You can limit what checks are ran by +specifying them as extra arguments. #### `npm ping` diff --git a/lib/commands/doctor.js b/lib/commands/doctor.js index 5dc3aa0db55a8..82d6354dd597b 100644 --- a/lib/commands/doctor.js +++ b/lib/commands/doctor.js @@ -34,30 +34,104 @@ const maskLabel = mask => { return label.join(', ') } +const subcommands = [ + { + groups: ['ping', 'registry'], + title: 'npm ping', + cmd: 'checkPing', + }, { + groups: ['versions'], + title: 'npm -v', + cmd: 'getLatestNpmVersion', + }, { + groups: ['versions'], + title: 'node -v', + cmd: 'getLatestNodejsVersion', + }, { + groups: ['registry'], + title: 'npm config get registry', + cmd: 'checkNpmRegistry', + }, { + groups: ['environment'], + title: 'git executable in PATH', + cmd: 'getGitPath', + }, { + groups: ['environment'], + title: 'global bin folder in PATH', + cmd: 'getBinPath', + }, { + groups: ['permissions', 'cache'], + title: 'Perms check on cached files', + cmd: 'checkCachePermission', + windows: false, + }, { + groups: ['permissions'], + title: 'Perms check on local node_modules', + cmd: 'checkLocalModulesPermission', + windows: false, + }, { + groups: ['permissions'], + title: 'Perms check on global node_modules', + cmd: 'checkGlobalModulesPermission', + windows: false, + }, { + groups: ['permissions'], + title: 'Perms check on local bin folder', + cmd: 'checkLocalBinPermission', + windows: false, + }, { + groups: ['permissions'], + title: 'Perms check on global bin folder', + cmd: 'checkGlobalBinPermission', + windows: false, + }, { + groups: ['cache'], + title: 'Verify cache contents', + cmd: 'verifyCachedFiles', + windows: false, + }, + // TODO: + // group === 'dependencies'? + // - ensure arborist.loadActual() runs without errors and no invalid edges + // - ensure package-lock.json matches loadActual() + // - verify loadActual without hidden lock file matches hidden lockfile + // group === '???' + // - verify all local packages have bins linked + // What is the fix for these? +] const BaseCommand = require('../base-command.js') class Doctor extends BaseCommand { static description = 'Check your npm environment' static name = 'doctor' static params = ['registry'] static ignoreImplicitWorkspace = false + static usage = [`[${subcommands.flatMap(s => s.groups) + .filter((value, index, self) => self.indexOf(value) === index) + .join('] [')}]`] + + static subcommands = subcommands + + // minimum width of check column, enough for the word `Check` + #checkWidth = 5 async exec (args) { log.info('Running checkup') let allOk = true const actions = this.actions(args) - this.checkWidth = actions.reduce((length, item) => Math.max(item[0].length, length), 5) + this.#checkWidth = actions.reduce((length, item) => + Math.max(item.title.length, length), this.#checkWidth) if (!this.npm.silent) { this.output(['Check', 'Value', 'Recommendation/Notes'].map(h => this.npm.chalk.underline(h))) } // Do the actual work - for (const [msg, fn, args] of actions) { - const item = [msg] + for (const { title, cmd } of actions) { + const item = [title] try { - item.push(true, await this[fn](...args)) - } catch (er) { - item.push(false, er) + item.push(true, await this[cmd]()) + } catch (err) { + item.push(false, err) } if (!item[1]) { allOk = false @@ -72,11 +146,12 @@ class Doctor extends BaseCommand { } } - if (!this.npm.silent) { - // this.npm.output(table(outTable, tableOpts)) - } if (!allOk) { - throw new Error('Some problems found. See above for recommendations.') + if (this.npm.silent) { + throw new Error('Some problems found. Check logs or disable silent mode for recommendations.') + } else { + throw new Error('Some problems found. See above for recommendations.') + } } } @@ -144,15 +219,35 @@ class Doctor extends BaseCommand { } } - async checkBinPath (dir) { - const tracker = log.newItem('checkBinPath', 1) - tracker.info('checkBinPath', 'Finding npm global bin in your PATH') + async getBinPath (dir) { + const tracker = log.newItem('getBinPath', 1) + tracker.info('getBinPath', 'Finding npm global bin in your PATH') if (!process.env.PATH.includes(this.npm.globalBin)) { throw new Error(`Add ${this.npm.globalBin} to your $PATH`) } return this.npm.globalBin } + async checkCachePermission () { + return this.checkFilesPermission(this.npm.cache, true, R_OK) + } + + async checkLocalModulesPermission () { + return this.checkFilesPermission(this.npm.localDir, true, R_OK | W_OK, true) + } + + async checkGlobalModulesPermission () { + return this.checkFilesPermission(this.npm.globalDir, false, R_OK) + } + + async checkLocalBinPermission () { + return this.checkFilesPermission(this.npm.localBin, false, R_OK | W_OK | X_OK, true) + } + + async checkGlobalBinPermission () { + return this.checkFilesPermission(this.npm.globalBin, false, X_OK) + } + async checkFilesPermission (root, shouldOwn, mask, missingOk) { let ok = true @@ -293,79 +388,22 @@ class Doctor extends BaseCommand { 'right-mid': '', middle: ' ' }, style: { 'padding-left': 0, 'padding-right': 0 }, - colWidths: [this.checkWidth, 6], + colWidths: [this.#checkWidth, 6], }) t.push(row) this.npm.output(t.toString()) } - actions (subcmds) { - const a = [] - if (!subcmds.length || subcmds.includes('ping')) { - a.push(['npm ping', 'checkPing', []]) - } - if (!subcmds.length || subcmds.includes('versions')) { - a.push(['npm -v', 'getLatestNpmVersion', []]) - a.push(['node -v', 'getLatestNodejsVersion', []]) - } - if (!subcmds.length || subcmds.includes('registry')) { - a.push(['npm config get registry', 'checkNpmRegistry', []]) - } - if (!subcmds.length || subcmds.includes('git')) { - a.push(['which git', 'getGitPath', []]) - } - if (!subcmds.length || subcmds.includes('permissions')) { - if (subcmds.includes('permissions') && process.platform === 'win32') { - log.warn('Ignoring permissions checks for windows') - } else if (process.platform !== 'win32') { - a.push([ - 'Perms check on cached files', - 'checkFilesPermission', - [this.npm.cache, true, R_OK], - ]) - a.push([ - 'Perms check on local node_modules', - 'checkFilesPermission', - [this.npm.localDir, true, R_OK | W_OK, true], - ]) - a.push([ - 'Perms check on global node_modules', - 'checkFilesPermission', - [this.npm.globalDir, false, R_OK], - ]) - a.push([ - 'Perms check on local bin folder', - 'checkFilesPermission', - [this.npm.localBin, false, R_OK | W_OK | X_OK, true], - ]) - a.push([ - 'Perms check on global bin folder', - 'checkFilesPermission', - [this.npm.globalBin, false, X_OK], - ]) + actions (params) { + return this.constructor.subcommands.filter(subcmd => { + if (process.platform === 'win32' && subcmd.windows === false) { + return false } - } - if (!subcmds.length || subcmds.includes('cache')) { - a.push([ - 'Verify cache contents', - 'verifyCachedFiles', - [this.npm.flatOptions.cache], - ]) - } - - if (!subcmds.length || subcmds.includes('environment')) { - a.push(['Global bin folder in PATH', 'checkBinPath', []]) - } - - // TODO: - // subcmd === 'dependencies'? - // - ensure arborist.loadActual() runs without errors and no invalid edges - // - ensure package-lock.json matches loadActual() - // - verify loadActual without hidden lock file matches hidden lockfile - // subcmd === '???' - // - verify all local packages have bins linked - // What is the fix for these? - return a + if (params.length) { + return params.some(param => subcmd.groups.includes(param)) + } + return true + }) } } diff --git a/tap-snapshots/test/lib/commands/doctor.js.test.cjs b/tap-snapshots/test/lib/commands/doctor.js.test.cjs index 52a90f6843be2..8d21f98e4892c 100644 --- a/tap-snapshots/test/lib/commands/doctor.js.test.cjs +++ b/tap-snapshots/test/lib/commands/doctor.js.test.cjs @@ -28,6 +28,10 @@ Object { "getGitPath", "Finding git in your PATH", ], + Array [ + "getBinPath", + "Finding npm global bin in your PATH", + ], Array [ "verifyCachedFiles", "Verifying the npm cache", @@ -43,10 +47,6 @@ Object { } ), ], - Array [ - "checkBinPath", - "Finding npm global bin in your PATH", - ], ], "warn": Array [], } @@ -58,14 +58,14 @@ npm ping  ok   npm -v  ok  current: v1.0.0, latest: v1.0.0 node -v  ok  current: v1.0.0, recommended: v1.0.0 npm config get registry  ok  using default registry (https://registry.npmjs.org/) -which git  ok  /path/to/git +git executable in PATH  ok  /path/to/git +global bin folder in PATH  ok  {CWD}/test/lib/commands/tap-testdir-doctor-all-clear/global/bin Perms check on cached files  ok   Perms check on local node_modules  ok   Perms check on global node_modules ok   Perms check on local bin folder  ok   Perms check on global bin folder  ok   Verify cache contents  ok  verified 0 tarballs -Global bin folder in PATH  ok  {CWD}/test/lib/commands/tap-testdir-doctor-all-clear/global/bin ` exports[`test/lib/commands/doctor.js TAP all clear in color > everything is ok in color 1`] = ` @@ -74,14 +74,14 @@ npm ping  ok   npm -v  ok  current: v1.0.0, latest: v1.0.0 node -v  ok  current: v1.0.0, recommended: v1.0.0 npm config get registry  ok  using default registry (https://registry.npmjs.org/) -which git  ok  /path/to/git +git executable in PATH  ok  /path/to/git +global bin folder in PATH  ok  {CWD}/test/lib/commands/tap-testdir-doctor-all-clear-in-color/global/bin Perms check on cached files  ok   Perms check on local node_modules  ok   Perms check on global node_modules ok   Perms check on local bin folder  ok   Perms check on global bin folder  ok   Verify cache contents  ok  verified 0 tarballs -Global bin folder in PATH  ok  {CWD}/test/lib/commands/tap-testdir-doctor-all-clear-in-color/global/bin ` exports[`test/lib/commands/doctor.js TAP all clear in color > logs 1`] = ` @@ -107,6 +107,10 @@ Object { "getGitPath", "Finding git in your PATH", ], + Array [ + "getBinPath", + "Finding npm global bin in your PATH", + ], Array [ "verifyCachedFiles", "Verifying the npm cache", @@ -122,10 +126,6 @@ Object { } ), ], - Array [ - "checkBinPath", - "Finding npm global bin in your PATH", - ], ], "warn": Array [], } @@ -154,6 +154,10 @@ Object { "getGitPath", "Finding git in your PATH", ], + Array [ + "getBinPath", + "Finding npm global bin in your PATH", + ], Array [ "verifyCachedFiles", "Verifying the npm cache", @@ -169,10 +173,6 @@ Object { } ), ], - Array [ - "checkBinPath", - "Finding npm global bin in your PATH", - ], ], "warn": Array [], } @@ -184,14 +184,14 @@ npm ping  not ok unsupported prox npm -v  not ok Error: unsupported proxy protocol: 'ssh:' node -v  not ok Error: unsupported proxy protocol: 'ssh:' npm config get registry  ok  using default registry (https://registry.npmjs.org/) -which git  ok  /path/to/git +git executable in PATH  ok  /path/to/git +global bin folder in PATH  ok  {CWD}/test/lib/commands/tap-testdir-doctor-bad-proxy/global/bin Perms check on cached files  ok   Perms check on local node_modules  ok   Perms check on global node_modules ok   Perms check on local bin folder  ok   Perms check on global bin folder  ok   Verify cache contents  ok  verified 0 tarballs -Global bin folder in PATH  ok  {CWD}/test/lib/commands/tap-testdir-doctor-bad-proxy/global/bin ` exports[`test/lib/commands/doctor.js TAP cacache badContent > corrupted cache content 1`] = ` @@ -200,14 +200,14 @@ npm ping  ok   npm -v  ok  current: v1.0.0, latest: v1.0.0 node -v  ok  current: v1.0.0, recommended: v1.0.0 npm config get registry  ok  using default registry (https://registry.npmjs.org/) -which git  ok  /path/to/git +git executable in PATH  ok  /path/to/git +global bin folder in PATH  ok  {CWD}/test/lib/commands/tap-testdir-doctor-cacache-badContent/global/bin Perms check on cached files  ok   Perms check on local node_modules  ok   Perms check on global node_modules ok   Perms check on local bin folder  ok   Perms check on global bin folder  ok   Verify cache contents  ok  verified 2 tarballs -Global bin folder in PATH  ok  {CWD}/test/lib/commands/tap-testdir-doctor-cacache-badContent/global/bin ` exports[`test/lib/commands/doctor.js TAP cacache badContent > logs 1`] = ` @@ -233,6 +233,10 @@ Object { "getGitPath", "Finding git in your PATH", ], + Array [ + "getBinPath", + "Finding npm global bin in your PATH", + ], Array [ "verifyCachedFiles", "Verifying the npm cache", @@ -248,10 +252,6 @@ Object { } ), ], - Array [ - "checkBinPath", - "Finding npm global bin in your PATH", - ], ], "warn": Array [ Array [ @@ -289,6 +289,10 @@ Object { "getGitPath", "Finding git in your PATH", ], + Array [ + "getBinPath", + "Finding npm global bin in your PATH", + ], Array [ "verifyCachedFiles", "Verifying the npm cache", @@ -304,10 +308,6 @@ Object { } ), ], - Array [ - "checkBinPath", - "Finding npm global bin in your PATH", - ], ], "warn": Array [ Array [ @@ -328,14 +328,14 @@ npm ping  ok   npm -v  ok  current: v1.0.0, latest: v1.0.0 node -v  ok  current: v1.0.0, recommended: v1.0.0 npm config get registry  ok  using default registry (https://registry.npmjs.org/) -which git  ok  /path/to/git +git executable in PATH  ok  /path/to/git +global bin folder in PATH  ok  {CWD}/test/lib/commands/tap-testdir-doctor-cacache-missingContent/global/bin Perms check on cached files  ok   Perms check on local node_modules  ok   Perms check on global node_modules ok   Perms check on local bin folder  ok   Perms check on global bin folder  ok   Verify cache contents  ok  verified 2 tarballs -Global bin folder in PATH  ok  {CWD}/test/lib/commands/tap-testdir-doctor-cacache-missingContent/global/bin ` exports[`test/lib/commands/doctor.js TAP cacache reclaimedCount > content garbage collected 1`] = ` @@ -344,14 +344,14 @@ npm ping  ok   npm -v  ok  current: v1.0.0, latest: v1.0.0 node -v  ok  current: v1.0.0, recommended: v1.0.0 npm config get registry  ok  using default registry (https://registry.npmjs.org/) -which git  ok  /path/to/git +git executable in PATH  ok  /path/to/git +global bin folder in PATH  ok  {CWD}/test/lib/commands/tap-testdir-doctor-cacache-reclaimedCount/global/bin Perms check on cached files  ok   Perms check on local node_modules  ok   Perms check on global node_modules ok   Perms check on local bin folder  ok   Perms check on global bin folder  ok   Verify cache contents  ok  verified 2 tarballs -Global bin folder in PATH  ok  {CWD}/test/lib/commands/tap-testdir-doctor-cacache-reclaimedCount/global/bin ` exports[`test/lib/commands/doctor.js TAP cacache reclaimedCount > logs 1`] = ` @@ -377,6 +377,10 @@ Object { "getGitPath", "Finding git in your PATH", ], + Array [ + "getBinPath", + "Finding npm global bin in your PATH", + ], Array [ "verifyCachedFiles", "Verifying the npm cache", @@ -392,10 +396,6 @@ Object { } ), ], - Array [ - "checkBinPath", - "Finding npm global bin in your PATH", - ], ], "warn": Array [ Array [ @@ -438,8 +438,9 @@ Object { ` exports[`test/lib/commands/doctor.js TAP discrete checks cache > output 1`] = ` -Check  Value  Recommendation/Notes -Verify cache contents ok  verified 0 tarballs +Check  Value  Recommendation/Notes +Perms check on cached files ok   +Verify cache contents  ok  verified 0 tarballs ` exports[`test/lib/commands/doctor.js TAP discrete checks git > logs 1`] = ` @@ -449,18 +450,13 @@ Object { Array [ "Running checkup", ], - Array [ - "getGitPath", - "Finding git in your PATH", - ], ], "warn": Array [], } ` exports[`test/lib/commands/doctor.js TAP discrete checks git > output 1`] = ` -Check  Value  Recommendation/Notes -which git ok  /path/to/git +Check Value  Recommendation/Notes ` exports[`test/lib/commands/doctor.js TAP discrete checks invalid environment > logs 1`] = ` @@ -471,7 +467,11 @@ Object { "Running checkup", ], Array [ - "checkBinPath", + "getGitPath", + "Finding git in your PATH", + ], + Array [ + "getBinPath", "Finding npm global bin in your PATH", ], ], @@ -481,7 +481,8 @@ Object { exports[`test/lib/commands/doctor.js TAP discrete checks invalid environment > output 1`] = ` Check  Value  Recommendation/Notes -Global bin folder in PATH not ok Error: Add {CWD}/test/lib/commands/tap-testdir-doctor-discrete-checks-invalid-environment/global/bin to your $PATH +git executable in PATH  ok  /path/to/git +global bin folder in PATH not ok Error: Add {CWD}/test/lib/commands/tap-testdir-doctor-discrete-checks-invalid-environment/global/bin to your $PATH ` exports[`test/lib/commands/doctor.js TAP discrete checks permissions - not windows > logs 1`] = ` @@ -513,11 +514,7 @@ Object { "Running checkup", ], ], - "warn": Array [ - Array [ - "Ignoring permissions checks for windows", - ], - ], + "warn": Array [], } ` @@ -553,6 +550,10 @@ Object { Array [ "Running checkup", ], + Array [ + "checkPing", + "Pinging registry", + ], ], "warn": Array [], } @@ -560,6 +561,7 @@ Object { exports[`test/lib/commands/doctor.js TAP discrete checks registry > output 1`] = ` Check  Value  Recommendation/Notes +npm ping  ok   npm config get registry ok  using default registry (https://registry.npmjs.org/) ` @@ -612,6 +614,10 @@ Object { "getGitPath", "Finding git in your PATH", ], + Array [ + "getBinPath", + "Finding npm global bin in your PATH", + ], Array [ "verifyCachedFiles", "Verifying the npm cache", @@ -627,10 +633,6 @@ Object { } ), ], - Array [ - "checkBinPath", - "Finding npm global bin in your PATH", - ], ], "warn": Array [ Array [ @@ -663,14 +665,14 @@ npm ping  ok   npm -v  ok  current: v1.0.0, latest: v1.0.0 node -v  ok  current: v1.0.0, recommended: v1.0.0 npm config get registry  ok  using default registry (https://registry.npmjs.org/) -which git  ok  /path/to/git +git executable in PATH  ok  /path/to/git +global bin folder in PATH  ok  {CWD}/test/lib/commands/tap-testdir-doctor-error-reading-directory/global/bin Perms check on cached files  not ok Check the permissions of files in {CWD}/test/lib/commands/tap-testdir-doctor-error-reading-directory/cache (should be owned by current user) Perms check on local node_modules  not ok Check the permissions of files in {CWD}/test/lib/commands/tap-testdir-doctor-error-reading-directory/prefix/node_modules (should be owned by current user) Perms check on global node_modules not ok Check the permissions of files in {CWD}/test/lib/commands/tap-testdir-doctor-error-reading-directory/global/lib/node_modules Perms check on local bin folder  not ok Check the permissions of files in {CWD}/test/lib/commands/tap-testdir-doctor-error-reading-directory/prefix/node_modules/.bin Perms check on global bin folder  not ok Check the permissions of files in {CWD}/test/lib/commands/tap-testdir-doctor-error-reading-directory/global/bin Verify cache contents  ok  verified 0 tarballs -Global bin folder in PATH  ok  {CWD}/test/lib/commands/tap-testdir-doctor-error-reading-directory/global/bin ` exports[`test/lib/commands/doctor.js TAP incorrect owner > incorrect owner 1`] = ` @@ -679,14 +681,14 @@ npm ping  ok   npm -v  ok  current: v1.0.0, latest: v1.0.0 node -v  ok  current: v1.0.0, recommended: v1.0.0 npm config get registry  ok  using default registry (https://registry.npmjs.org/) -which git  ok  /path/to/git +git executable in PATH  ok  /path/to/git +global bin folder in PATH  ok  {CWD}/test/lib/commands/tap-testdir-doctor-incorrect-owner/global/bin Perms check on cached files  not ok Check the permissions of files in {CWD}/test/lib/commands/tap-testdir-doctor-incorrect-owner/cache (should be owned by current user) Perms check on local node_modules  ok   Perms check on global node_modules ok   Perms check on local bin folder  ok   Perms check on global bin folder  ok   Verify cache contents  ok  verified 0 tarballs -Global bin folder in PATH  ok  {CWD}/test/lib/commands/tap-testdir-doctor-incorrect-owner/global/bin ` exports[`test/lib/commands/doctor.js TAP incorrect owner > logs 1`] = ` @@ -712,6 +714,10 @@ Object { "getGitPath", "Finding git in your PATH", ], + Array [ + "getBinPath", + "Finding npm global bin in your PATH", + ], Array [ "verifyCachedFiles", "Verifying the npm cache", @@ -727,10 +733,6 @@ Object { } ), ], - Array [ - "checkBinPath", - "Finding npm global bin in your PATH", - ], ], "warn": Array [ Array [ @@ -747,14 +749,14 @@ npm ping  ok   npm -v  ok  current: v1.0.0, latest: v1.0.0 node -v  ok  current: v1.0.0, recommended: v1.0.0 npm config get registry  ok  using default registry (https://registry.npmjs.org/) -which git  ok  /path/to/git +git executable in PATH  ok  /path/to/git +global bin folder in PATH  ok  {CWD}/test/lib/commands/tap-testdir-doctor-incorrect-permissions/global/bin Perms check on cached files  not ok Check the permissions of files in {CWD}/test/lib/commands/tap-testdir-doctor-incorrect-permissions/cache (should be owned by current user) Perms check on local node_modules  not ok Check the permissions of files in {CWD}/test/lib/commands/tap-testdir-doctor-incorrect-permissions/prefix/node_modules (should be owned by current user) Perms check on global node_modules not ok Check the permissions of files in {CWD}/test/lib/commands/tap-testdir-doctor-incorrect-permissions/global/lib/node_modules Perms check on local bin folder  not ok Check the permissions of files in {CWD}/test/lib/commands/tap-testdir-doctor-incorrect-permissions/prefix/node_modules/.bin Perms check on global bin folder  not ok Check the permissions of files in {CWD}/test/lib/commands/tap-testdir-doctor-incorrect-permissions/global/bin Verify cache contents  ok  verified 0 tarballs -Global bin folder in PATH  ok  {CWD}/test/lib/commands/tap-testdir-doctor-incorrect-permissions/global/bin ` exports[`test/lib/commands/doctor.js TAP incorrect permissions > logs 1`] = ` @@ -801,6 +803,10 @@ Object { "getGitPath", "Finding git in your PATH", ], + Array [ + "getBinPath", + "Finding npm global bin in your PATH", + ], Array [ "verifyCachedFiles", "Verifying the npm cache", @@ -816,10 +822,6 @@ Object { } ), ], - Array [ - "checkBinPath", - "Finding npm global bin in your PATH", - ], ], "warn": Array [], } @@ -848,6 +850,10 @@ Object { "getGitPath", "Finding git in your PATH", ], + Array [ + "getBinPath", + "Finding npm global bin in your PATH", + ], Array [ "verifyCachedFiles", "Verifying the npm cache", @@ -863,10 +869,6 @@ Object { } ), ], - Array [ - "checkBinPath", - "Finding npm global bin in your PATH", - ], ], "warn": Array [ Array [ @@ -882,14 +884,14 @@ npm ping  ok   npm -v  ok  current: v1.0.0, latest: v1.0.0 node -v  ok  current: v1.0.0, recommended: v1.0.0 npm config get registry  ok  using default registry (https://registry.npmjs.org/) -which git  not ok Error: Install git and ensure it's in your PATH. +git executable in PATH  not ok Error: Install git and ensure it's in your PATH. +global bin folder in PATH  ok  {CWD}/test/lib/commands/tap-testdir-doctor-missing-git/global/bin Perms check on cached files  ok   Perms check on local node_modules  ok   Perms check on global node_modules ok   Perms check on local bin folder  ok   Perms check on global bin folder  ok   Verify cache contents  ok  verified 0 tarballs -Global bin folder in PATH  ok  {CWD}/test/lib/commands/tap-testdir-doctor-missing-git/global/bin ` exports[`test/lib/commands/doctor.js TAP missing global directories > logs 1`] = ` @@ -915,6 +917,10 @@ Object { "getGitPath", "Finding git in your PATH", ], + Array [ + "getBinPath", + "Finding npm global bin in your PATH", + ], Array [ "verifyCachedFiles", "Verifying the npm cache", @@ -930,10 +936,6 @@ Object { } ), ], - Array [ - "checkBinPath", - "Finding npm global bin in your PATH", - ], ], "warn": Array [ Array [ @@ -954,14 +956,14 @@ npm ping  ok   npm -v  ok  current: v1.0.0, latest: v1.0.0 node -v  ok  current: v1.0.0, recommended: v1.0.0 npm config get registry  ok  using default registry (https://registry.npmjs.org/) -which git  ok  /path/to/git +git executable in PATH  ok  /path/to/git +global bin folder in PATH  ok  {CWD}/test/lib/commands/tap-testdir-doctor-missing-global-directories/global/bin Perms check on cached files  ok   Perms check on local node_modules  ok   Perms check on global node_modules not ok Check the permissions of files in {CWD}/test/lib/commands/tap-testdir-doctor-missing-global-directories/global/lib/node_modules Perms check on local bin folder  ok   Perms check on global bin folder  not ok Check the permissions of files in {CWD}/test/lib/commands/tap-testdir-doctor-missing-global-directories/global/bin Verify cache contents  ok  verified 0 tarballs -Global bin folder in PATH  ok  {CWD}/test/lib/commands/tap-testdir-doctor-missing-global-directories/global/bin ` exports[`test/lib/commands/doctor.js TAP missing local node_modules > logs 1`] = ` @@ -987,6 +989,10 @@ Object { "getGitPath", "Finding git in your PATH", ], + Array [ + "getBinPath", + "Finding npm global bin in your PATH", + ], Array [ "verifyCachedFiles", "Verifying the npm cache", @@ -1002,10 +1008,6 @@ Object { } ), ], - Array [ - "checkBinPath", - "Finding npm global bin in your PATH", - ], ], "warn": Array [], } @@ -1017,14 +1019,14 @@ npm ping  ok   npm -v  ok  current: v1.0.0, latest: v1.0.0 node -v  ok  current: v1.0.0, recommended: v1.0.0 npm config get registry  ok  using default registry (https://registry.npmjs.org/) -which git  ok  /path/to/git +git executable in PATH  ok  /path/to/git +global bin folder in PATH  ok  {CWD}/test/lib/commands/tap-testdir-doctor-missing-local-node_modules/global/bin Perms check on cached files  ok   Perms check on local node_modules  ok   Perms check on global node_modules ok   Perms check on local bin folder  ok   Perms check on global bin folder  ok   Verify cache contents  ok  verified 0 tarballs -Global bin folder in PATH  ok  {CWD}/test/lib/commands/tap-testdir-doctor-missing-local-node_modules/global/bin ` exports[`test/lib/commands/doctor.js TAP node out of date - current > logs 1`] = ` @@ -1050,6 +1052,10 @@ Object { "getGitPath", "Finding git in your PATH", ], + Array [ + "getBinPath", + "Finding npm global bin in your PATH", + ], Array [ "verifyCachedFiles", "Verifying the npm cache", @@ -1065,10 +1071,6 @@ Object { } ), ], - Array [ - "checkBinPath", - "Finding npm global bin in your PATH", - ], ], "warn": Array [], } @@ -1080,14 +1082,14 @@ npm ping  ok   npm -v  ok  current: v1.0.0, latest: v1.0.0 node -v  not ok Use node v2.0.1 (current: v2.0.0) npm config get registry  ok  using default registry (https://registry.npmjs.org/) -which git  ok  /path/to/git +git executable in PATH  ok  /path/to/git +global bin folder in PATH  ok  {CWD}/test/lib/commands/tap-testdir-doctor-node-out-of-date---current/global/bin Perms check on cached files  ok   Perms check on local node_modules  ok   Perms check on global node_modules ok   Perms check on local bin folder  ok   Perms check on global bin folder  ok   Verify cache contents  ok  verified 0 tarballs -Global bin folder in PATH  ok  {CWD}/test/lib/commands/tap-testdir-doctor-node-out-of-date---current/global/bin ` exports[`test/lib/commands/doctor.js TAP node out of date - lts > logs 1`] = ` @@ -1113,6 +1115,10 @@ Object { "getGitPath", "Finding git in your PATH", ], + Array [ + "getBinPath", + "Finding npm global bin in your PATH", + ], Array [ "verifyCachedFiles", "Verifying the npm cache", @@ -1128,10 +1134,6 @@ Object { } ), ], - Array [ - "checkBinPath", - "Finding npm global bin in your PATH", - ], ], "warn": Array [], } @@ -1143,14 +1145,14 @@ npm ping  ok   npm -v  ok  current: v1.0.0, latest: v1.0.0 node -v  not ok Use node v1.0.0 (current: v0.0.1) npm config get registry  ok  using default registry (https://registry.npmjs.org/) -which git  ok  /path/to/git +git executable in PATH  ok  /path/to/git +global bin folder in PATH  ok  {CWD}/test/lib/commands/tap-testdir-doctor-node-out-of-date---lts/global/bin Perms check on cached files  ok   Perms check on local node_modules  ok   Perms check on global node_modules ok   Perms check on local bin folder  ok   Perms check on global bin folder  ok   Verify cache contents  ok  verified 0 tarballs -Global bin folder in PATH  ok  {CWD}/test/lib/commands/tap-testdir-doctor-node-out-of-date---lts/global/bin ` exports[`test/lib/commands/doctor.js TAP non-default registry > logs 1`] = ` @@ -1176,6 +1178,10 @@ Object { "getGitPath", "Finding git in your PATH", ], + Array [ + "getBinPath", + "Finding npm global bin in your PATH", + ], Array [ "verifyCachedFiles", "Verifying the npm cache", @@ -1191,10 +1197,6 @@ Object { } ), ], - Array [ - "checkBinPath", - "Finding npm global bin in your PATH", - ], ], "warn": Array [], } @@ -1206,14 +1208,14 @@ npm ping  ok   npm -v  ok  current: v1.0.0, latest: v1.0.0 node -v  ok  current: v1.0.0, recommended: v1.0.0 npm config get registry  not ok Try \`npm config set registry=https://registry.npmjs.org/\` -which git  ok  /path/to/git +git executable in PATH  ok  /path/to/git +global bin folder in PATH  ok  {CWD}/test/lib/commands/tap-testdir-doctor-non-default-registry/global/bin Perms check on cached files  ok   Perms check on local node_modules  ok   Perms check on global node_modules ok   Perms check on local bin folder  ok   Perms check on global bin folder  ok   Verify cache contents  ok  verified 0 tarballs -Global bin folder in PATH  ok  {CWD}/test/lib/commands/tap-testdir-doctor-non-default-registry/global/bin ` exports[`test/lib/commands/doctor.js TAP npm out of date > logs 1`] = ` @@ -1239,6 +1241,10 @@ Object { "getGitPath", "Finding git in your PATH", ], + Array [ + "getBinPath", + "Finding npm global bin in your PATH", + ], Array [ "verifyCachedFiles", "Verifying the npm cache", @@ -1254,10 +1260,6 @@ Object { } ), ], - Array [ - "checkBinPath", - "Finding npm global bin in your PATH", - ], ], "warn": Array [], } @@ -1269,14 +1271,14 @@ npm ping  ok   npm -v  not ok Use npm v2.0.0 node -v  ok  current: v1.0.0, recommended: v1.0.0 npm config get registry  ok  using default registry (https://registry.npmjs.org/) -which git  ok  /path/to/git +git executable in PATH  ok  /path/to/git +global bin folder in PATH  ok  {CWD}/test/lib/commands/tap-testdir-doctor-npm-out-of-date/global/bin Perms check on cached files  ok   Perms check on local node_modules  ok   Perms check on global node_modules ok   Perms check on local bin folder  ok   Perms check on global bin folder  ok   Verify cache contents  ok  verified 0 tarballs -Global bin folder in PATH  ok  {CWD}/test/lib/commands/tap-testdir-doctor-npm-out-of-date/global/bin ` exports[`test/lib/commands/doctor.js TAP ping 404 > logs 1`] = ` @@ -1302,6 +1304,10 @@ Object { "getGitPath", "Finding git in your PATH", ], + Array [ + "getBinPath", + "Finding npm global bin in your PATH", + ], Array [ "verifyCachedFiles", "Verifying the npm cache", @@ -1317,10 +1323,6 @@ Object { } ), ], - Array [ - "checkBinPath", - "Finding npm global bin in your PATH", - ], ], "warn": Array [], } @@ -1332,14 +1334,14 @@ npm ping  not ok 404 404 Not Foun npm -v  ok  current: v1.0.0, latest: v1.0.0 node -v  ok  current: v1.0.0, recommended: v1.0.0 npm config get registry  ok  using default registry (https://registry.npmjs.org/) -which git  ok  /path/to/git +git executable in PATH  ok  /path/to/git +global bin folder in PATH  ok  {CWD}/test/lib/commands/tap-testdir-doctor-ping-404/global/bin Perms check on cached files  ok   Perms check on local node_modules  ok   Perms check on global node_modules ok   Perms check on local bin folder  ok   Perms check on global bin folder  ok   Verify cache contents  ok  verified 0 tarballs -Global bin folder in PATH  ok  {CWD}/test/lib/commands/tap-testdir-doctor-ping-404/global/bin ` exports[`test/lib/commands/doctor.js TAP ping 404 in color > logs 1`] = ` @@ -1365,6 +1367,10 @@ Object { "getGitPath", "Finding git in your PATH", ], + Array [ + "getBinPath", + "Finding npm global bin in your PATH", + ], Array [ "verifyCachedFiles", "Verifying the npm cache", @@ -1380,10 +1386,6 @@ Object { } ), ], - Array [ - "checkBinPath", - "Finding npm global bin in your PATH", - ], ], "warn": Array [], } @@ -1395,14 +1397,14 @@ exports[`test/lib/commands/doctor.js TAP ping 404 in color > ping 404 in color 1 npm -v  ok  current: v1.0.0, latest: v1.0.0 node -v  ok  current: v1.0.0, recommended: v1.0.0 npm config get registry  ok  using default registry (https://registry.npmjs.org/) -which git  ok  /path/to/git +git executable in PATH  ok  /path/to/git +global bin folder in PATH  ok  {CWD}/test/lib/commands/tap-testdir-doctor-ping-404-in-color/global/bin Perms check on cached files  ok   Perms check on local node_modules  ok   Perms check on global node_modules ok   Perms check on local bin folder  ok   Perms check on global bin folder  ok   Verify cache contents  ok  verified 0 tarballs -Global bin folder in PATH  ok  {CWD}/test/lib/commands/tap-testdir-doctor-ping-404-in-color/global/bin ` exports[`test/lib/commands/doctor.js TAP ping exception with code > logs 1`] = ` @@ -1428,6 +1430,10 @@ Object { "getGitPath", "Finding git in your PATH", ], + Array [ + "getBinPath", + "Finding npm global bin in your PATH", + ], Array [ "verifyCachedFiles", "Verifying the npm cache", @@ -1443,10 +1449,6 @@ Object { } ), ], - Array [ - "checkBinPath", - "Finding npm global bin in your PATH", - ], ], "warn": Array [], } @@ -1458,14 +1460,14 @@ npm ping  not ok request to https npm -v  ok  current: v1.0.0, latest: v1.0.0 node -v  ok  current: v1.0.0, recommended: v1.0.0 npm config get registry  ok  using default registry (https://registry.npmjs.org/) -which git  ok  /path/to/git +git executable in PATH  ok  /path/to/git +global bin folder in PATH  ok  {CWD}/test/lib/commands/tap-testdir-doctor-ping-exception-with-code/global/bin Perms check on cached files  ok   Perms check on local node_modules  ok   Perms check on global node_modules ok   Perms check on local bin folder  ok   Perms check on global bin folder  ok   Verify cache contents  ok  verified 0 tarballs -Global bin folder in PATH  ok  {CWD}/test/lib/commands/tap-testdir-doctor-ping-exception-with-code/global/bin ` exports[`test/lib/commands/doctor.js TAP ping exception without code > logs 1`] = ` @@ -1491,6 +1493,10 @@ Object { "getGitPath", "Finding git in your PATH", ], + Array [ + "getBinPath", + "Finding npm global bin in your PATH", + ], Array [ "verifyCachedFiles", "Verifying the npm cache", @@ -1506,10 +1512,6 @@ Object { } ), ], - Array [ - "checkBinPath", - "Finding npm global bin in your PATH", - ], ], "warn": Array [], } @@ -1521,17 +1523,37 @@ npm ping  not ok request to https npm -v  ok  current: v1.0.0, latest: v1.0.0 node -v  ok  current: v1.0.0, recommended: v1.0.0 npm config get registry  ok  using default registry (https://registry.npmjs.org/) -which git  ok  /path/to/git +git executable in PATH  ok  /path/to/git +global bin folder in PATH  ok  {CWD}/test/lib/commands/tap-testdir-doctor-ping-exception-without-code/global/bin Perms check on cached files  ok   Perms check on local node_modules  ok   Perms check on global node_modules ok   Perms check on local bin folder  ok   Perms check on global bin folder  ok   Verify cache contents  ok  verified 0 tarballs -Global bin folder in PATH  ok  {CWD}/test/lib/commands/tap-testdir-doctor-ping-exception-without-code/global/bin ` -exports[`test/lib/commands/doctor.js TAP silent > logs 1`] = ` +exports[`test/lib/commands/doctor.js TAP silent errors > logs 1`] = ` +Object { + "error": Array [], + "info": Array [ + Array [ + "Running checkup", + ], + Array [ + "checkPing", + "Pinging registry", + ], + ], + "warn": Array [], +} +` + +exports[`test/lib/commands/doctor.js TAP silent errors > output 1`] = ` + +` + +exports[`test/lib/commands/doctor.js TAP silent success > logs 1`] = ` Object { "error": Array [], "info": Array [ @@ -1554,6 +1576,10 @@ Object { "getGitPath", "Finding git in your PATH", ], + Array [ + "getBinPath", + "Finding npm global bin in your PATH", + ], Array [ "verifyCachedFiles", "Verifying the npm cache", @@ -1569,16 +1595,12 @@ Object { } ), ], - Array [ - "checkBinPath", - "Finding npm global bin in your PATH", - ], ], "warn": Array [], } ` -exports[`test/lib/commands/doctor.js TAP silent > output 1`] = ` +exports[`test/lib/commands/doctor.js TAP silent success > output 1`] = ` ` @@ -1606,22 +1628,7 @@ Object { "Finding git in your PATH", ], Array [ - "verifyCachedFiles", - "Verifying the npm cache", - ], - Array [ - "verifyCachedFiles", - String( - Verification complete. Stats: { - "badContentCount": 0, - "reclaimedCount": 0, - "missingContent": 0, - "verifiedContent": 0 - } - ), - ], - Array [ - "checkBinPath", + "getBinPath", "Finding npm global bin in your PATH", ], ], @@ -1635,7 +1642,6 @@ npm ping  ok   npm -v  ok  current: v1.0.0, latest: v1.0.0 node -v  ok  current: v1.0.0, recommended: v1.0.0 npm config get registry  ok  using default registry (https://registry.npmjs.org/) -which git  ok  /path/to/git -Verify cache contents  ok  verified 0 tarballs -Global bin folder in PATH ok  {CWD}/test/lib/commands/tap-testdir-doctor-windows-skips-permissions-checks/global +git executable in PATH  ok  /path/to/git +global bin folder in PATH ok  {CWD}/test/lib/commands/tap-testdir-doctor-windows-skips-permissions-checks/global ` diff --git a/test/lib/commands/doctor.js b/test/lib/commands/doctor.js index 7fb78cf2b5c6e..b0b9c0563c4cf 100644 --- a/test/lib/commands/doctor.js +++ b/test/lib/commands/doctor.js @@ -118,7 +118,7 @@ t.test('all clear in color', async t => { t.matchSnapshot({ info: logs.info, warn: logs.warn, error: logs.error }, 'logs') }) -t.test('silent', async t => { +t.test('silent success', async t => { const { joinedOutput, logs, npm } = await loadMockNpm(t, { mocks, globals, @@ -137,6 +137,24 @@ t.test('silent', async t => { t.matchSnapshot({ info: logs.info, warn: logs.warn, error: logs.error }, 'logs') }) +t.test('silent errors', async t => { + const { joinedOutput, logs, npm } = await loadMockNpm(t, { + mocks, + globals, + config: { + loglevel: 'silent', + }, + ...dirs, + }) + tnock(t, npm.config.get('registry')) + .get('/-/ping?write=true').reply(404, '{}') + await t.rejects(npm.exec('doctor', ['ping']), { + message: /Check logs/ + }) + t.matchSnapshot(joinedOutput(), 'output') + t.matchSnapshot({ info: logs.info, warn: logs.warn, error: logs.error }, 'logs') +}) + t.test('ping 404', async t => { const { joinedOutput, logs, npm } = await loadMockNpm(t, { mocks, @@ -148,7 +166,9 @@ t.test('ping 404', async t => { .get('/npm').reply(200, npmManifest(npm.version)) tnock(t, 'https://nodejs.org') .get('/dist/index.json').reply(200, nodeVersions) - await t.rejects(npm.exec('doctor', [])) + await t.rejects(npm.exec('doctor', []), { + message: /See above/ + }) t.matchSnapshot(joinedOutput(), 'ping 404') t.matchSnapshot({ info: logs.info, warn: logs.warn, error: logs.error }, 'logs') }) @@ -560,6 +580,8 @@ t.test('discrete checks', t => { globals, ...dirs, }) + tnock(t, npm.config.get('registry')) + .get('/-/ping?write=true').reply(200, '{}') await npm.exec('doctor', ['registry']) t.matchSnapshot(joinedOutput(), 'output') t.matchSnapshot({ info: logs.info, warn: logs.warn, error: logs.error }, 'logs')