@@ -11,6 +11,7 @@ import { ConfigurationTarget, Uri, WorkspaceConfiguration } from 'vscode';
11
11
import { IApplicationShell , IWorkspaceService } from '../../../client/common/application/types' ;
12
12
import { PersistentStateFactory } from '../../../client/common/persistentState' ;
13
13
import { IPersistentState , IPersistentStateFactory } from '../../../client/common/types' ;
14
+ import { createDeferred , createDeferredFromPromise , sleep } from '../../../client/common/utils/async' ;
14
15
import { InteractiveShiftEnterBanner , Interpreters } from '../../../client/common/utils/localize' ;
15
16
import { IInterpreterService , InterpreterType } from '../../../client/interpreter/contracts' ;
16
17
import { CondaInheritEnvPrompt , condaInheritEnvPromptKey } from '../../../client/interpreter/virtualEnvs/condaInheritEnvPrompt' ;
@@ -185,8 +186,47 @@ suite('Conda Inherit Env Prompt', async () => {
185
186
verifyAll ( ) ;
186
187
} ) ;
187
188
} ) ;
188
-
189
189
suite ( 'Method activate()' , ( ) => {
190
+ let initializeInBackground : sinon . SinonStub < any > ;
191
+ setup ( ( ) => {
192
+ workspaceService = TypeMoq . Mock . ofType < IWorkspaceService > ( ) ;
193
+ appShell = TypeMoq . Mock . ofType < IApplicationShell > ( ) ;
194
+ interpreterService = TypeMoq . Mock . ofType < IInterpreterService > ( ) ;
195
+ persistentStateFactory = mock ( PersistentStateFactory ) ;
196
+ } ) ;
197
+
198
+ teardown ( ( ) => {
199
+ sinon . restore ( ) ;
200
+ } ) ;
201
+
202
+ test ( 'Invokes initializeInBackground() in the background' , async ( ) => {
203
+ const initializeInBackgroundDeferred = createDeferred < void > ( ) ;
204
+ initializeInBackground = sinon . stub ( CondaInheritEnvPrompt . prototype , 'initializeInBackground' ) ;
205
+ initializeInBackground . callsFake ( ( ) => initializeInBackgroundDeferred . promise ) ;
206
+ condaInheritEnvPrompt = new CondaInheritEnvPrompt ( interpreterService . object , workspaceService . object , appShell . object , instance ( persistentStateFactory ) ) ;
207
+
208
+ const promise = condaInheritEnvPrompt . activate ( resource ) ;
209
+ const deferred = createDeferredFromPromise ( promise ) ;
210
+ await sleep ( 1 ) ;
211
+
212
+ // Ensure activate() function has completed while initializeInBackground() is still not resolved
213
+ assert . equal ( deferred . completed , true ) ;
214
+
215
+ initializeInBackgroundDeferred . resolve ( ) ;
216
+ await sleep ( 1 ) ;
217
+ assert . ok ( initializeInBackground . calledOnce ) ;
218
+ } ) ;
219
+
220
+ test ( 'Ignores errors raised by initializeInBackground()' , async ( ) => {
221
+ initializeInBackground = sinon . stub ( CondaInheritEnvPrompt . prototype , 'initializeInBackground' ) ;
222
+ initializeInBackground . rejects ( new Error ( 'Kaboom' ) ) ;
223
+ condaInheritEnvPrompt = new CondaInheritEnvPrompt ( interpreterService . object , workspaceService . object , appShell . object , instance ( persistentStateFactory ) ) ;
224
+ await condaInheritEnvPrompt . activate ( resource ) ;
225
+ assert . ok ( initializeInBackground . calledOnce ) ;
226
+ } ) ;
227
+ } ) ;
228
+
229
+ suite ( 'Method initializeInBackground()' , ( ) => {
190
230
let shouldShowPrompt : sinon . SinonStub < any > ;
191
231
let promptAndUpdate : sinon . SinonStub < any > ;
192
232
setup ( ( ) => {
@@ -206,7 +246,7 @@ suite('Conda Inherit Env Prompt', async () => {
206
246
promptAndUpdate = sinon . stub ( CondaInheritEnvPrompt . prototype , 'promptAndUpdate' ) ;
207
247
promptAndUpdate . callsFake ( ( ) => Promise . resolve ( undefined ) ) ;
208
248
condaInheritEnvPrompt = new CondaInheritEnvPrompt ( interpreterService . object , workspaceService . object , appShell . object , instance ( persistentStateFactory ) ) ;
209
- await condaInheritEnvPrompt . activate ( resource ) ;
249
+ await condaInheritEnvPrompt . initializeInBackground ( resource ) ;
210
250
assert . ok ( shouldShowPrompt . calledOnce ) ;
211
251
assert . ok ( promptAndUpdate . calledOnce ) ;
212
252
} ) ;
@@ -217,7 +257,7 @@ suite('Conda Inherit Env Prompt', async () => {
217
257
promptAndUpdate = sinon . stub ( CondaInheritEnvPrompt . prototype , 'promptAndUpdate' ) ;
218
258
promptAndUpdate . callsFake ( ( ) => Promise . resolve ( undefined ) ) ;
219
259
condaInheritEnvPrompt = new CondaInheritEnvPrompt ( interpreterService . object , workspaceService . object , appShell . object , instance ( persistentStateFactory ) ) ;
220
- await condaInheritEnvPrompt . activate ( resource ) ;
260
+ await condaInheritEnvPrompt . initializeInBackground ( resource ) ;
221
261
assert . ok ( shouldShowPrompt . calledOnce ) ;
222
262
assert . ok ( promptAndUpdate . notCalled ) ;
223
263
} ) ;
0 commit comments