-
Notifications
You must be signed in to change notification settings - Fork 407
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: add eventEmitter on libraryCommand #5768
Open
angelamuliu
wants to merge
5
commits into
forcedotcom:develop
Choose a base branch
from
angelamuliu:eventEmitter
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
18e5eb8
chore: add eventEmitter on libraryCommand
angelamuliu 65f452c
chore: unit tests for eventEmitter on libraryCommand
angelamuliu 62ab788
Merge branch 'develop' into eventEmitter
angelamuliu 3ab034f
Update commandletExecutors.test.ts
peternhale 7e126f5
Merge branch 'develop' into eventEmitter
mingxuanzhangsfdx File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
61 changes: 61 additions & 0 deletions
61
packages/salesforcedx-utils-vscode/test/jest/commands/commandletExecutors.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,61 @@ | ||
/* | ||
* Copyright (c) 2021, salesforce.com, inc. | ||
* All rights reserved. | ||
* 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 { Progress, CancellationToken } from 'vscode'; | ||
import * as vscode from 'vscode'; | ||
import { ContinueResponse, LibraryCommandletExecutor } from '../../../src'; | ||
import { ChannelService } from '../../../src/commands/channelService'; | ||
import { SettingsService } from '../../../src/settings'; | ||
|
||
class SimpleTestLibraryCommandletExecutor<T> extends LibraryCommandletExecutor<T> { | ||
public run( | ||
response: ContinueResponse<T>, | ||
progress?: Progress<{ message?: string | undefined; increment?: number | undefined }>, | ||
token?: CancellationToken): Promise<boolean> { | ||
return new Promise(resolve => { | ||
resolve(true); | ||
}); | ||
} | ||
} | ||
|
||
jest.mock('../../../src/commands/channelService'); | ||
|
||
describe('LibraryCommandletExecutor', () => { | ||
|
||
it('should fire the onLibraryCommandCompletion event once the library command is done', async () => { | ||
const fireSpy = jest.spyOn( | ||
LibraryCommandletExecutor.libraryCommandCompletionEventEmitter, | ||
'fire' | ||
); | ||
const channel = vscode.window.createOutputChannel('simpleExecutorChannel'); | ||
const executor = new SimpleTestLibraryCommandletExecutor('simpleExecutor', 'logName', channel); | ||
|
||
await executor.execute({} as ContinueResponse<{}>); | ||
|
||
expect(fireSpy).toHaveBeenCalledWith(false); | ||
}); | ||
|
||
it('should not fire onLibraryCommandCompletion event if an error is thrown before try catch block', async () => { | ||
const fireSpy = jest.spyOn( | ||
LibraryCommandletExecutor.libraryCommandCompletionEventEmitter, | ||
'fire' | ||
); | ||
try { | ||
jest | ||
.spyOn(SettingsService, 'getEnableClearOutputBeforeEachCommand') | ||
.mockImplementation(() => { | ||
throw new Error(); | ||
}); | ||
const channel = vscode.window.createOutputChannel('simpleExecutorChannel'); | ||
const executor = new SimpleTestLibraryCommandletExecutor('simpleExecutor', 'logName', channel); | ||
|
||
await executor.execute({} as ContinueResponse<{}>); | ||
} catch(e) { | ||
expect(fireSpy).not.toHaveBeenCalled(); | ||
} | ||
}); | ||
}); |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Not sure if it is meaningful. LibraryCommandletExecutor is an abstract class to be extended by other real executors such as
orgLogoutDefault
ororgLoginAccessToken
. How does the subscriber know the result from which command it is listening to with only a boolean value? Can you help me understand that? @angelamuliu @peternhaleThere 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.
Great catch @mingxuanzhangsfdx, there is no way to know. If two commands are run concurrently and are listening for the completion event, knowing which event belongs any given listener is indeterminant.