diff --git a/packages/salesforcedx-utils-vscode/src/commands/channelService.ts b/packages/salesforcedx-utils-vscode/src/commands/channelService.ts index 345960f968..c2c8e30c43 100644 --- a/packages/salesforcedx-utils-vscode/src/commands/channelService.ts +++ b/packages/salesforcedx-utils-vscode/src/commands/channelService.ts @@ -9,6 +9,7 @@ import stripAnsi from 'strip-ansi'; import { OutputChannel, window } from 'vscode'; import { CommandExecution } from '../cli'; import { nls } from '../messages'; +import { SfdxSettingsService } from '../settings'; export class ChannelService { private readonly channel: OutputChannel; @@ -37,6 +38,9 @@ export class ChannelService { } public streamCommandStartStop(execution: CommandExecution) { + if (SfdxSettingsService.getEnableClearOutputBeforeEachCommand()) { + this.clear(); + } this.channel.append(nls.localize('channel_starting_message')); this.channel.appendLine(execution.command.toString()); this.channel.appendLine(''); @@ -101,4 +105,8 @@ export class ChannelService { public appendLine(text: string) { this.channel.appendLine(text); } + + public clear() { + this.channel.clear(); + } } diff --git a/packages/salesforcedx-utils-vscode/src/commands/commandletExecutors.ts b/packages/salesforcedx-utils-vscode/src/commands/commandletExecutors.ts index 48b91be46c..d356039d02 100644 --- a/packages/salesforcedx-utils-vscode/src/commands/commandletExecutors.ts +++ b/packages/salesforcedx-utils-vscode/src/commands/commandletExecutors.ts @@ -14,6 +14,7 @@ import { TelemetryService } from '../index'; import { nls } from '../messages'; +import { SfdxSettingsService } from '../settings'; import { CommandletExecutor, ContinueResponse } from '../types'; import { getRootWorkspacePath } from '../workspaces'; import { ChannelService } from './channelService'; @@ -161,6 +162,9 @@ export abstract class LibraryCommandletExecutor const startTime = process.hrtime(); const channelService = new ChannelService(this.outputChannel); const telemetryService = TelemetryService.getInstance(); + if (SfdxSettingsService.getEnableClearOutputBeforeEachCommand()) { + channelService.clear(); + } channelService.showCommandWithTimestamp( `${nls.localize('channel_starting_message')}${this.executionName}\n` diff --git a/packages/salesforcedx-utils-vscode/src/commands/notificationService.ts b/packages/salesforcedx-utils-vscode/src/commands/notificationService.ts index f251b43241..507afe817b 100644 --- a/packages/salesforcedx-utils-vscode/src/commands/notificationService.ts +++ b/packages/salesforcedx-utils-vscode/src/commands/notificationService.ts @@ -7,6 +7,7 @@ import { Observable } from 'rxjs/Observable'; import * as vscode from 'vscode'; import { CommandExecution } from '../cli'; +import { SFDX_CORE_CONFIGURATION_NAME } from '../constants'; import { nls } from '../messages'; import { ChannelService } from './index'; @@ -111,9 +112,8 @@ export class NotificationService { 'notification_successful_execution_text', executionName ); - const showCLISuccessMsg = vscode.workspace - .getConfiguration('salesforcedx-vscode-core') - .get('show-cli-success-msg', true); + const coreConfigurationName = vscode.workspace.getConfiguration(SFDX_CORE_CONFIGURATION_NAME); + const showCLISuccessMsg = coreConfigurationName.get('show-cli-success-msg', true); if (showCLISuccessMsg) { const showButtonText = nls.localize('notification_show_button_text'); const showOnlyStatusBarButtonText = nls.localize( @@ -128,9 +128,7 @@ export class NotificationService { if (selection === showButtonText && channelService) { channelService.showChannelOutput(); } else if (selection === showOnlyStatusBarButtonText) { - await vscode.workspace - .getConfiguration('salesforcedx-vscode-core') - .update('show-cli-success-msg', false); + await coreConfigurationName.update('show-cli-success-msg', false); } } } else { diff --git a/packages/salesforcedx-utils-vscode/src/constants.ts b/packages/salesforcedx-utils-vscode/src/constants.ts new file mode 100644 index 0000000000..df7d2f925f --- /dev/null +++ b/packages/salesforcedx-utils-vscode/src/constants.ts @@ -0,0 +1,3 @@ +export const SETTING_CLEAR_OUTPUT_TAB = 'clearOutputTab'; +export const SFDX_CORE_CONFIGURATION_NAME = 'salesforcedx-vscode-core'; +export const SFDX_CORE_EXTENSION_NAME = 'salesforcedx-vscode-core'; diff --git a/packages/salesforcedx-utils-vscode/src/index.ts b/packages/salesforcedx-utils-vscode/src/index.ts index 22616fff30..8f0e64be13 100644 --- a/packages/salesforcedx-utils-vscode/src/index.ts +++ b/packages/salesforcedx-utils-vscode/src/index.ts @@ -21,6 +21,11 @@ export { } from './commands/commandletExecutors'; export { SfdxCommandlet } from './commands/sfdxCommandlet'; export { ConfigSource, ConfigUtil } from './config/configUtil'; +export { + SETTING_CLEAR_OUTPUT_TAB, + SFDX_CORE_CONFIGURATION_NAME, + SFDX_CORE_EXTENSION_NAME +} from './constants'; export { OrgInfo, WorkspaceContextUtil, getLogDirPath } from './context/workspaceContextUtil'; export { TelemetryService, diff --git a/packages/salesforcedx-utils-vscode/src/settings/index.ts b/packages/salesforcedx-utils-vscode/src/settings/index.ts new file mode 100644 index 0000000000..0156d124bd --- /dev/null +++ b/packages/salesforcedx-utils-vscode/src/settings/index.ts @@ -0,0 +1 @@ +export * from './sfdxSettingsService'; diff --git a/packages/salesforcedx-utils-vscode/src/settings/sfdxSettingsService.ts b/packages/salesforcedx-utils-vscode/src/settings/sfdxSettingsService.ts new file mode 100644 index 0000000000..2cbccdd29c --- /dev/null +++ b/packages/salesforcedx-utils-vscode/src/settings/sfdxSettingsService.ts @@ -0,0 +1,10 @@ +import * as vscode from 'vscode'; +import { SETTING_CLEAR_OUTPUT_TAB, SFDX_CORE_CONFIGURATION_NAME } from '../constants'; + +export class SfdxSettingsService { + public static getEnableClearOutputBeforeEachCommand(): boolean { + return vscode.workspace + .getConfiguration(SFDX_CORE_CONFIGURATION_NAME) + .get(SETTING_CLEAR_OUTPUT_TAB, false); + } +} diff --git a/packages/salesforcedx-utils-vscode/src/telemetry/telemetry.ts b/packages/salesforcedx-utils-vscode/src/telemetry/telemetry.ts index 434b38be9b..717ef5b93b 100644 --- a/packages/salesforcedx-utils-vscode/src/telemetry/telemetry.ts +++ b/packages/salesforcedx-utils-vscode/src/telemetry/telemetry.ts @@ -7,6 +7,7 @@ import * as util from 'util'; import { env, ExtensionContext, workspace } from 'vscode'; +import { SFDX_CORE_CONFIGURATION_NAME } from '../constants'; import { disableCLITelemetry, isCLITelemetryAllowed } from './cliConfiguration'; import { TelemetryReporter } from './telemetryReporter'; @@ -140,7 +141,7 @@ export class TelemetryService { .getConfiguration('telemetry') .get('enableTelemetry', true) && workspace - .getConfiguration('salesforcedx-vscode-core') + .getConfiguration(SFDX_CORE_CONFIGURATION_NAME) .get('telemetry.enabled', true) ); } diff --git a/packages/salesforcedx-utils-vscode/test/unit/commands/channelService.test.ts b/packages/salesforcedx-utils-vscode/test/unit/commands/channelService.test.ts index 0cbef5e9ce..24be633f53 100644 --- a/packages/salesforcedx-utils-vscode/test/unit/commands/channelService.test.ts +++ b/packages/salesforcedx-utils-vscode/test/unit/commands/channelService.test.ts @@ -135,4 +135,27 @@ describe('Channel Service', () => { channelService.streamCommandOutput(execution); expect(ensureDoubleDigitsStub.called).equals(true); }); + + it('should clear channel', async () => { + const clearStub = sb.stub(mChannel, 'clear'); + sb.stub(vscodeStub.window, 'createOutputChannel').returns(mChannel); + // @ts-ignore + channelService.clear(); + expect(clearStub.called).equals(true); + }); + + it('should clear channel when streamCommandStartStop is executed', () => { + const clearStub = sb.stub(mChannel, 'clear'); + sb.stub(vscodeStub.window, 'createOutputChannel').returns(mChannel); + const execution = new CliCommandExecutor( + new SfdxCommandBuilder() + .withArg('force') + .withArg('--help') + .build(), + {} + ).execute(); + // @ts-ignore + channelService.streamCommandStartStop(execution); + expect(clearStub.called).equals(true); + }); }); diff --git a/packages/salesforcedx-utils-vscode/test/unit/commands/commandletExecutor.test.ts b/packages/salesforcedx-utils-vscode/test/unit/commands/commandletExecutor.test.ts index 151359ff50..55b33cf70d 100644 --- a/packages/salesforcedx-utils-vscode/test/unit/commands/commandletExecutor.test.ts +++ b/packages/salesforcedx-utils-vscode/test/unit/commands/commandletExecutor.test.ts @@ -94,6 +94,24 @@ describe('LibraryCommandletExecutor', () => { expect(showInfoStub.called).to.be.true; }); + it('should clear channel output if preference set', async () => { + sb.stub(vscodeStub.workspace, 'getConfiguration').returns({ + get: () => true + }); + const clearStub = sb.stub(MockChannel.prototype, 'clear'); + await executor.execute({ data: { success: false }, type: 'CONTINUE' }); + expect(clearStub.called).to.be.true; + }); + + it('should NOT clear channel output if preference NOT set', async () => { + sb.stub(vscodeStub.workspace, 'getConfiguration').returns({ + get: () => false + }); + const clearStub = sb.stub(MockChannel.prototype, 'clear'); + await executor.execute({ data: { success: false }, type: 'CONTINUE' }); + expect(clearStub.called).not.to.be.true; + }); + it('should show failed execution notification if run returns false', async () => { const showErrStub = sb .stub(vscodeStub.window, 'showErrorMessage') diff --git a/packages/salesforcedx-utils-vscode/test/unit/settings/sfdxSettingsService.test.ts b/packages/salesforcedx-utils-vscode/test/unit/settings/sfdxSettingsService.test.ts new file mode 100644 index 0000000000..f4b6ac1e4d --- /dev/null +++ b/packages/salesforcedx-utils-vscode/test/unit/settings/sfdxSettingsService.test.ts @@ -0,0 +1,35 @@ +import { expect } from 'chai'; +import * as proxyquire from 'proxyquire'; +import { createSandbox, SinonSandbox } from 'sinon'; +import { vscodeStub } from '../commands/mocks'; + +const { SfdxSettingsService } = proxyquire.noCallThru()( + '../../../src/settings/index', + { + vscode: vscodeStub + } +); + +describe('SfdxSettingsService', () => { + let sb: SinonSandbox; + beforeEach(() => { + sb = createSandbox(); + }); + afterEach(() => { + sb.restore(); + }); + describe('when reading workspace preference for clearing output', () => { + it('should return true when underlying workspace configuration for preference', () => { + sb.stub(vscodeStub.workspace, 'getConfiguration').returns({ + get: () => true + }); + expect(SfdxSettingsService.getEnableClearOutputBeforeEachCommand()).equals(true); + }); + it('should return false if underlying configuration is false', () => { + sb.stub(vscodeStub.workspace, 'getConfiguration').returns({ + get: () => false + }); + expect(SfdxSettingsService.getEnableClearOutputBeforeEachCommand()).equals(false); + }); + }); +}); diff --git a/packages/salesforcedx-vscode-apex-replay-debugger/src/utils/settings.ts b/packages/salesforcedx-vscode-apex-replay-debugger/src/utils/settings.ts index 4d667777ec..e9018db78b 100644 --- a/packages/salesforcedx-vscode-apex-replay-debugger/src/utils/settings.ts +++ b/packages/salesforcedx-vscode-apex-replay-debugger/src/utils/settings.ts @@ -5,10 +5,11 @@ * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause */ +import { SFDX_CORE_CONFIGURATION_NAME } from '@salesforce/salesforcedx-utils-vscode/out/src'; import * as vscode from 'vscode'; export function retrieveTestCodeCoverage(): boolean { return vscode.workspace - .getConfiguration('salesforcedx-vscode-core') + .getConfiguration(SFDX_CORE_CONFIGURATION_NAME) .get('retrieve-test-code-coverage', false); } diff --git a/packages/salesforcedx-vscode-apex-replay-debugger/test/vscode-integration/commands/quickLaunch.test.ts b/packages/salesforcedx-vscode-apex-replay-debugger/test/vscode-integration/commands/quickLaunch.test.ts index 5e5217edbf..691ff92c7f 100644 --- a/packages/salesforcedx-vscode-apex-replay-debugger/test/vscode-integration/commands/quickLaunch.test.ts +++ b/packages/salesforcedx-vscode-apex-replay-debugger/test/vscode-integration/commands/quickLaunch.test.ts @@ -50,7 +50,7 @@ describe('Quick launch apex tests', () => { sb = createSandbox(); settingStub = sb.stub(); sb.stub(vscode.workspace, 'getConfiguration') - .withArgs('salesforcedx-vscode-core') + .withArgs(utils.SFDX_CORE_CONFIGURATION_NAME) .returns({ get: settingStub }); diff --git a/packages/salesforcedx-vscode-apex/src/settings.ts b/packages/salesforcedx-vscode-apex/src/settings.ts index 4d667777ec..e9018db78b 100644 --- a/packages/salesforcedx-vscode-apex/src/settings.ts +++ b/packages/salesforcedx-vscode-apex/src/settings.ts @@ -5,10 +5,11 @@ * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause */ +import { SFDX_CORE_CONFIGURATION_NAME } from '@salesforce/salesforcedx-utils-vscode/out/src'; import * as vscode from 'vscode'; export function retrieveTestCodeCoverage(): boolean { return vscode.workspace - .getConfiguration('salesforcedx-vscode-core') + .getConfiguration(SFDX_CORE_CONFIGURATION_NAME) .get('retrieve-test-code-coverage', false); } diff --git a/packages/salesforcedx-vscode-apex/test/vscode-integration/commands/forceApexExecute.test.ts b/packages/salesforcedx-vscode-apex/test/vscode-integration/commands/forceApexExecute.test.ts index 5ef110a0fe..a6b29c44c3 100644 --- a/packages/salesforcedx-vscode-apex/test/vscode-integration/commands/forceApexExecute.test.ts +++ b/packages/salesforcedx-vscode-apex/test/vscode-integration/commands/forceApexExecute.test.ts @@ -7,7 +7,7 @@ import { ExecuteService } from '@salesforce/apex-node'; import { AuthInfo, ConfigAggregator, Connection } from '@salesforce/core'; import { MockTestOrgData, testSetup } from '@salesforce/core/lib/testSetup'; -import { getRootWorkspacePath } from '@salesforce/salesforcedx-utils-vscode/out/src'; +import { getRootWorkspacePath, SFDX_CORE_CONFIGURATION_NAME } from '@salesforce/salesforcedx-utils-vscode/out/src'; import { ChannelService } from '@salesforce/salesforcedx-utils-vscode/out/src/commands'; import { TraceFlags } from '@salesforce/salesforcedx-utils-vscode/out/src/helpers'; import { ContinueResponse } from '@salesforce/salesforcedx-utils-vscode/out/src/types'; @@ -40,7 +40,7 @@ describe('Force Apex Execute', () => { sb = createSandbox(); settingStub = sb.stub(); sb.stub(vscode.workspace, 'getConfiguration') - .withArgs('salesforcedx-vscode-core') + .withArgs(SFDX_CORE_CONFIGURATION_NAME) .returns({ get: settingStub }); diff --git a/packages/salesforcedx-vscode-apex/test/vscode-integration/settings.test.ts b/packages/salesforcedx-vscode-apex/test/vscode-integration/settings.test.ts index bc5d6d6ae6..d5afc0bab2 100644 --- a/packages/salesforcedx-vscode-apex/test/vscode-integration/settings.test.ts +++ b/packages/salesforcedx-vscode-apex/test/vscode-integration/settings.test.ts @@ -4,6 +4,7 @@ * Licensed under the BSD 3-Clause license. * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause */ +import { SFDX_CORE_CONFIGURATION_NAME } from '@salesforce/salesforcedx-utils-vscode/out/src'; import { expect } from 'chai'; import { createSandbox, SinonStub } from 'sinon'; import * as vscode from 'vscode'; @@ -18,7 +19,7 @@ describe('Settings', () => { settingStub = sandbox.stub(); sandbox .stub(vscode.workspace, 'getConfiguration') - .withArgs('salesforcedx-vscode-core') + .withArgs(SFDX_CORE_CONFIGURATION_NAME) .returns({ get: settingStub }); diff --git a/packages/salesforcedx-vscode-core/package.json b/packages/salesforcedx-vscode-core/package.json index 3e1660707e..a247b082aa 100644 --- a/packages/salesforcedx-vscode-core/package.json +++ b/packages/salesforcedx-vscode-core/package.json @@ -954,8 +954,13 @@ ], "configuration": { "type": "object", - "title": "%feature_previews_title%", + "title": "%core_settings_title%", "properties": { + "salesforcedx-vscode-core.clearOutputTab": { + "type": "boolean", + "default": false, + "description": "%setting_clear_output_tab_description%" + }, "salesforcedx-vscode-core.push-or-deploy-on-save.overrideConflictsOnPush": { "type": "boolean", "default": false, diff --git a/packages/salesforcedx-vscode-core/package.nls.ja.json b/packages/salesforcedx-vscode-core/package.nls.ja.json index 9197ef1325..7d0a3fcb74 100644 --- a/packages/salesforcedx-vscode-core/package.nls.ja.json +++ b/packages/salesforcedx-vscode-core/package.nls.ja.json @@ -35,7 +35,7 @@ "force_data_soql_query_input_text": "SFDX: SOQL クエリを実行...", "force_data_soql_query_selection_text": "SFDX: 現在選択されているテキストを使用して SOQL クエリを実行", "force_package_install_text": "SFDX: パッケージをインストール", - "feature_previews_title": "Salesforce 機能のプレビュー", + "core_settings_title": "Salesforce 機能のプレビュー", "force_project_create_text": "SFDX: プロジェクトを作成", "force_project_with_manifest_create_text": "SFDX: マニフェストファイルを使用してプロジェクトを作成", "force_apex_trigger_create_text": "SFDX: Apex トリガを作成", diff --git a/packages/salesforcedx-vscode-core/package.nls.json b/packages/salesforcedx-vscode-core/package.nls.json index 5d824234fd..1250ff6445 100644 --- a/packages/salesforcedx-vscode-core/package.nls.json +++ b/packages/salesforcedx-vscode-core/package.nls.json @@ -41,7 +41,7 @@ "force_data_soql_query_input_text": "SFDX: Execute SOQL Query...", "force_data_soql_query_selection_text": "SFDX: Execute SOQL Query with Currently Selected Text", "force_package_install_text": "SFDX: Install Package", - "feature_previews_title": "Salesforce Feature Previews", + "core_settings_title": "Salesforce Core Configuration", "force_project_create_text": "SFDX: Create Project", "force_project_with_manifest_create_text": "SFDX: Create Project with Manifest", "force_apex_trigger_create_text": "SFDX: Create Apex Trigger", @@ -82,5 +82,6 @@ "force_function_stop": "SFDX: Stop Function", "force_sobjects_refresh": "SFDX: Refresh SObject Definitions", "enable_sobject_refresh_on_startup_description": "If a project has no sObject definitions, specifies whether to automatically refresh sObject definitions on extension activation (true) or not (false).", - "force_launch_apex_replay_debugger_with_current_file": "SFDX: Launch Apex Replay Debugger with Current File" + "force_launch_apex_replay_debugger_with_current_file": "SFDX: Launch Apex Replay Debugger with Current File", + "setting_clear_output_tab_description": "When a new command is run, clear the output content from the previous command." } diff --git a/packages/salesforcedx-vscode-core/src/commands/util/sfdxCommandlet.ts b/packages/salesforcedx-vscode-core/src/commands/util/sfdxCommandlet.ts index 73ed06bb6f..8b0f2a8e47 100644 --- a/packages/salesforcedx-vscode-core/src/commands/util/sfdxCommandlet.ts +++ b/packages/salesforcedx-vscode-core/src/commands/util/sfdxCommandlet.ts @@ -24,6 +24,7 @@ import * as vscode from 'vscode'; import { EmptyPostChecker } from '.'; import { channelService } from '../../channels'; import { notificationService, ProgressNotification } from '../../notifications'; +import { sfdxCoreSettings } from '../../settings'; import { taskViewService } from '../../statuses'; import { telemetryService } from '../../telemetry'; import { getRootWorkspacePath } from '../../util'; @@ -165,6 +166,9 @@ export class SfdxCommandlet { } public async run(): Promise { + if (sfdxCoreSettings.getEnableClearOutputBeforeEachCommand()) { + channelService.clear(); + } if (await this.prechecker.check()) { let inputs = await this.gatherer.gather(); inputs = await this.postchecker.check(inputs); diff --git a/packages/salesforcedx-vscode-core/src/constants.ts b/packages/salesforcedx-vscode-core/src/constants.ts index 8947d83699..e36b78939d 100644 --- a/packages/salesforcedx-vscode-core/src/constants.ts +++ b/packages/salesforcedx-vscode-core/src/constants.ts @@ -32,7 +32,6 @@ export const INTERNAL_DEVELOPMENT_FLAG = 'internal-development'; export const PUSH_OR_DEPLOY_ON_SAVE_ENABLED = 'push-or-deploy-on-save.enabled'; export const PUSH_OR_DEPLOY_ON_SAVE_OVERRIDE_CONFLICTS = 'push-or-deploy-on-save.overrideConflictsOnPush'; export const RETRIEVE_TEST_CODE_COVERAGE = 'retrieve-test-code-coverage'; -export const SFDX_CORE_CONFIGURATION_NAME = 'salesforcedx-vscode-core'; export const SHOW_CLI_SUCCESS_INFO_MSG = 'show-cli-success-msg'; export const TELEMETRY_ENABLED = 'telemetry.enabled'; export const ENABLE_SOBJECT_REFRESH_ON_STARTUP = diff --git a/packages/salesforcedx-vscode-core/src/index.ts b/packages/salesforcedx-vscode-core/src/index.ts index fc7475f344..d7788e2282 100644 --- a/packages/salesforcedx-vscode-core/src/index.ts +++ b/packages/salesforcedx-vscode-core/src/index.ts @@ -4,6 +4,7 @@ * Licensed under the BSD 3-Clause license. * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause */ +import { SFDX_CORE_CONFIGURATION_NAME } from '@salesforce/salesforcedx-utils-vscode/out/src'; import * as vscode from 'vscode'; import { channelService } from './channels'; import { @@ -91,8 +92,7 @@ import { setupConflictView } from './conflict'; import { - ENABLE_SOBJECT_REFRESH_ON_STARTUP, - SFDX_CORE_CONFIGURATION_NAME + ENABLE_SOBJECT_REFRESH_ON_STARTUP } from './constants'; import { getDefaultUsernameOrAlias } from './context'; import { workspaceContext } from './context'; diff --git a/packages/salesforcedx-vscode-core/src/settings/sfdxCoreSettings.ts b/packages/salesforcedx-vscode-core/src/settings/sfdxCoreSettings.ts index bbe5ba649a..097cf9f835 100644 --- a/packages/salesforcedx-vscode-core/src/settings/sfdxCoreSettings.ts +++ b/packages/salesforcedx-vscode-core/src/settings/sfdxCoreSettings.ts @@ -5,15 +5,14 @@ * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause */ +import { SETTING_CLEAR_OUTPUT_TAB, SFDX_CORE_CONFIGURATION_NAME } from '@salesforce/salesforcedx-utils-vscode/out/src'; import * as vscode from 'vscode'; import { - BETA_DEPLOY_RETRIEVE, CONFLICT_DETECTION_ENABLED, INTERNAL_DEVELOPMENT_FLAG, PUSH_OR_DEPLOY_ON_SAVE_ENABLED, PUSH_OR_DEPLOY_ON_SAVE_OVERRIDE_CONFLICTS, RETRIEVE_TEST_CODE_COVERAGE, - SFDX_CORE_CONFIGURATION_NAME, SHOW_CLI_SUCCESS_INFO_MSG, TELEMETRY_ENABLED } from '../constants'; @@ -75,6 +74,10 @@ export class SfdxCoreSettings { return this.getConfigValue(CONFLICT_DETECTION_ENABLED, false); } + public getEnableClearOutputBeforeEachCommand(): boolean { + return this.getConfigValue(SETTING_CLEAR_OUTPUT_TAB, false); + } + private getConfigValue(key: string, defaultValue: T): T { return this.getConfiguration().get(key, defaultValue); } diff --git a/packages/salesforcedx-vscode-core/test/vscode-integration/commands/util/sfdxCommandlet.test.ts b/packages/salesforcedx-vscode-core/test/vscode-integration/commands/util/sfdxCommandlet.test.ts index 73db2cef1b..6cdee7360c 100644 --- a/packages/salesforcedx-vscode-core/test/vscode-integration/commands/util/sfdxCommandlet.test.ts +++ b/packages/salesforcedx-vscode-core/test/vscode-integration/commands/util/sfdxCommandlet.test.ts @@ -10,13 +10,22 @@ import { ParametersGatherer } from '@salesforce/salesforcedx-utils-vscode/out/src/types'; import { expect } from 'chai'; +import { createSandbox, SinonSandbox } from 'sinon'; +import { channelService } from '../../../../src/channels'; import { CommandletExecutor, SfdxCommandlet } from '../../../../src/commands/util'; +import { sfdxCoreSettings } from '../../../../src/settings'; -// tslint:disable:no-unused-expression describe('SfdxCommandlet', () => { + let sandbox: SinonSandbox; + beforeEach(() => { + sandbox = createSandbox(); + }); + afterEach(() => { + sandbox.restore(); + }); it('Should not proceed if checker fails', async () => { const commandlet = new SfdxCommandlet( new class { @@ -83,6 +92,65 @@ describe('SfdxCommandlet', () => { await commandlet.run(); + // tslint:disable-next-line:no-unused-expression expect(executed).to.be.true; }); + + it('Should clear channel if user preference is set to true', async () => { + sandbox + .stub( + sfdxCoreSettings, + 'getEnableClearOutputBeforeEachCommand' + ) + .returns(false); + const clearStub = sandbox.stub(channelService, 'clear'); + const commandlet = new SfdxCommandlet( + new class { + public check(): boolean { + return true; + } + }(), + new class implements ParametersGatherer<{}> { + public async gather(): Promise> { + return { type: 'CONTINUE', data: {} }; + } + }(), + new class implements CommandletExecutor<{}> { + public execute(response: ContinueResponse<{}>): void { + } + }() + ); + await commandlet.run(); + // tslint:disable-next-line:no-unused-expression + expect(clearStub.called).to.be.false; + }); + + it('Should not clear channel if user preference is set to false', async () => { + sandbox + .stub( + sfdxCoreSettings, + 'getEnableClearOutputBeforeEachCommand' + ) + .returns(false); + const clearStub = sandbox.stub(channelService, 'clear'); + const commandlet = new SfdxCommandlet( + new class { + public check(): boolean { + return true; + } + }(), + new class implements ParametersGatherer<{}> { + public async gather(): Promise> { + return { type: 'CONTINUE', data: {} }; + } + }(), + new class implements CommandletExecutor<{}> { + public execute(response: ContinueResponse<{}>): void { + } + }() + ); + await commandlet.run(); + // tslint:disable-next-line:no-unused-expression + expect(clearStub.called).to.be.false; + }); }); diff --git a/packages/salesforcedx-vscode-core/test/vscode-integration/telemetry/index.test.ts b/packages/salesforcedx-vscode-core/test/vscode-integration/telemetry/index.test.ts index 456170867a..af906962e7 100644 --- a/packages/salesforcedx-vscode-core/test/vscode-integration/telemetry/index.test.ts +++ b/packages/salesforcedx-vscode-core/test/vscode-integration/telemetry/index.test.ts @@ -4,7 +4,7 @@ * Licensed under the BSD 3-Clause license. * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause */ -import { TelemetryReporter } from '@salesforce/salesforcedx-utils-vscode/out/src'; +import { SFDX_CORE_EXTENSION_NAME, TelemetryReporter } from '@salesforce/salesforcedx-utils-vscode/out/src'; import { expect } from 'chai'; import { assert, match, SinonStub, stub } from 'sinon'; import { window } from 'vscode'; @@ -234,7 +234,7 @@ describe('Telemetry', () => { assert.calledOnce(reporter); const expectedProps = { - extensionName: 'salesforcedx-vscode-core' + extensionName: SFDX_CORE_EXTENSION_NAME }; const expectedMeasures = match({ startupTime: match.number }); assert.calledWith( @@ -261,7 +261,7 @@ describe('Telemetry', () => { assert.calledOnce(reporter); const expectedData = { - extensionName: 'salesforcedx-vscode-core' + extensionName: SFDX_CORE_EXTENSION_NAME }; assert.calledWith(reporter, 'deactivationEvent', expectedData); expect(teleStub.firstCall.args).to.eql([true]); @@ -282,7 +282,7 @@ describe('Telemetry', () => { assert.calledOnce(reporter); const expectedProps = { - extensionName: 'salesforcedx-vscode-core', + extensionName: SFDX_CORE_EXTENSION_NAME, commandName: 'create_apex_class_command' }; const expectedMeasures = { executionTime: match.number }; @@ -318,7 +318,7 @@ describe('Telemetry', () => { assert.calledOnce(reporter); const expectedProps = { - extensionName: 'salesforcedx-vscode-core', + extensionName: SFDX_CORE_EXTENSION_NAME, commandName: 'create_apex_class_command', dirType: 'testDirectoryType', secondParam: 'value' @@ -357,7 +357,7 @@ describe('Telemetry', () => { assert.calledOnce(reporter); const expectedProps = { - extensionName: 'salesforcedx-vscode-core', + extensionName: SFDX_CORE_EXTENSION_NAME, commandName: 'create_apex_class_command' }; const expectedMeasures = {