From dc88b822a551fdde5cd351403b926935d775ca8e Mon Sep 17 00:00:00 2001 From: CristiCanizales Date: Wed, 12 Jul 2023 16:47:06 -0300 Subject: [PATCH 1/9] fix: push-on-save working as expected, diagnostics cleared after successful push --- .../src/commands/forceSourcePush.ts | 9 +++------ .../src/commands/util/sfdxCommandletExecutor.ts | 3 +++ .../src/settings/pushOrDeployOnSave.ts | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/packages/salesforcedx-vscode-core/src/commands/forceSourcePush.ts b/packages/salesforcedx-vscode-core/src/commands/forceSourcePush.ts index 46d2fdbd37..4fd5f1c5f2 100644 --- a/packages/salesforcedx-vscode-core/src/commands/forceSourcePush.ts +++ b/packages/salesforcedx-vscode-core/src/commands/forceSourcePush.ts @@ -50,9 +50,6 @@ export const pushCommand: CommandParams = { export class ForceSourcePushExecutor extends SfdxCommandletExecutor<{}> { private flag: string | undefined; - public errorCollection = vscode.languages.createDiagnosticCollection( - 'push-errors' - ); public constructor( flag?: string, public params: CommandParams = pushCommand @@ -132,7 +129,7 @@ export class ForceSourcePushExecutor extends SfdxCommandletExecutor<{}> { const telemetry = new TelemetryBuilder(); let success = false; try { - this.errorCollection.clear(); + SfdxCommandletExecutor.errorCollection.clear(); if (stdOut) { const pushParser = new ForcePushResultParser(stdOut); const errors = pushParser.getErrors(); @@ -142,7 +139,7 @@ export class ForceSourcePushExecutor extends SfdxCommandletExecutor<{}> { errors, workspacePath, execFilePathOrPaths, - this.errorCollection + SfdxCommandletExecutor.errorCollection ); } else { success = true; @@ -150,7 +147,7 @@ export class ForceSourcePushExecutor extends SfdxCommandletExecutor<{}> { this.outputResult(pushParser); } } catch (e) { - this.errorCollection.clear(); + SfdxCommandletExecutor.errorCollection.clear(); if (e.name !== 'PushParserFail') { e.message = 'Error while creating diagnostics for vscode problem view.'; diff --git a/packages/salesforcedx-vscode-core/src/commands/util/sfdxCommandletExecutor.ts b/packages/salesforcedx-vscode-core/src/commands/util/sfdxCommandletExecutor.ts index bf1f2da3c5..80d490086c 100644 --- a/packages/salesforcedx-vscode-core/src/commands/util/sfdxCommandletExecutor.ts +++ b/packages/salesforcedx-vscode-core/src/commands/util/sfdxCommandletExecutor.ts @@ -29,6 +29,9 @@ import { CommandletExecutor } from './commandletExecutor'; export abstract class SfdxCommandletExecutor implements CommandletExecutor { + public static errorCollection = vscode.languages.createDiagnosticCollection( + 'push-errors' + ); protected showChannelOutput = true; protected executionCwd = workspaceUtils.getRootWorkspacePath(); protected onDidFinishExecutionEventEmitter = new vscode.EventEmitter< diff --git a/packages/salesforcedx-vscode-core/src/settings/pushOrDeployOnSave.ts b/packages/salesforcedx-vscode-core/src/settings/pushOrDeployOnSave.ts index c6f202238a..877c5e0e49 100644 --- a/packages/salesforcedx-vscode-core/src/settings/pushOrDeployOnSave.ts +++ b/packages/salesforcedx-vscode-core/src/settings/pushOrDeployOnSave.ts @@ -115,6 +115,7 @@ export class DeployQueue { : 0 } ); + this.locked = false; } catch (e) { switch (e.name) { case 'NamedOrgNotFound': @@ -128,7 +129,6 @@ export class DeployQueue { default: displayError(e.message); } - this.locked = false; } this.deployWaitStart = undefined; } else if (this.locked && !this.deployWaitStart) { From a19c7ae68551b3151ad143dace6f8da12897da55 Mon Sep 17 00:00:00 2001 From: CristiCanizales Date: Wed, 12 Jul 2023 19:38:12 -0300 Subject: [PATCH 2/9] fix: after successful retrieve all previous errors from failed push are gone --- .../src/commands/baseDeployRetrieve.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/packages/salesforcedx-vscode-core/src/commands/baseDeployRetrieve.ts b/packages/salesforcedx-vscode-core/src/commands/baseDeployRetrieve.ts index a8af04624e..4bc585606c 100644 --- a/packages/salesforcedx-vscode-core/src/commands/baseDeployRetrieve.ts +++ b/packages/salesforcedx-vscode-core/src/commands/baseDeployRetrieve.ts @@ -36,7 +36,11 @@ import { nls } from '../messages'; import { componentSetUtils } from '../services/sdr/componentSetUtils'; import { DeployQueue, sfdxCoreSettings } from '../settings'; import { SfdxPackageDirectories } from '../sfdxProject'; -import { createComponentCount, formatException } from './util'; +import { + createComponentCount, + formatException, + SfdxCommandletExecutor +} from './util'; type DeployRetrieveResult = DeployResult | RetrieveResult; type DeployRetrieveOperation = MetadataApiDeploy | MetadataApiRetrieve; @@ -277,6 +281,7 @@ export abstract class RetrieveExecutor extends DeployRetrieveExecutor { ): Promise { if (result) { DeployRetrieveExecutor.errorCollection.clear(); + SfdxCommandletExecutor.errorCollection.clear(); const relativePackageDirs = await SfdxPackageDirectories.getPackageDirectoryPaths(); const output = this.createOutput(result, relativePackageDirs); channelService.appendLine(output); From aa7fd7048f55bec01e5a1e5dbad492bfad483ff0 Mon Sep 17 00:00:00 2001 From: CristiCanizales Date: Fri, 14 Jul 2023 16:46:15 -0300 Subject: [PATCH 3/9] chore: fix for all the combinations of push/deploy --- .../src/commands/baseDeployRetrieve.ts | 3 ++- .../salesforcedx-vscode-core/src/commands/forceSourcePush.ts | 3 +++ .../salesforcedx-vscode-core/src/diagnostics/diagnostics.ts | 2 ++ 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/packages/salesforcedx-vscode-core/src/commands/baseDeployRetrieve.ts b/packages/salesforcedx-vscode-core/src/commands/baseDeployRetrieve.ts index 4bc585606c..73e5ce85ff 100644 --- a/packages/salesforcedx-vscode-core/src/commands/baseDeployRetrieve.ts +++ b/packages/salesforcedx-vscode-core/src/commands/baseDeployRetrieve.ts @@ -48,7 +48,7 @@ type DeployRetrieveOperation = MetadataApiDeploy | MetadataApiRetrieve; export abstract class DeployRetrieveExecutor< T > extends LibraryCommandletExecutor { - protected static errorCollection = vscode.languages.createDiagnosticCollection( + public static errorCollection = vscode.languages.createDiagnosticCollection( 'deploy-errors' ); protected cancellable: boolean = true; @@ -163,6 +163,7 @@ export abstract class DeployExecutor extends DeployRetrieveExecutor { ); } else { DeployRetrieveExecutor.errorCollection.clear(); + SfdxCommandletExecutor.errorCollection.clear(); } } } finally { diff --git a/packages/salesforcedx-vscode-core/src/commands/forceSourcePush.ts b/packages/salesforcedx-vscode-core/src/commands/forceSourcePush.ts index 4fd5f1c5f2..f0112f1768 100644 --- a/packages/salesforcedx-vscode-core/src/commands/forceSourcePush.ts +++ b/packages/salesforcedx-vscode-core/src/commands/forceSourcePush.ts @@ -25,6 +25,7 @@ import { FORCE_SOURCE_PUSH_LOG_NAME } from '../constants'; import { handleDiagnosticErrors } from '../diagnostics'; import { nls } from '../messages'; import { telemetryService } from '../telemetry'; +import { DeployRetrieveExecutor } from './baseDeployRetrieve'; import { CommandParams, EmptyParametersGatherer, @@ -130,6 +131,7 @@ export class ForceSourcePushExecutor extends SfdxCommandletExecutor<{}> { let success = false; try { SfdxCommandletExecutor.errorCollection.clear(); + DeployRetrieveExecutor.errorCollection.clear(); if (stdOut) { const pushParser = new ForcePushResultParser(stdOut); const errors = pushParser.getErrors(); @@ -148,6 +150,7 @@ export class ForceSourcePushExecutor extends SfdxCommandletExecutor<{}> { } } catch (e) { SfdxCommandletExecutor.errorCollection.clear(); + DeployRetrieveExecutor.errorCollection.clear(); if (e.name !== 'PushParserFail') { e.message = 'Error while creating diagnostics for vscode problem view.'; diff --git a/packages/salesforcedx-vscode-core/src/diagnostics/diagnostics.ts b/packages/salesforcedx-vscode-core/src/diagnostics/diagnostics.ts index 2c6e3c32da..1b4310537d 100644 --- a/packages/salesforcedx-vscode-core/src/diagnostics/diagnostics.ts +++ b/packages/salesforcedx-vscode-core/src/diagnostics/diagnostics.ts @@ -12,6 +12,7 @@ import { } from '@salesforce/source-deploy-retrieve'; import * as path from 'path'; import * as vscode from 'vscode'; +import { SfdxCommandletExecutor } from '../commands/util'; const notApplicable = 'N/A'; @@ -104,6 +105,7 @@ export function handleDeployDiagnostics( errorCollection: vscode.DiagnosticCollection ): vscode.DiagnosticCollection { errorCollection.clear(); + SfdxCommandletExecutor.errorCollection.clear(); const diagnosticMap: Map = new Map(); From c27b7e5526b4cf4f7bde766f8b75b267585b90cf Mon Sep 17 00:00:00 2001 From: CristiCanizales Date: Fri, 14 Jul 2023 17:51:55 -0300 Subject: [PATCH 4/9] test: test in progress for deploy --- .../src/settings/pushOrDeployOnSave.ts | 3 +- .../test/jest/commands/deployExecutor.test.ts | 62 ++++++++++++++++++- 2 files changed, 62 insertions(+), 3 deletions(-) diff --git a/packages/salesforcedx-vscode-core/src/settings/pushOrDeployOnSave.ts b/packages/salesforcedx-vscode-core/src/settings/pushOrDeployOnSave.ts index 877c5e0e49..dbaad8555e 100644 --- a/packages/salesforcedx-vscode-core/src/settings/pushOrDeployOnSave.ts +++ b/packages/salesforcedx-vscode-core/src/settings/pushOrDeployOnSave.ts @@ -115,7 +115,6 @@ export class DeployQueue { : 0 } ); - this.locked = false; } catch (e) { switch (e.name) { case 'NamedOrgNotFound': @@ -129,6 +128,8 @@ export class DeployQueue { default: displayError(e.message); } + } finally { + this.locked = false; } this.deployWaitStart = undefined; } else if (this.locked && !this.deployWaitStart) { diff --git a/packages/salesforcedx-vscode-core/test/jest/commands/deployExecutor.test.ts b/packages/salesforcedx-vscode-core/test/jest/commands/deployExecutor.test.ts index 1d08bbe828..622c4465f1 100644 --- a/packages/salesforcedx-vscode-core/test/jest/commands/deployExecutor.test.ts +++ b/packages/salesforcedx-vscode-core/test/jest/commands/deployExecutor.test.ts @@ -13,7 +13,10 @@ import { ComponentSet } from '@salesforce/source-deploy-retrieve'; import * as fs from 'fs'; import { DeployExecutor } from '../../../src/commands/baseDeployRetrieve'; import { WorkspaceContext } from '../../../src/context/workspaceContext'; -import { sfdxCoreSettings } from '../../../src/settings'; +import { DeployQueue, sfdxCoreSettings } from '../../../src/settings'; +import { PersistentStorageService } from '../../../src/conflict'; +import { SfdxPackageDirectories } from '../../../src/sfdxProject'; +import { channelService } from '../../../src/channels'; jest.mock('@salesforce/source-deploy-retrieve', () => { return { @@ -94,7 +97,8 @@ describe('Deploy Executor', () => { .mockResolvedValue({ pollStatus: jest.fn() } as any); getEnableSourceTrackingForDeployAndRetrieveMock = jest.spyOn( sfdxCoreSettings, - 'getEnableSourceTrackingForDeployAndRetrieve'); + 'getEnableSourceTrackingForDeployAndRetrieve' + ); }); it('should create Source Tracking and call ensureLocalTracking before deploying', async () => { @@ -148,4 +152,58 @@ describe('Deploy Executor', () => { expect(ensureLocalTrackingSpy).not.toHaveBeenCalled(); expect(deploySpy).toHaveBeenCalled(); }); + + it('should clear errors on success', async () => { + const mockDeployResult = { + response: { status: 'Succeeded' } + }; + const setPropertiesForFilesDeployMock = jest.fn(); + const getInstanceSpy = jest + .spyOn(PersistentStorageService, 'getInstance') + .mockReturnValue({ + setPropertiesForFilesDeploy: setPropertiesForFilesDeployMock + } as any); + jest + .spyOn(SfdxPackageDirectories, 'getPackageDirectoryPaths') + .mockResolvedValue('path/to/foo' as any); + jest + .spyOn(TestDeployExecutor.prototype as any, 'createOutput') + .mockReturnValue('path/to/foo' as any); + const appendLineMock = jest + .spyOn(channelService, 'appendLine') + .mockImplementation(jest.fn()); + const executor = new TestDeployExecutor( + 'testDeploy', + 'force_source_deploy_with_sourcepath_beta' + ); + (executor as any).errorCollection = { clear: jest.fn() }; + + // Act + await (executor as any).postOperation(mockDeployResult); + + // Assert + expect(getInstanceSpy).toHaveBeenCalled(); + expect(setPropertiesForFilesDeployMock).toHaveBeenCalledWith( + mockDeployResult + ); + expect(TestDeployExecutor.errorCollection.clear).toHaveBeenCalled(); + }); + + it('should unlock queue on failure', async () => { + // Arrange + const mock = jest.fn(); + const unlock = jest + .spyOn(DeployQueue, 'get') + .mockReturnValue({ unlock: mock } as any); + const executor = new TestDeployExecutor( + 'testDeploy', + 'force_source_deploy_with_sourcepath_beta' + ); + // Act + await (executor as any).postOperation(); + + // Asserts + expect(unlock).toHaveBeenCalled(); + expect(mock).toHaveBeenCalled(); + }); }); From adf5c75e0651408870e4c6ae24e8b8233589cae1 Mon Sep 17 00:00:00 2001 From: CristiCanizales Date: Sun, 16 Jul 2023 07:27:51 -0300 Subject: [PATCH 5/9] test: errorcollection finally mocked :') --- .../test/jest/commands/deployExecutor.test.ts | 50 +++++++++++++---- .../jest/commands/forceSourcePush.test.ts | 24 +++++++- .../commands/baseDeployRetrieve.test.ts | 56 ------------------- 3 files changed, 60 insertions(+), 70 deletions(-) diff --git a/packages/salesforcedx-vscode-core/test/jest/commands/deployExecutor.test.ts b/packages/salesforcedx-vscode-core/test/jest/commands/deployExecutor.test.ts index 622c4465f1..0a7e47f4fb 100644 --- a/packages/salesforcedx-vscode-core/test/jest/commands/deployExecutor.test.ts +++ b/packages/salesforcedx-vscode-core/test/jest/commands/deployExecutor.test.ts @@ -11,12 +11,16 @@ import { } from '@salesforce/salesforcedx-utils-vscode'; import { ComponentSet } from '@salesforce/source-deploy-retrieve'; import * as fs from 'fs'; -import { DeployExecutor } from '../../../src/commands/baseDeployRetrieve'; +import { + DeployExecutor, + DeployRetrieveExecutor +} from '../../../src/commands/baseDeployRetrieve'; import { WorkspaceContext } from '../../../src/context/workspaceContext'; import { DeployQueue, sfdxCoreSettings } from '../../../src/settings'; import { PersistentStorageService } from '../../../src/conflict'; import { SfdxPackageDirectories } from '../../../src/sfdxProject'; import { channelService } from '../../../src/channels'; +import { SfdxCommandletExecutor } from '../../../src/commands/util'; jest.mock('@salesforce/source-deploy-retrieve', () => { return { @@ -77,6 +81,11 @@ describe('Deploy Executor', () => { return new Promise(resolve => resolve(new ComponentSet())); } } + class MockErrorCollection { + static clear(): void { + jest.fn(); + } + } beforeEach(async () => { jest.spyOn(process, 'cwd').mockReturnValue(dummyProcessCwd); @@ -155,7 +164,9 @@ describe('Deploy Executor', () => { it('should clear errors on success', async () => { const mockDeployResult = { - response: { status: 'Succeeded' } + response: { + status: 'Succeeded' + } }; const setPropertiesForFilesDeployMock = jest.fn(); const getInstanceSpy = jest @@ -163,38 +174,53 @@ describe('Deploy Executor', () => { .mockReturnValue({ setPropertiesForFilesDeploy: setPropertiesForFilesDeployMock } as any); - jest + const getPackageDirectoryPathsSpy = jest .spyOn(SfdxPackageDirectories, 'getPackageDirectoryPaths') .mockResolvedValue('path/to/foo' as any); - jest + const createOutputSpy = jest .spyOn(TestDeployExecutor.prototype as any, 'createOutput') .mockReturnValue('path/to/foo' as any); - const appendLineMock = jest + const appendLineSpy = jest .spyOn(channelService, 'appendLine') .mockImplementation(jest.fn()); + + DeployRetrieveExecutor.errorCollection = MockErrorCollection as any; + SfdxCommandletExecutor.errorCollection = MockErrorCollection as any; + const deployRetrieveExecutorClearSpy = jest.spyOn( + DeployRetrieveExecutor.errorCollection, + 'clear' + ); + const sfdxCommandletExecutorClearSpy = jest.spyOn( + SfdxCommandletExecutor.errorCollection, + 'clear' + ); + const executor = new TestDeployExecutor( 'testDeploy', 'force_source_deploy_with_sourcepath_beta' ); - (executor as any).errorCollection = { clear: jest.fn() }; // Act await (executor as any).postOperation(mockDeployResult); // Assert expect(getInstanceSpy).toHaveBeenCalled(); + expect(getPackageDirectoryPathsSpy).toHaveBeenCalled(); + expect(createOutputSpy).toHaveBeenCalled(); + expect(appendLineSpy).toHaveBeenCalled(); expect(setPropertiesForFilesDeployMock).toHaveBeenCalledWith( mockDeployResult ); - expect(TestDeployExecutor.errorCollection.clear).toHaveBeenCalled(); + expect(deployRetrieveExecutorClearSpy).toHaveBeenCalled(); + expect(sfdxCommandletExecutorClearSpy).toHaveBeenCalled(); }); it('should unlock queue on failure', async () => { // Arrange - const mock = jest.fn(); - const unlock = jest + const mockUnlock = jest.fn(); + const unlockSpy = jest .spyOn(DeployQueue, 'get') - .mockReturnValue({ unlock: mock } as any); + .mockReturnValue({ unlock: mockUnlock } as any); const executor = new TestDeployExecutor( 'testDeploy', 'force_source_deploy_with_sourcepath_beta' @@ -203,7 +229,7 @@ describe('Deploy Executor', () => { await (executor as any).postOperation(); // Asserts - expect(unlock).toHaveBeenCalled(); - expect(mock).toHaveBeenCalled(); + expect(unlockSpy).toHaveBeenCalled(); + expect(mockUnlock).toHaveBeenCalled(); }); }); diff --git a/packages/salesforcedx-vscode-core/test/jest/commands/forceSourcePush.test.ts b/packages/salesforcedx-vscode-core/test/jest/commands/forceSourcePush.test.ts index 459c721fc8..bc4a1fc53d 100644 --- a/packages/salesforcedx-vscode-core/test/jest/commands/forceSourcePush.test.ts +++ b/packages/salesforcedx-vscode-core/test/jest/commands/forceSourcePush.test.ts @@ -9,12 +9,21 @@ import { ChannelService } from '@salesforce/salesforcedx-utils-vscode'; import { nls } from '@salesforce/salesforcedx-utils-vscode/src/messages'; import { ForceSourcePushExecutor } from '../../../src/commands'; import { DeployType } from '../../../src/commands/forceSourcePush'; -import { CommandParams } from '../../../src/commands/util'; +import { + CommandParams, + SfdxCommandletExecutor +} from '../../../src/commands/util'; import { PersistentStorageService } from '../../../src/conflict'; import { dummyPushResult, dummyStdOut } from './data/testData'; +import { DeployRetrieveExecutor } from '../../../src/commands/baseDeployRetrieve'; describe('ForceSourcePushExecutor', () => { describe('exitProcessHandlerPush', () => { + class MockErrorCollection { + static clear(): void { + jest.fn(); + } + } beforeEach(() => { jest.spyOn(ChannelService, 'getInstance').mockReturnValue({} as any); jest.spyOn(nls, 'localize').mockReturnValue(''); @@ -38,7 +47,16 @@ describe('ForceSourcePushExecutor', () => { const executor = new ForceSourcePushExecutor(flag, pushCommand); const updateCacheMock = jest.fn(); const executorAsAny = executor as any; - executorAsAny.errorCollection = { clear: jest.fn() }; + SfdxCommandletExecutor.errorCollection = MockErrorCollection as any; + DeployRetrieveExecutor.errorCollection = MockErrorCollection as any; + const deployRetrieveExecutorClearSpy = jest.spyOn( + DeployRetrieveExecutor.errorCollection, + 'clear' + ); + const sfdxCommandletExecutorClearSpy = jest.spyOn( + SfdxCommandletExecutor.errorCollection, + 'clear' + ); executorAsAny.updateCache = updateCacheMock; executorAsAny.getDeployType = jest.fn().mockReturnValue(DeployType.Push); executorAsAny.logMetric = jest.fn(); @@ -56,6 +74,8 @@ describe('ForceSourcePushExecutor', () => { // Assert expect(updateCacheMock).toHaveBeenCalled(); + expect(sfdxCommandletExecutorClearSpy).toHaveBeenCalled(); + expect(deployRetrieveExecutorClearSpy).toHaveBeenCalled(); }); }); diff --git a/packages/salesforcedx-vscode-core/test/vscode-integration/commands/baseDeployRetrieve.test.ts b/packages/salesforcedx-vscode-core/test/vscode-integration/commands/baseDeployRetrieve.test.ts index f97f2734d6..5e93b4db70 100644 --- a/packages/salesforcedx-vscode-core/test/vscode-integration/commands/baseDeployRetrieve.test.ts +++ b/packages/salesforcedx-vscode-core/test/vscode-integration/commands/baseDeployRetrieve.test.ts @@ -569,62 +569,6 @@ describe('Base Deploy Retrieve Commands', () => { expect(appendLineStub.calledOnce).to.equal(true); expect(appendLineStub.firstCall.args[0]).to.equal(expectedOutput); }); - - xit('should report any diagnostics if deploy failed', async () => { - const executor = new TestDeploy(); - - const mockDeployResult = new DeployResult( - { - status: RequestStatus.Failed - } as MetadataApiDeployStatus, - new ComponentSet() - ); - executor.pollStatusStub.resolves(mockDeployResult); - - const failedRows = fileResponses.map(r => ({ - fullName: r.fullName, - type: r.type, - error: 'There was an issue', - state: ComponentStatus.Failed, - filePath: r.filePath, - problemType: 'Error', - lineNumber: 2, - columnNumber: 3 - })); - sb.stub(mockDeployResult, 'getFileResponses').returns(failedRows); - - const setDiagnosticsStub = sb.stub( - (executor as any).errorCollection, - 'set' - ); - - await executor.run({ data: {}, type: 'CONTINUE' }); - - expect(setDiagnosticsStub.callCount).to.equal(failedRows.length); - failedRows.forEach((row, index) => { - const [fileUri, diagnostics] = setDiagnosticsStub.getCall(index).args; - const expectedFileUri = vscode.Uri.file( - getAbsoluteFilePath( - row.filePath, - workspaceUtils.getRootWorkspacePath() - ) - ); - expect(fileUri).to.deep.equal(expectedFileUri); - expect(diagnostics).to.deep.equal([ - { - message: row.error, - range: new vscode.Range( - row.lineNumber - 1, - row.columnNumber - 1, - row.lineNumber - 1, - row.columnNumber - 1 - ), - severity: vscode.DiagnosticSeverity.Error, - source: row.type - } - ]); - }); - }); }); it('should unlock the deploy queue when finished', async () => { From 01a36a24ffb2c8146579540481efcf9e1ade614f Mon Sep 17 00:00:00 2001 From: CristiCanizales Date: Sun, 16 Jul 2023 07:30:54 -0300 Subject: [PATCH 6/9] chore: specified accessibility --- .../test/jest/commands/deployExecutor.test.ts | 2 +- .../test/jest/commands/forceSourcePush.test.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/salesforcedx-vscode-core/test/jest/commands/deployExecutor.test.ts b/packages/salesforcedx-vscode-core/test/jest/commands/deployExecutor.test.ts index 0a7e47f4fb..d17b90ace3 100644 --- a/packages/salesforcedx-vscode-core/test/jest/commands/deployExecutor.test.ts +++ b/packages/salesforcedx-vscode-core/test/jest/commands/deployExecutor.test.ts @@ -82,7 +82,7 @@ describe('Deploy Executor', () => { } } class MockErrorCollection { - static clear(): void { + public static clear(): void { jest.fn(); } } diff --git a/packages/salesforcedx-vscode-core/test/jest/commands/forceSourcePush.test.ts b/packages/salesforcedx-vscode-core/test/jest/commands/forceSourcePush.test.ts index bc4a1fc53d..baa088f520 100644 --- a/packages/salesforcedx-vscode-core/test/jest/commands/forceSourcePush.test.ts +++ b/packages/salesforcedx-vscode-core/test/jest/commands/forceSourcePush.test.ts @@ -20,7 +20,7 @@ import { DeployRetrieveExecutor } from '../../../src/commands/baseDeployRetrieve describe('ForceSourcePushExecutor', () => { describe('exitProcessHandlerPush', () => { class MockErrorCollection { - static clear(): void { + public static clear(): void { jest.fn(); } } From ea169eb1e4378fd2f158047f6183517aac2b18f7 Mon Sep 17 00:00:00 2001 From: CristiCanizales Date: Sun, 16 Jul 2023 07:32:29 -0300 Subject: [PATCH 7/9] chore: sorted imports --- .../test/jest/commands/deployExecutor.test.ts | 6 +++--- .../test/jest/commands/forceSourcePush.test.ts | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/salesforcedx-vscode-core/test/jest/commands/deployExecutor.test.ts b/packages/salesforcedx-vscode-core/test/jest/commands/deployExecutor.test.ts index d17b90ace3..1d3057dfda 100644 --- a/packages/salesforcedx-vscode-core/test/jest/commands/deployExecutor.test.ts +++ b/packages/salesforcedx-vscode-core/test/jest/commands/deployExecutor.test.ts @@ -11,16 +11,16 @@ import { } from '@salesforce/salesforcedx-utils-vscode'; import { ComponentSet } from '@salesforce/source-deploy-retrieve'; import * as fs from 'fs'; +import { channelService } from '../../../src/channels'; import { DeployExecutor, DeployRetrieveExecutor } from '../../../src/commands/baseDeployRetrieve'; +import { SfdxCommandletExecutor } from '../../../src/commands/util'; +import { PersistentStorageService } from '../../../src/conflict'; import { WorkspaceContext } from '../../../src/context/workspaceContext'; import { DeployQueue, sfdxCoreSettings } from '../../../src/settings'; -import { PersistentStorageService } from '../../../src/conflict'; import { SfdxPackageDirectories } from '../../../src/sfdxProject'; -import { channelService } from '../../../src/channels'; -import { SfdxCommandletExecutor } from '../../../src/commands/util'; jest.mock('@salesforce/source-deploy-retrieve', () => { return { diff --git a/packages/salesforcedx-vscode-core/test/jest/commands/forceSourcePush.test.ts b/packages/salesforcedx-vscode-core/test/jest/commands/forceSourcePush.test.ts index baa088f520..7d0d08b236 100644 --- a/packages/salesforcedx-vscode-core/test/jest/commands/forceSourcePush.test.ts +++ b/packages/salesforcedx-vscode-core/test/jest/commands/forceSourcePush.test.ts @@ -8,6 +8,7 @@ import { ChannelService } from '@salesforce/salesforcedx-utils-vscode'; import { nls } from '@salesforce/salesforcedx-utils-vscode/src/messages'; import { ForceSourcePushExecutor } from '../../../src/commands'; +import { DeployRetrieveExecutor } from '../../../src/commands/baseDeployRetrieve'; import { DeployType } from '../../../src/commands/forceSourcePush'; import { CommandParams, @@ -15,7 +16,6 @@ import { } from '../../../src/commands/util'; import { PersistentStorageService } from '../../../src/conflict'; import { dummyPushResult, dummyStdOut } from './data/testData'; -import { DeployRetrieveExecutor } from '../../../src/commands/baseDeployRetrieve'; describe('ForceSourcePushExecutor', () => { describe('exitProcessHandlerPush', () => { From ca0cc8c8a6937616fb286136db5831aaf64e5ff4 Mon Sep 17 00:00:00 2001 From: CristiCanizales Date: Mon, 17 Jul 2023 15:54:55 -0300 Subject: [PATCH 8/9] chore: test --- .../settings/pushOrDeployOnSave.test.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/salesforcedx-vscode-core/test/vscode-integration/settings/pushOrDeployOnSave.test.ts b/packages/salesforcedx-vscode-core/test/vscode-integration/settings/pushOrDeployOnSave.test.ts index 129f77f8d3..9fed337e9a 100644 --- a/packages/salesforcedx-vscode-core/test/vscode-integration/settings/pushOrDeployOnSave.test.ts +++ b/packages/salesforcedx-vscode-core/test/vscode-integration/settings/pushOrDeployOnSave.test.ts @@ -151,14 +151,14 @@ describe('Push or Deploy on Save', () => { // signal to the queue we're done and deploy anything that has been queued while locked await queue.unlock(); - expect(executeCommandStub.calledTwice).to.be.true; - expect(executeCommandStub.getCall(1).args[1]).to.eql(uris); + expect(executeCommandStub.callCount).to.equal(3); + expect(executeCommandStub.getCall(1).args[1]).to.eql([uris[0]]); const telemArgs = telemetryStub.getCall(1).args; expect(telemArgs[0]).to.equal('deployOnSave'); expect(telemArgs[1]).to.deep.equal({ deployType: 'Deploy' }); - expect(telemArgs[2]['documentsToDeploy']).to.equal(2); - expect(telemArgs[2]['waitTimeForLastDeploy'] > 0).to.be.true; + expect(telemArgs[2]['documentsToDeploy']).to.equal(1); + expect(telemArgs[2]['waitTimeForLastDeploy'] > 0).to.be.false; }); it('should display an error to the user when the defaultusername org info cannot be found', async () => { From a73924baa304f14c60c5fc8b588ad8495d0f1be6 Mon Sep 17 00:00:00 2001 From: CristiCanizales Date: Tue, 18 Jul 2023 11:52:21 -0300 Subject: [PATCH 9/9] test: failure case --- .../test/jest/commands/deployExecutor.test.ts | 170 ++++++++++++------ .../commands/baseDeployRetrieve.test.ts | 1 - 2 files changed, 118 insertions(+), 53 deletions(-) diff --git a/packages/salesforcedx-vscode-core/test/jest/commands/deployExecutor.test.ts b/packages/salesforcedx-vscode-core/test/jest/commands/deployExecutor.test.ts index 1d3057dfda..1a9139793c 100644 --- a/packages/salesforcedx-vscode-core/test/jest/commands/deployExecutor.test.ts +++ b/packages/salesforcedx-vscode-core/test/jest/commands/deployExecutor.test.ts @@ -19,6 +19,7 @@ import { import { SfdxCommandletExecutor } from '../../../src/commands/util'; import { PersistentStorageService } from '../../../src/conflict'; import { WorkspaceContext } from '../../../src/context/workspaceContext'; +import * as diagnostics from '../../../src/diagnostics'; import { DeployQueue, sfdxCoreSettings } from '../../../src/settings'; import { SfdxPackageDirectories } from '../../../src/sfdxProject'; @@ -162,74 +163,139 @@ describe('Deploy Executor', () => { expect(deploySpy).toHaveBeenCalled(); }); - it('should clear errors on success', async () => { + it('unsuccessfulOperationHandler', () => { + // Arrange const mockDeployResult = { response: { - status: 'Succeeded' + status: 'Failed' } }; - const setPropertiesForFilesDeployMock = jest.fn(); - const getInstanceSpy = jest - .spyOn(PersistentStorageService, 'getInstance') - .mockReturnValue({ - setPropertiesForFilesDeploy: setPropertiesForFilesDeployMock - } as any); - const getPackageDirectoryPathsSpy = jest - .spyOn(SfdxPackageDirectories, 'getPackageDirectoryPaths') - .mockResolvedValue('path/to/foo' as any); - const createOutputSpy = jest - .spyOn(TestDeployExecutor.prototype as any, 'createOutput') - .mockReturnValue('path/to/foo' as any); - const appendLineSpy = jest - .spyOn(channelService, 'appendLine') + const handleDeployDiagnosticsSpy = jest + .spyOn(diagnostics, 'handleDeployDiagnostics') .mockImplementation(jest.fn()); - DeployRetrieveExecutor.errorCollection = MockErrorCollection as any; - SfdxCommandletExecutor.errorCollection = MockErrorCollection as any; - const deployRetrieveExecutorClearSpy = jest.spyOn( - DeployRetrieveExecutor.errorCollection, - 'clear' - ); - const sfdxCommandletExecutorClearSpy = jest.spyOn( - SfdxCommandletExecutor.errorCollection, - 'clear' - ); - const executor = new TestDeployExecutor( 'testDeploy', 'force_source_deploy_with_sourcepath_beta' ); // Act - await (executor as any).postOperation(mockDeployResult); + (executor as any).unsuccessfulOperationHandler( + mockDeployResult, + DeployRetrieveExecutor.errorCollection + ); - // Assert - expect(getInstanceSpy).toHaveBeenCalled(); - expect(getPackageDirectoryPathsSpy).toHaveBeenCalled(); - expect(createOutputSpy).toHaveBeenCalled(); - expect(appendLineSpy).toHaveBeenCalled(); - expect(setPropertiesForFilesDeployMock).toHaveBeenCalledWith( - mockDeployResult + expect(handleDeployDiagnosticsSpy).toHaveBeenCalledWith( + mockDeployResult, + DeployRetrieveExecutor.errorCollection ); - expect(deployRetrieveExecutorClearSpy).toHaveBeenCalled(); - expect(sfdxCommandletExecutorClearSpy).toHaveBeenCalled(); }); - it('should unlock queue on failure', async () => { - // Arrange - const mockUnlock = jest.fn(); - const unlockSpy = jest - .spyOn(DeployQueue, 'get') - .mockReturnValue({ unlock: mockUnlock } as any); - const executor = new TestDeployExecutor( - 'testDeploy', - 'force_source_deploy_with_sourcepath_beta' - ); - // Act - await (executor as any).postOperation(); + describe('postOperation', () => { + let mockUnlock: any; + let unlockSpy: any; + let setPropertiesForFilesDeployMock: any; + let getInstanceSpy: any; + let getPackageDirectoryPathsSpy: any; + let createOutputSpy: any; + let appendLineSpy: any; + beforeEach(() => { + setPropertiesForFilesDeployMock = jest.fn(); + getInstanceSpy = jest + .spyOn(PersistentStorageService, 'getInstance') + .mockReturnValue({ + setPropertiesForFilesDeploy: setPropertiesForFilesDeployMock + } as any); + getPackageDirectoryPathsSpy = jest + .spyOn(SfdxPackageDirectories, 'getPackageDirectoryPaths') + .mockResolvedValue('path/to/foo' as any); + createOutputSpy = jest + .spyOn(TestDeployExecutor.prototype as any, 'createOutput') + .mockReturnValue('path/to/foo' as any); + appendLineSpy = jest + .spyOn(channelService, 'appendLine') + .mockImplementation(jest.fn()); + mockUnlock = jest.fn(); + unlockSpy = jest + .spyOn(DeployQueue, 'get') + .mockReturnValue({ unlock: mockUnlock } as any); + DeployRetrieveExecutor.errorCollection = MockErrorCollection as any; + }); + + it('should clear errors on success', async () => { + // Arrange + const mockDeployResult = { + response: { + status: 'Succeeded' + } + }; + const deployRetrieveExecutorClearSpy = jest.spyOn( + DeployRetrieveExecutor.errorCollection, + 'clear' + ); + SfdxCommandletExecutor.errorCollection = MockErrorCollection as any; + const sfdxCommandletExecutorClearSpy = jest.spyOn( + SfdxCommandletExecutor.errorCollection, + 'clear' + ); + + const executor = new TestDeployExecutor( + 'testDeploy', + 'force_source_deploy_with_sourcepath_beta' + ); + + // Act + await (executor as any).postOperation(mockDeployResult); + + // Assert + expect(getInstanceSpy).toHaveBeenCalled(); + expect(getPackageDirectoryPathsSpy).toHaveBeenCalled(); + expect(createOutputSpy).toHaveBeenCalled(); + expect(appendLineSpy).toHaveBeenCalled(); + expect(setPropertiesForFilesDeployMock).toHaveBeenCalledWith( + mockDeployResult + ); + expect(deployRetrieveExecutorClearSpy).toHaveBeenCalled(); + expect(sfdxCommandletExecutorClearSpy).toHaveBeenCalled(); + expect(unlockSpy).toHaveBeenCalled(); + expect(mockUnlock).toHaveBeenCalled(); + }); + + it('should create diagnostics on failure', async () => { + // Arrange + const mockDeployResult = { + response: { + status: 'Failed' + } + }; + const unsuccessfulOperationHandlerSpy = jest + .spyOn( + TestDeployExecutor.prototype as any, + 'unsuccessfulOperationHandler' + ) + .mockImplementation(jest.fn()); + const executor = new TestDeployExecutor( + 'testDeploy', + 'force_source_deploy_with_sourcepath_beta' + ); + + // Act + await (executor as any).postOperation(mockDeployResult); - // Asserts - expect(unlockSpy).toHaveBeenCalled(); - expect(mockUnlock).toHaveBeenCalled(); + // Asserts + expect(getInstanceSpy).toHaveBeenCalled(); + expect(getPackageDirectoryPathsSpy).toHaveBeenCalled(); + expect(createOutputSpy).toHaveBeenCalled(); + expect(appendLineSpy).toHaveBeenCalled(); + expect(setPropertiesForFilesDeployMock).toHaveBeenCalledWith( + mockDeployResult + ); + expect(unsuccessfulOperationHandlerSpy).toHaveBeenCalledWith( + mockDeployResult, + DeployRetrieveExecutor.errorCollection + ); + expect(unlockSpy).toHaveBeenCalled(); + expect(mockUnlock).toHaveBeenCalled(); + }); }); }); diff --git a/packages/salesforcedx-vscode-core/test/vscode-integration/commands/baseDeployRetrieve.test.ts b/packages/salesforcedx-vscode-core/test/vscode-integration/commands/baseDeployRetrieve.test.ts index 5e93b4db70..7b3ab2820e 100644 --- a/packages/salesforcedx-vscode-core/test/vscode-integration/commands/baseDeployRetrieve.test.ts +++ b/packages/salesforcedx-vscode-core/test/vscode-integration/commands/baseDeployRetrieve.test.ts @@ -46,7 +46,6 @@ import { } from '../../../src/commands/baseDeployRetrieve'; import { PersistentStorageService } from '../../../src/conflict/persistentStorageService'; import { WorkspaceContext } from '../../../src/context'; -import { getAbsoluteFilePath } from '../../../src/diagnostics'; import { nls } from '../../../src/messages'; import { componentSetUtils } from '../../../src/services/sdr/componentSetUtils'; import { DeployQueue } from '../../../src/settings';