1- import {
2- EnvironmentVariableCollection ,
3- EnvironmentVariableMutator ,
4- Event ,
5- ExtensionContext ,
6- ExtensionMode ,
7- Memento ,
8- SecretStorage ,
9- SecretStorageChangeEvent ,
10- Uri ,
11- } from "vscode" ;
1+ import { Memento } from "vscode" ;
122import { InvocationRateLimiter } from "../../../src/invocation-rate-limiter" ;
133
144describe ( "Invocation rate limiter" , ( ) => {
@@ -28,75 +18,13 @@ describe("Invocation rate limiter", () => {
2818 func : ( ) => Promise < T > ,
2919 ) : InvocationRateLimiter < T > {
3020 return new InvocationRateLimiter (
31- new MockExtensionContext ( ) ,
21+ new MockGlobalStorage ( ) ,
3222 funcIdentifier ,
3323 func ,
3424 ( s ) => createDate ( s ) ,
3525 ) ;
3626 }
3727
38- class MockExtensionContext implements ExtensionContext {
39- extensionMode : ExtensionMode = 3 ;
40- subscriptions : Array < { dispose ( ) : unknown } > = [ ] ;
41- workspaceState : Memento = new MockMemento ( ) ;
42- globalState = new MockGlobalStorage ( ) ;
43- extensionPath = "" ;
44- asAbsolutePath ( _relativePath : string ) : string {
45- throw new Error ( "Method not implemented." ) ;
46- }
47- storagePath = "" ;
48- globalStoragePath = "" ;
49- logPath = "" ;
50- extensionUri = Uri . parse ( "" ) ;
51- environmentVariableCollection = new MockEnvironmentVariableCollection ( ) ;
52- secrets = new MockSecretStorage ( ) ;
53- storageUri = Uri . parse ( "" ) ;
54- globalStorageUri = Uri . parse ( "" ) ;
55- logUri = Uri . parse ( "" ) ;
56- extension : any ;
57- }
58-
59- class MockEnvironmentVariableCollection
60- implements EnvironmentVariableCollection
61- {
62- [ Symbol . iterator ] ( ) : Iterator <
63- [ variable : string , mutator : EnvironmentVariableMutator ] ,
64- any ,
65- undefined
66- > {
67- throw new Error ( "Method not implemented." ) ;
68- }
69- persistent = false ;
70- replace ( _variable : string , _value : string ) : void {
71- throw new Error ( "Method not implemented." ) ;
72- }
73- append ( _variable : string , _value : string ) : void {
74- throw new Error ( "Method not implemented." ) ;
75- }
76- prepend ( _variable : string , _value : string ) : void {
77- throw new Error ( "Method not implemented." ) ;
78- }
79- get ( _variable : string ) : EnvironmentVariableMutator | undefined {
80- throw new Error ( "Method not implemented." ) ;
81- }
82- forEach (
83- _callback : (
84- variable : string ,
85- mutator : EnvironmentVariableMutator ,
86- collection : EnvironmentVariableCollection ,
87- ) => any ,
88- _thisArg ?: any ,
89- ) : void {
90- throw new Error ( "Method not implemented." ) ;
91- }
92- delete ( _variable : string ) : void {
93- throw new Error ( "Method not implemented." ) ;
94- }
95- clear ( ) : void {
96- throw new Error ( "Method not implemented." ) ;
97- }
98- }
99-
10028 class MockMemento implements Memento {
10129 keys ( ) : readonly string [ ] {
10230 throw new Error ( "Method not implemented." ) ;
@@ -132,19 +60,6 @@ describe("Invocation rate limiter", () => {
13260 }
13361 }
13462
135- class MockSecretStorage implements SecretStorage {
136- get ( _key : string ) : Thenable < string | undefined > {
137- throw new Error ( "Method not implemented." ) ;
138- }
139- store ( _key : string , _value : string ) : Thenable < void > {
140- throw new Error ( "Method not implemented." ) ;
141- }
142- delete ( _key : string ) : Thenable < void > {
143- throw new Error ( "Method not implemented." ) ;
144- }
145- onDidChange ! : Event < SecretStorageChangeEvent > ;
146- }
147-
14863 it ( "initially invokes function" , async ( ) => {
14964 let numTimesFuncCalled = 0 ;
15065 const invocationRateLimiter = createInvocationRateLimiter (
0 commit comments