Move the invocation rate limiter class out of helpers.ts#2464
Merged
robertbrignull merged 5 commits intomainfrom May 31, 2023
Merged
Move the invocation rate limiter class out of helpers.ts#2464robertbrignull merged 5 commits intomainfrom
robertbrignull merged 5 commits intomainfrom
Conversation
robertbrignull
commented
May 31, 2023
| { customCodeQlPath: pathToCmd } as any, | ||
| {} as any, | ||
| undefined as any, | ||
| {} as any, |
Contributor
Author
There was a problem hiding this comment.
I'm not hugely happy that we're doing as any in the tests, but I don't think the change in this PR makes it any worse than it was already.
koesie10
approved these changes
May 31, 2023
Comment on lines
+57
to
+61
| class MockGlobalStorage extends MockMemento { | ||
| public setKeysForSync(_keys: string[]): void { | ||
| return; | ||
| } | ||
| } |
Member
There was a problem hiding this comment.
I see that this is from the previous testing implementation, but do we need this? It seems like just having MockMemento is enough.
Contributor
Author
There was a problem hiding this comment.
Ah, I see why we had this. It's because the real type defined on the ExtensionContext is
readonly globalState: Memento & {
/**
* Set the keys whose values should be synchronized across devices when synchronizing user-data
* like configuration, extensions, and mementos.
*
* Note that this function defines the whole set of keys whose values are synchronized:
* - calling it with an empty array stops synchronization for this memento
* - calling it with a non-empty array replaces all keys whose values are synchronized
*
* For any given set of keys this function needs to be called only once but there is no harm in
* repeatedly calling it.
*
* @param keys The set of keys whose values are synced.
*/
setKeysForSync(keys: readonly string[]): void;
};So we had to implement setKeysForSync too. But now we've declared that InvocationRateLimiter only takes a Memento instead of typeof ExtensionContext.globalState, we don't have to mock this method in the tests anymore.
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Moves the
InvocationRateLimiterclass out ofhelpers.tsand into its own file. Then by having it take theMementointerface as an argument instead of the fullExtensionContextwe can move it to thecommondirectory and dramatically reduce the amount of mocking in the tests.Checklist
ready-for-doc-reviewlabel there.