@@ -14,6 +14,8 @@ import { IApplicationEnvironment, IWorkspaceService } from '../../../client/comm
14
14
import { WorkspaceService } from '../../../client/common/application/workspace' ;
15
15
import { Channel } from '../../../client/common/constants' ;
16
16
import { ExperimentService } from '../../../client/common/experiments/service' ;
17
+ import { PersistentState } from '../../../client/common/persistentState' ;
18
+ import { IPersistentStateFactory } from '../../../client/common/types' ;
17
19
import { Experiments } from '../../../client/common/utils/localize' ;
18
20
import { registerLogger } from '../../../client/logging' ;
19
21
import { OutputChannelLogger } from '../../../client/logging/outputChannelLogger' ;
@@ -25,17 +27,23 @@ import { MockMemento } from '../../mocks/mementos';
25
27
26
28
suite ( 'Experimentation service' , ( ) => {
27
29
const extensionVersion = '1.2.3' ;
30
+ const dummyExperimentKey = 'experimentsKey' ;
28
31
29
32
let workspaceService : IWorkspaceService ;
30
33
let appEnvironment : IApplicationEnvironment ;
34
+ let stateFactory : IPersistentStateFactory ;
31
35
let globalMemento : MockMemento ;
32
36
let outputChannel : MockOutputChannel ;
33
37
let disposeLogger : Disposable ;
34
38
35
39
setup ( ( ) => {
36
40
appEnvironment = mock ( ApplicationEnvironment ) ;
37
41
workspaceService = mock ( WorkspaceService ) ;
42
+ stateFactory = mock < IPersistentStateFactory > ( ) ;
38
43
globalMemento = new MockMemento ( ) ;
44
+ when ( stateFactory . createGlobalPersistentState ( anything ( ) , anything ( ) ) ) . thenReturn (
45
+ new PersistentState ( globalMemento , dummyExperimentKey , { features : [ ] } ) ,
46
+ ) ;
39
47
outputChannel = new MockOutputChannel ( '' ) ;
40
48
disposeLogger = registerLogger ( new OutputChannelLogger ( outputChannel ) ) ;
41
49
} ) ;
@@ -78,7 +86,7 @@ suite('Experimentation service', () => {
78
86
configureApplicationEnvironment ( 'stable' , extensionVersion ) ;
79
87
80
88
// eslint-disable-next-line no-new
81
- new ExperimentService ( instance ( workspaceService ) , instance ( appEnvironment ) , globalMemento ) ;
89
+ new ExperimentService ( instance ( workspaceService ) , instance ( appEnvironment ) , instance ( stateFactory ) ) ;
82
90
83
91
sinon . assert . calledWithExactly (
84
92
getExperimentationServiceStub ,
@@ -97,7 +105,7 @@ suite('Experimentation service', () => {
97
105
configureApplicationEnvironment ( 'insiders' , extensionVersion ) ;
98
106
99
107
// eslint-disable-next-line no-new
100
- new ExperimentService ( instance ( workspaceService ) , instance ( appEnvironment ) , globalMemento ) ;
108
+ new ExperimentService ( instance ( workspaceService ) , instance ( appEnvironment ) , instance ( stateFactory ) ) ;
101
109
102
110
sinon . assert . calledWithExactly (
103
111
getExperimentationServiceStub ,
@@ -118,7 +126,7 @@ suite('Experimentation service', () => {
118
126
const experimentService = new ExperimentService (
119
127
instance ( workspaceService ) ,
120
128
instance ( appEnvironment ) ,
121
- globalMemento ,
129
+ instance ( stateFactory ) ,
122
130
) ;
123
131
124
132
assert . deepEqual ( experimentService . _optInto , [ 'Foo - experiment' ] ) ;
@@ -132,25 +140,22 @@ suite('Experimentation service', () => {
132
140
const experimentService = new ExperimentService (
133
141
instance ( workspaceService ) ,
134
142
instance ( appEnvironment ) ,
135
- globalMemento ,
143
+ instance ( stateFactory ) ,
136
144
) ;
137
145
138
146
assert . deepEqual ( experimentService . _optOutFrom , [ 'Foo - experiment' ] ) ;
139
147
} ) ;
140
148
141
149
test ( 'Experiment data in Memento storage should be logged if it starts with "python"' , async ( ) => {
142
150
const experiments = [ 'ExperimentOne' , 'pythonExperiment' ] ;
143
- globalMemento = mock ( MockMemento ) ;
151
+ globalMemento . update ( dummyExperimentKey , { features : experiments } ) ;
144
152
configureSettings ( true , [ ] , [ ] ) ;
145
153
configureApplicationEnvironment ( 'stable' , extensionVersion , { configuration : { properties : { } } } ) ;
146
154
147
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
148
- when ( globalMemento . get ( anything ( ) , anything ( ) ) ) . thenReturn ( { features : experiments } as any ) ;
149
-
150
155
const exp = new ExperimentService (
151
156
instance ( workspaceService ) ,
152
157
instance ( appEnvironment ) ,
153
- instance ( globalMemento ) ,
158
+ instance ( stateFactory ) ,
154
159
) ;
155
160
await exp . activate ( ) ;
156
161
const output = `${ Experiments . inGroup ( ) . format ( 'pythonExperiment' ) } \n` ;
@@ -192,7 +197,7 @@ suite('Experimentation service', () => {
192
197
const experimentService = new ExperimentService (
193
198
instance ( workspaceService ) ,
194
199
instance ( appEnvironment ) ,
195
- globalMemento ,
200
+ instance ( stateFactory ) ,
196
201
) ;
197
202
const result = experimentService . inExperimentSync ( experiment ) ;
198
203
@@ -207,7 +212,7 @@ suite('Experimentation service', () => {
207
212
const experimentService = new ExperimentService (
208
213
instance ( workspaceService ) ,
209
214
instance ( appEnvironment ) ,
210
- globalMemento ,
215
+ instance ( stateFactory ) ,
211
216
) ;
212
217
const result = experimentService . inExperimentSync ( experiment ) ;
213
218
@@ -222,7 +227,7 @@ suite('Experimentation service', () => {
222
227
const experimentService = new ExperimentService (
223
228
instance ( workspaceService ) ,
224
229
instance ( appEnvironment ) ,
225
- globalMemento ,
230
+ instance ( stateFactory ) ,
226
231
) ;
227
232
const result = experimentService . inExperimentSync ( experiment ) ;
228
233
@@ -236,7 +241,7 @@ suite('Experimentation service', () => {
236
241
const experimentService = new ExperimentService (
237
242
instance ( workspaceService ) ,
238
243
instance ( appEnvironment ) ,
239
- globalMemento ,
244
+ instance ( stateFactory ) ,
240
245
) ;
241
246
const result = experimentService . inExperimentSync ( experiment ) ;
242
247
@@ -251,7 +256,7 @@ suite('Experimentation service', () => {
251
256
const experimentService = new ExperimentService (
252
257
instance ( workspaceService ) ,
253
258
instance ( appEnvironment ) ,
254
- globalMemento ,
259
+ instance ( stateFactory ) ,
255
260
) ;
256
261
const result = experimentService . inExperimentSync ( experiment ) ;
257
262
@@ -266,7 +271,7 @@ suite('Experimentation service', () => {
266
271
const experimentService = new ExperimentService (
267
272
instance ( workspaceService ) ,
268
273
instance ( appEnvironment ) ,
269
- globalMemento ,
274
+ instance ( stateFactory ) ,
270
275
) ;
271
276
const result = experimentService . inExperimentSync ( experiment ) ;
272
277
@@ -281,7 +286,7 @@ suite('Experimentation service', () => {
281
286
const experimentService = new ExperimentService (
282
287
instance ( workspaceService ) ,
283
288
instance ( appEnvironment ) ,
284
- globalMemento ,
289
+ instance ( stateFactory ) ,
285
290
) ;
286
291
const result = experimentService . inExperimentSync ( experiment ) ;
287
292
@@ -296,7 +301,7 @@ suite('Experimentation service', () => {
296
301
const experimentService = new ExperimentService (
297
302
instance ( workspaceService ) ,
298
303
instance ( appEnvironment ) ,
299
- globalMemento ,
304
+ instance ( stateFactory ) ,
300
305
) ;
301
306
const result = experimentService . inExperimentSync ( experiment ) ;
302
307
@@ -311,7 +316,7 @@ suite('Experimentation service', () => {
311
316
const experimentService = new ExperimentService (
312
317
instance ( workspaceService ) ,
313
318
instance ( appEnvironment ) ,
314
- globalMemento ,
319
+ instance ( stateFactory ) ,
315
320
) ;
316
321
const result = experimentService . inExperimentSync ( experiment ) ;
317
322
@@ -340,7 +345,7 @@ suite('Experimentation service', () => {
340
345
const experimentService = new ExperimentService (
341
346
instance ( workspaceService ) ,
342
347
instance ( appEnvironment ) ,
343
- globalMemento ,
348
+ instance ( stateFactory ) ,
344
349
) ;
345
350
const result = await experimentService . getExperimentValue ( experiment ) ;
346
351
@@ -354,7 +359,7 @@ suite('Experimentation service', () => {
354
359
const experimentService = new ExperimentService (
355
360
instance ( workspaceService ) ,
356
361
instance ( appEnvironment ) ,
357
- globalMemento ,
362
+ instance ( stateFactory ) ,
358
363
) ;
359
364
const result = await experimentService . getExperimentValue ( experiment ) ;
360
365
@@ -368,7 +373,7 @@ suite('Experimentation service', () => {
368
373
const experimentService = new ExperimentService (
369
374
instance ( workspaceService ) ,
370
375
instance ( appEnvironment ) ,
371
- globalMemento ,
376
+ instance ( stateFactory ) ,
372
377
) ;
373
378
const result = await experimentService . getExperimentValue ( experiment ) ;
374
379
@@ -382,7 +387,7 @@ suite('Experimentation service', () => {
382
387
const experimentService = new ExperimentService (
383
388
instance ( workspaceService ) ,
384
389
instance ( appEnvironment ) ,
385
- globalMemento ,
390
+ instance ( stateFactory ) ,
386
391
) ;
387
392
const result = await experimentService . getExperimentValue ( experiment ) ;
388
393
@@ -417,7 +422,7 @@ suite('Experimentation service', () => {
417
422
const experimentService = new ExperimentService (
418
423
instance ( workspaceService ) ,
419
424
instance ( appEnvironment ) ,
420
- globalMemento ,
425
+ instance ( stateFactory ) ,
421
426
) ;
422
427
423
428
await experimentService . activate ( ) ;
@@ -450,7 +455,7 @@ suite('Experimentation service', () => {
450
455
const experimentService = new ExperimentService (
451
456
instance ( workspaceService ) ,
452
457
instance ( appEnvironment ) ,
453
- globalMemento ,
458
+ instance ( stateFactory ) ,
454
459
) ;
455
460
456
461
await experimentService . activate ( ) ;
@@ -482,7 +487,7 @@ suite('Experimentation service', () => {
482
487
const experimentService = new ExperimentService (
483
488
instance ( workspaceService ) ,
484
489
instance ( appEnvironment ) ,
485
- globalMemento ,
490
+ instance ( stateFactory ) ,
486
491
) ;
487
492
488
493
await experimentService . activate ( ) ;
@@ -514,7 +519,7 @@ suite('Experimentation service', () => {
514
519
const experimentService = new ExperimentService (
515
520
instance ( workspaceService ) ,
516
521
instance ( appEnvironment ) ,
517
- globalMemento ,
522
+ instance ( stateFactory ) ,
518
523
) ;
519
524
520
525
await experimentService . activate ( ) ;
@@ -536,7 +541,7 @@ suite('Experimentation service', () => {
536
541
const experimentService = new ExperimentService (
537
542
instance ( workspaceService ) ,
538
543
instance ( appEnvironment ) ,
539
- globalMemento ,
544
+ instance ( stateFactory ) ,
540
545
) ;
541
546
542
547
await experimentService . activate ( ) ;
@@ -567,7 +572,7 @@ suite('Experimentation service', () => {
567
572
const experimentService = new ExperimentService (
568
573
instance ( workspaceService ) ,
569
574
instance ( appEnvironment ) ,
570
- globalMemento ,
575
+ instance ( stateFactory ) ,
571
576
) ;
572
577
573
578
await experimentService . activate ( ) ;
0 commit comments