@@ -9,7 +9,7 @@ import * as externalDeps from '../../../client/pythonEnvironments/common/externa
9
9
10
10
suite ( 'Environment Info cache' , ( ) => {
11
11
let createGlobalPersistentStoreStub : sinon . SinonStub ;
12
- let updatedValues : PythonEnvInfo [ ] = [ ] ;
12
+ let updatedValues : PythonEnvInfo [ ] | undefined ;
13
13
14
14
const allEnvsComplete : CompleteEnvInfoFunction = ( ) => true ;
15
15
const envInfoArray = [
@@ -37,7 +37,7 @@ suite('Environment Info cache', () => {
37
37
38
38
teardown ( ( ) => {
39
39
createGlobalPersistentStoreStub . restore ( ) ;
40
- updatedValues = [ ] ;
40
+ updatedValues = undefined ;
41
41
} ) ;
42
42
43
43
test ( '`initialize` reads from persistent storage' , ( ) => {
@@ -48,6 +48,16 @@ suite('Environment Info cache', () => {
48
48
assert . ok ( createGlobalPersistentStoreStub . calledOnce ) ;
49
49
} ) ;
50
50
51
+ test ( 'The in-memory env info array is undefined if there is no value in persistent storage when initializing the cache' , ( ) => {
52
+ const envsCache = new PythonEnvInfoCache ( allEnvsComplete ) ;
53
+
54
+ createGlobalPersistentStoreStub . returns ( { value : undefined } ) ;
55
+ envsCache . initialize ( ) ;
56
+ const result = envsCache . getAllEnvs ( ) ;
57
+
58
+ assert . strictEqual ( result , undefined ) ;
59
+ } ) ;
60
+
51
61
test ( '`getAllEnvs` should return undefined if nothing has been set' , ( ) => {
52
62
const envsCache = new PythonEnvInfoCache ( allEnvsComplete ) ;
53
63
@@ -108,12 +118,20 @@ suite('Environment Info cache', () => {
108
118
assert . deepStrictEqual ( updatedValues , expected ) ;
109
119
} ) ;
110
120
121
+ test ( '`flush` should not write to persistent storage if there are no environment info objects in-memory' , async ( ) => {
122
+ const envsCache = new PythonEnvInfoCache ( ( env ) => env . kind === PythonEnvKind . MacDefault ) ;
123
+
124
+ await envsCache . flush ( ) ;
125
+
126
+ assert . strictEqual ( updatedValues , undefined ) ;
127
+ } ) ;
128
+
111
129
test ( '`flush` should not write to persistent storage if there are no complete environment info objects' , async ( ) => {
112
130
const envsCache = new PythonEnvInfoCache ( ( env ) => env . kind === PythonEnvKind . MacDefault ) ;
113
131
114
132
envsCache . initialize ( ) ;
115
133
await envsCache . flush ( ) ;
116
134
117
- assert . deepStrictEqual ( updatedValues , [ ] ) ;
135
+ assert . strictEqual ( updatedValues , undefined ) ;
118
136
} ) ;
119
137
} ) ;
0 commit comments