From c3242a7127a2721eea60edad29f3ad72261a96e6 Mon Sep 17 00:00:00 2001 From: mshanemc Date: Thu, 28 Sep 2023 12:59:00 -0500 Subject: [PATCH 1/3] fix: stop spinners on caught error --- src/sfCommand.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/sfCommand.ts b/src/sfCommand.ts index 5e28a15d..967fd089 100644 --- a/src/sfCommand.ts +++ b/src/sfCommand.ts @@ -415,6 +415,9 @@ export abstract class SfCommand extends Command { // eslint-disable-next-line @typescript-eslint/require-await protected async catch(error: Error | SfError | SfCommand.Error): Promise { + // stop any spinners to prevent it from unintentionally swallowing output. + // If there is an active spinner, it'll say "Error" instead of "Done" + this.spinner.stop(StandardColors.error('Error')); // transform an unknown error into one that conforms to the interface // @ts-expect-error because exitCode is not on Error From 6f7fdb49de9113396419ffa6298b1d719a01e7f3 Mon Sep 17 00:00:00 2001 From: mshanemc Date: Thu, 28 Sep 2023 14:36:48 -0500 Subject: [PATCH 2/3] test: ut for spinner stopping --- test/unit/sfCommand.test.ts | 48 ++++++++++++++++++++++++++++++++++--- 1 file changed, 45 insertions(+), 3 deletions(-) diff --git a/test/unit/sfCommand.test.ts b/test/unit/sfCommand.test.ts index 77eff995..6fb06fea 100644 --- a/test/unit/sfCommand.test.ts +++ b/test/unit/sfCommand.test.ts @@ -8,11 +8,11 @@ import { Flags } from '@oclif/core'; import { Lifecycle } from '@salesforce/core'; import { TestContext } from '@salesforce/core/lib/testSetup'; import { stubMethod } from '@salesforce/ts-sinon'; -import { expect } from 'chai'; +import { assert, expect } from 'chai'; import { SfError } from '@salesforce/core'; import { Config } from '@oclif/core/lib/interfaces'; -import { SfCommand } from '../../src/sfCommand'; - +import { SfCommand, StandardColors } from '../../src/sfCommand'; +import { stubSfCommandUx, stubSpinner } from '../../src/stubUx'; class TestCommand extends SfCommand { public static readonly flags = { actions: Flags.boolean({ char: 'a', description: 'show actions' }), @@ -49,6 +49,7 @@ class NonJsonCommand extends SfCommand { await this.parse(TestCommand); } } + describe('jsonEnabled', () => { beforeEach(() => { delete process.env.SF_CONTENT_TYPE; @@ -169,3 +170,44 @@ describe('warning messages', () => { .and.to.include('action'); }); }); + +describe('spinner stops on errors', () => { + const $$ = new TestContext(); + + class SpinnerThrow extends SfCommand { + // public static enableJsonFlag = true; + public static flags = { + throw: Flags.boolean(), + }; + public async run(): Promise { + const { flags } = await this.parse(SpinnerThrow); + this.spinner.start('go'); + if (flags.throw) { + throw new Error('boo'); + } + } + } + + it("spinner stops but stop isn't called", async () => { + const spinnerStub = stubSpinner($$.SANDBOX); + stubSfCommandUx($$.SANDBOX); + try { + await SpinnerThrow.run(['--throw']); + throw new Error('should have thrown'); + } catch (e) { + assert(e instanceof Error); + expect(e.message).to.equal('boo'); + expect(spinnerStub.start.callCount).to.equal(1); + expect(spinnerStub.stop.callCount).to.equal(1); + expect(spinnerStub.stop.firstCall.firstArg).to.equal(StandardColors.error('Error')); + } + }); + it('spinner not stopped when no throw', async () => { + const spinnerStub = stubSpinner($$.SANDBOX); + stubSfCommandUx($$.SANDBOX); + await SpinnerThrow.run([]); + + expect(spinnerStub.start.callCount).to.equal(1); + expect(spinnerStub.stop.callCount).to.equal(0); + }); +}); From 737acf0d1f31109b838030688734697f0d62b7db Mon Sep 17 00:00:00 2001 From: svc-cli-bot Date: Mon, 2 Oct 2023 20:47:03 +0000 Subject: [PATCH 3/3] chore(release): 3.1.28 [skip ci] --- CHANGELOG.md | 6 ++++++ package.json | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8b816528..99388e7c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +## [3.1.28](https://github.com/salesforcecli/sf-plugins-core/compare/3.1.27...3.1.28) (2023-10-02) + +### Bug Fixes + +- stop spinners on caught error ([c3242a7](https://github.com/salesforcecli/sf-plugins-core/commit/c3242a7127a2721eea60edad29f3ad72261a96e6)) + ## [3.1.27](https://github.com/salesforcecli/sf-plugins-core/compare/3.1.26...3.1.27) (2023-10-01) ### Bug Fixes diff --git a/package.json b/package.json index 6cd10f81..1336977c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@salesforce/sf-plugins-core", - "version": "3.1.27", + "version": "3.1.28", "description": "Utils for writing Salesforce CLI plugins", "main": "lib/exported", "types": "lib/exported.d.ts",