-
Notifications
You must be signed in to change notification settings - Fork 405
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Mingxuanzhang/248 synchronize init tasks (#5163)
* feat: add an option for waiting init jobs * fix: suspend setting * feat: add unit test for the new vscode setting * fix: release 246 apex language server (#5152) @W-13804822@ Update apex language server jar for 246 There should not be any functional changes since kast version if v58.* * fix: disable dependabot major version prs (#5144) * fix: upgrade language client to version 9 (#5127) * fix: upgrade apex to use latest language modules @W-14169322@ * chore: remove unneeded dependencies * chore: apply review suggestions * feat: add request for checking indexer status * feat: refactor constants & tests * fix: ts lint * fix: delete unnecessary indexer status check * fix: remove unnecessary fields * fix: logic after client is running and refactor where configuration is defined * feat: refactor indexerDoneHandler & implement unit test * fix: promise error * fix: revert apex-jorje-lsp jar * feat: refactor index file of apex language client * chore: some unit testing cleanup * chore: more lint * chore: sentence and test cleanup * chore: sentence update * chore: test cleanup * chore: remove setting from package.json * chore: unit test for settings.ts and extensionUtils.ts --------- Co-authored-by: peternhale <[email protected]> Co-authored-by: Cristina Cañizales <[email protected]> Co-authored-by: gbockus-sf <[email protected]> Co-authored-by: Gordon Bockus <[email protected]>
- Loading branch information
1 parent
177f3da
commit 28b3e38
Showing
10 changed files
with
343 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
packages/salesforcedx-vscode-apex/src/languageUtils/extensionUtils.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { ApexLanguageClient } from '../apexLanguageClient'; | ||
import ApexLSPStatusBarItem from '../apexLspStatusBarItem'; | ||
import { getTestOutlineProvider } from '../views/testOutlineProvider'; | ||
import { | ||
ClientStatus, | ||
languageClientUtils | ||
} from './index'; | ||
|
||
const setClientReady = async (languageClient: ApexLanguageClient, languageServerStatusBarItem: ApexLSPStatusBarItem) => { | ||
await getTestOutlineProvider().refresh(); | ||
languageServerStatusBarItem.ready(); | ||
languageClientUtils.setStatus(ClientStatus.Ready, ''); | ||
languageClient?.errorHandler?.serviceHasStartedSuccessfully(); | ||
}; | ||
|
||
export const extensionUtils = { | ||
setClientReady | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import { API } from '../../src/constants'; | ||
import * as index from '../../src/index'; | ||
import { languageClientUtils } from '../../src/languageUtils'; | ||
import { extensionUtils } from '../../src/languageUtils/extensionUtils'; | ||
import ApexLSPStatusBarItem from './../../src/apexLspStatusBarItem'; | ||
|
||
jest.mock('./../../src/apexLspStatusBarItem'); | ||
describe('indexDoneHandler', () => { | ||
let setStatusSpy: jest.SpyInstance; | ||
let onNotificationSpy: jest.SpyInstance; | ||
let mockLanguageClient: any; | ||
let setClientReadySpy: jest.SpyInstance; | ||
const apexLSPStatusBarItemMock = jest.mocked(ApexLSPStatusBarItem); | ||
|
||
beforeEach(() => { | ||
setStatusSpy = jest | ||
.spyOn(languageClientUtils, 'setStatus') | ||
.mockReturnValue(); | ||
mockLanguageClient = { | ||
onNotification: jest.fn() | ||
}; | ||
onNotificationSpy = jest.spyOn(mockLanguageClient, 'onNotification'); | ||
setClientReadySpy = jest | ||
.spyOn(extensionUtils, 'setClientReady') | ||
.mockResolvedValue(); | ||
}); | ||
|
||
it('should call languageClientUtils.setStatus and set up event listener when enableSyncInitJobs is false', async () => { | ||
const languageServerStatusBarItem = new ApexLSPStatusBarItem(); | ||
await index.indexerDoneHandler( | ||
false, | ||
mockLanguageClient as any, | ||
languageServerStatusBarItem | ||
); | ||
expect(setStatusSpy).toHaveBeenCalledWith(1, ''); | ||
expect(onNotificationSpy).toHaveBeenCalledWith( | ||
API.doneIndexing, | ||
expect.any(Function) | ||
); | ||
expect(apexLSPStatusBarItemMock).toHaveBeenCalledTimes(1); | ||
|
||
const mockCallback = onNotificationSpy.mock.calls[0][1]; | ||
|
||
await mockCallback(); | ||
expect(setClientReadySpy).toHaveBeenCalledWith( | ||
mockLanguageClient, | ||
languageServerStatusBarItem | ||
); | ||
}); | ||
|
||
it('should call setClientReady when enableSyncInitJobs is true', async () => { | ||
const languageServerStatusBarItem = new ApexLSPStatusBarItem(); | ||
await index.indexerDoneHandler( | ||
true, | ||
mockLanguageClient as any, | ||
languageServerStatusBarItem | ||
); | ||
expect(setClientReadySpy).toHaveBeenCalledWith( | ||
mockLanguageClient, | ||
languageServerStatusBarItem | ||
); | ||
expect(apexLSPStatusBarItemMock).toHaveBeenCalledTimes(1); | ||
}); | ||
}); |
57 changes: 57 additions & 0 deletions
57
packages/salesforcedx-vscode-apex/test/jest/languageUtils/extensionUtils.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import ApexLSPStatusBarItem from '../../../src/apexLspStatusBarItem'; | ||
import { ClientStatus, languageClientUtils } from '../../../src/languageUtils'; | ||
import { extensionUtils } from '../../../src/languageUtils'; | ||
import * as testOutlineProvider from '../../../src/views/testOutlineProvider'; | ||
|
||
jest.mock('../../../src/apexLspStatusBarItem'); | ||
describe('extensionUtils Unit Tests.', () => { | ||
const apexLspStatusBarItemMock = jest.mocked(ApexLSPStatusBarItem); | ||
let refreshSpy: jest.SpyInstance; | ||
let readySpy: jest.SpyInstance; | ||
let setStatusSpy: jest.SpyInstance; | ||
let serviceHasStartedSuccessfullySpy: jest.SpyInstance; | ||
let languageServerStatusBarItem: ApexLSPStatusBarItem; | ||
let getTestOutlineProviderSpy: jest.SpyInstance; | ||
let mockTestOutlineProviderInst; | ||
let mockLanguageClient: any; | ||
|
||
beforeEach(() => { | ||
mockTestOutlineProviderInst = { | ||
refresh: jest.fn(() => Promise.resolve()) | ||
}; | ||
getTestOutlineProviderSpy = jest | ||
.spyOn(testOutlineProvider, 'getTestOutlineProvider') | ||
.mockReturnValue(mockTestOutlineProviderInst as any); | ||
|
||
languageServerStatusBarItem = new ApexLSPStatusBarItem(); | ||
refreshSpy = jest | ||
.spyOn(mockTestOutlineProviderInst, 'refresh') | ||
.mockResolvedValue(); | ||
readySpy = jest.spyOn(languageServerStatusBarItem, 'ready'); | ||
setStatusSpy = jest | ||
.spyOn(languageClientUtils, 'setStatus') | ||
.mockReturnValue(); | ||
mockLanguageClient = { | ||
errorHandler: { | ||
serviceHasStartedSuccessfully: jest.fn() | ||
} | ||
}; | ||
serviceHasStartedSuccessfullySpy = jest.spyOn( | ||
mockLanguageClient.errorHandler, | ||
'serviceHasStartedSuccessfully' | ||
); | ||
}); | ||
|
||
it('should be executed as expected', async () => { | ||
await extensionUtils.setClientReady( | ||
mockLanguageClient, | ||
languageServerStatusBarItem | ||
); | ||
expect(getTestOutlineProviderSpy).toHaveBeenCalled(); | ||
expect(refreshSpy).toHaveBeenCalled(); | ||
expect(readySpy).toHaveBeenCalled(); | ||
expect(setStatusSpy).toHaveBeenCalledWith(ClientStatus.Ready, ''); | ||
expect(serviceHasStartedSuccessfullySpy).toHaveBeenCalled(); | ||
expect(apexLspStatusBarItemMock).toHaveBeenCalledTimes(1); | ||
}); | ||
}); |
48 changes: 48 additions & 0 deletions
48
packages/salesforcedx-vscode-apex/test/jest/settings.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { SFDX_CORE_CONFIGURATION_NAME } from '@salesforce/salesforcedx-utils-vscode'; | ||
import * as vscode from 'vscode'; | ||
import { | ||
retrieveEnableSyncInitJobs, | ||
retrieveTestCodeCoverage | ||
} from '../../src/settings'; | ||
|
||
describe('settings Unit Tests.', () => { | ||
const vscodeMocked = jest.mocked(vscode); | ||
let getConfigurationMock: jest.SpyInstance; | ||
let getFn: jest.Mock; | ||
|
||
beforeEach(() => { | ||
getConfigurationMock = jest.spyOn( | ||
vscodeMocked.workspace, | ||
'getConfiguration' | ||
); | ||
getFn = jest.fn(); | ||
}); | ||
|
||
it('Should be able to get retrieveTestCodeCoverage setting.', () => { | ||
getConfigurationMock.mockReturnValue({ | ||
get: getFn.mockReturnValue(false) | ||
} as any); | ||
|
||
const result = retrieveTestCodeCoverage(); | ||
|
||
expect(result).toBe(false); | ||
expect(getConfigurationMock).toHaveBeenCalledWith( | ||
SFDX_CORE_CONFIGURATION_NAME | ||
); | ||
expect(getFn).toHaveBeenCalledWith('retrieve-test-code-coverage', false); | ||
}); | ||
|
||
it('Should be able to get retrieveEnableSyncInitJobs setting.', () => { | ||
getConfigurationMock.mockReturnValue({ | ||
get: getFn.mockReturnValue(true) | ||
} as any); | ||
|
||
const result = retrieveEnableSyncInitJobs(); | ||
expect(result).toBe(true); | ||
expect(getConfigurationMock).toHaveBeenCalledWith(); | ||
expect(getFn).toHaveBeenCalledWith( | ||
'salesforcedx-vscode-apex.wait-init-jobs', | ||
true | ||
); | ||
}); | ||
}); |
Oops, something went wrong.