From 3b9abc656ddd95fffd03f1ed7c4c123aac3a6100 Mon Sep 17 00:00:00 2001 From: Steve Hetzel Date: Tue, 27 Aug 2024 16:48:06 -0600 Subject: [PATCH] fix: no events without proxy env vars --- src/diagnostics.ts | 30 ++++++++++++++++++------------ test/diagnostics.test.ts | 2 +- 2 files changed, 19 insertions(+), 13 deletions(-) diff --git a/src/diagnostics.ts b/src/diagnostics.ts index c882a066..8320b0a5 100644 --- a/src/diagnostics.ts +++ b/src/diagnostics.ts @@ -207,18 +207,24 @@ export class Diagnostics { const httpsProxyEnvVarStatus = getStatus(httpsProxyEnvVars); const noProxyEnvVarStatus = getStatus(noProxyEnvVars); - await Lifecycle.getInstance().emit('Doctor:diagnostic', { - testName: 'http_proxy and HTTP_proxy environment variables match', - status: httpProxyEnvVarStatus, - }); - await Lifecycle.getInstance().emit('Doctor:diagnostic', { - testName: 'https_proxy and HTTPS_PROXY environment variables match', - status: httpsProxyEnvVarStatus, - }); - await Lifecycle.getInstance().emit('Doctor:diagnostic', { - testName: 'no_proxy and NO_PROXY environment variables match', - status: noProxyEnvVarStatus, - }); + if (httpProxyEnvVars.length) { + await Lifecycle.getInstance().emit('Doctor:diagnostic', { + testName: 'http_proxy and HTTP_PROXY environment variables match', + status: httpProxyEnvVarStatus, + }); + } + if (httpsProxyEnvVars.length) { + await Lifecycle.getInstance().emit('Doctor:diagnostic', { + testName: 'https_proxy and HTTPS_PROXY environment variables match', + status: httpsProxyEnvVarStatus, + }); + } + if (noProxyEnvVars.length) { + await Lifecycle.getInstance().emit('Doctor:diagnostic', { + testName: 'no_proxy and NO_PROXY environment variables match', + status: noProxyEnvVarStatus, + }); + } if (httpProxyEnvVarStatus === 'fail') { this.doctor.addSuggestion(messages.getMessage('matchProxyEnvVarSuggestion', ['http_proxy', 'HTTP_PROXY'])); diff --git a/test/diagnostics.test.ts b/test/diagnostics.test.ts index f697ba2f..13d0c9fd 100644 --- a/test/diagnostics.test.ts +++ b/test/diagnostics.test.ts @@ -109,7 +109,7 @@ describe('Diagnostics', () => { const diagnostics = new Diagnostics(dr, oclifConfig); await diagnostics.proxyEnvVarsCheck(); - expect(lifecycleEmitSpy.callCount, 'Expected "Doctor:diagnostic" event fired 3 times').to.equal(3); + expect(lifecycleEmitSpy.callCount, 'Expected no "Doctor:diagnostic" event fired').to.equal(0); expect(drAddSuggestionSpy.called, 'Expected no suggestions to be added').to.be.false; });