From 1c182e11d524294d85348a3c2566f266bd281c00 Mon Sep 17 00:00:00 2001 From: Gar Date: Thu, 3 Mar 2022 10:03:09 -0800 Subject: [PATCH] fix(doctor): don't retry ping --- lib/commands/doctor.js | 2 +- .../test/lib/commands/doctor.js.test.cjs | 58 +++++++++++++++++++ test/lib/commands/doctor.js | 14 +++++ 3 files changed, 73 insertions(+), 1 deletion(-) diff --git a/lib/commands/doctor.js b/lib/commands/doctor.js index 14fda024b9069..552fe5d517341 100644 --- a/lib/commands/doctor.js +++ b/lib/commands/doctor.js @@ -142,7 +142,7 @@ class Doctor extends BaseCommand { const tracker = log.newItem('checkPing', 1) tracker.info('checkPing', 'Pinging registry') try { - await ping(this.npm.flatOptions) + await ping({ ...this.npm.flatOptions, retry: false }) return '' } catch (er) { if (/^E\d{3}$/.test(er.code || '')) { diff --git a/tap-snapshots/test/lib/commands/doctor.js.test.cjs b/tap-snapshots/test/lib/commands/doctor.js.test.cjs index 89599185d5dce..057b6f2e46c2b 100644 --- a/tap-snapshots/test/lib/commands/doctor.js.test.cjs +++ b/tap-snapshots/test/lib/commands/doctor.js.test.cjs @@ -121,6 +121,64 @@ Object { } ` +exports[`test/lib/commands/doctor.js TAP bad proxy > logs 1`] = ` +Object { + "error": Array [], + "info": Array [ + Array [ + "Running checkup", + ], + Array [ + "checkPing", + "Pinging registry", + ], + Array [ + "getLatestNpmVersion", + "Getting npm package information", + ], + Array [ + "getLatestNodejsVersion", + "Getting Node.js release information", + ], + Array [ + "getGitPath", + "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 + } + ), + ], + ], + "warn": Array [], +} +` + +exports[`test/lib/commands/doctor.js TAP bad proxy > output 1`] = ` +Check Value Recommendation/Notes +npm ping not ok unsupported proxy protocol: 'ssh:' +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 +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 +` + exports[`test/lib/commands/doctor.js TAP cacache badContent > corrupted cache content 1`] = ` Check Value Recommendation/Notes npm ping ok diff --git a/test/lib/commands/doctor.js b/test/lib/commands/doctor.js index 25c3bea0d3ce2..9445db8a6fa05 100644 --- a/test/lib/commands/doctor.js +++ b/test/lib/commands/doctor.js @@ -461,3 +461,17 @@ t.test('cacache missingContent', async t => { t.matchSnapshot(joinedOutput(), 'missing content') t.matchSnapshot({ info: logs.info, warn: logs.warn, error: logs.error }, 'logs') }) + +t.test('bad proxy', async t => { + const { joinedOutput, logs, npm } = await loadMockNpm(t, { + mocks, + config: { + proxy: 'ssh://npmjs.org' + }, + ...dirs, + }) + await t.rejects(npm.exec('doctor', [])) + t.matchSnapshot(joinedOutput(), 'output') + t.matchSnapshot({ info: logs.info, warn: logs.warn, error: logs.error }, 'logs') +}) +