-
Notifications
You must be signed in to change notification settings - Fork 409
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: push-on-save working as expected, diagnostics cleared after successful push #4975
Changes from all commits
dc88b82
a19c7ae
d566ea0
aa7fd70
c27b7e5
adf5c75
01a36a2
ea169eb
7b63161
ca0cc8c
ef629d9
a5ec199
a73924b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,9 +11,17 @@ 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 { 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 { sfdxCoreSettings } from '../../../src/settings'; | ||
import * as diagnostics from '../../../src/diagnostics'; | ||
import { DeployQueue, sfdxCoreSettings } from '../../../src/settings'; | ||
import { SfdxPackageDirectories } from '../../../src/sfdxProject'; | ||
|
||
jest.mock('@salesforce/source-deploy-retrieve', () => { | ||
return { | ||
|
@@ -74,6 +82,11 @@ describe('Deploy Executor', () => { | |
return new Promise(resolve => resolve(new ComponentSet())); | ||
} | ||
} | ||
class MockErrorCollection { | ||
public static clear(): void { | ||
jest.fn(); | ||
} | ||
} | ||
|
||
beforeEach(async () => { | ||
jest.spyOn(process, 'cwd').mockReturnValue(dummyProcessCwd); | ||
|
@@ -94,7 +107,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 +162,140 @@ describe('Deploy Executor', () => { | |
expect(ensureLocalTrackingSpy).not.toHaveBeenCalled(); | ||
expect(deploySpy).toHaveBeenCalled(); | ||
}); | ||
|
||
it('unsuccessfulOperationHandler', () => { | ||
// Arrange | ||
const mockDeployResult = { | ||
response: { | ||
status: 'Failed' | ||
} | ||
}; | ||
const handleDeployDiagnosticsSpy = jest | ||
.spyOn(diagnostics, 'handleDeployDiagnostics') | ||
.mockImplementation(jest.fn()); | ||
DeployRetrieveExecutor.errorCollection = MockErrorCollection as any; | ||
const executor = new TestDeployExecutor( | ||
'testDeploy', | ||
'force_source_deploy_with_sourcepath_beta' | ||
); | ||
|
||
// Act | ||
(executor as any).unsuccessfulOperationHandler( | ||
mockDeployResult, | ||
DeployRetrieveExecutor.errorCollection | ||
); | ||
|
||
expect(handleDeployDiagnosticsSpy).toHaveBeenCalledWith( | ||
mockDeployResult, | ||
DeployRetrieveExecutor.errorCollection | ||
); | ||
}); | ||
|
||
describe('postOperation', () => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Separate describe block for postOperation! Good Work on keeping the separation of concerns in mind! 🎉 |
||
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(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. mockUnlock is returnedValue of unlockSpy. Do we need this expect statement? Also mockUnlock should be a boolean, right? |
||
}); | ||
|
||
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(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(); | ||
}); | ||
}); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
DeployQueue.locked is set to false. What does this mean?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this unlocks the queue in order to let the subsequent pushes on save be triggered