@@ -20,6 +20,7 @@ import { ObjectCanon } from "../object-canon";
20
20
import { TypePolicies } from "../policies" ;
21
21
import { spyOnConsole } from "../../../testing/internal" ;
22
22
import { defaultCacheSizes } from "../../../utilities" ;
23
+ import { $ } from "../privates" ;
23
24
24
25
disableFragmentWarnings ( ) ;
25
26
@@ -1498,13 +1499,15 @@ describe("Cache", () => {
1498
1499
}
1499
1500
` ;
1500
1501
1501
- const originalReader = cache [ "storeReader" ] ;
1502
+ const privates = $ ( cache ) ;
1503
+
1504
+ const originalReader = privates . storeReader ;
1502
1505
expect ( originalReader ) . toBeInstanceOf ( StoreReader ) ;
1503
1506
1504
- const originalWriter = cache [ " storeWriter" ] ;
1507
+ const originalWriter = privates . storeWriter ;
1505
1508
expect ( originalWriter ) . toBeInstanceOf ( StoreWriter ) ;
1506
1509
1507
- const originalMBW = cache [ " maybeBroadcastWatch" ] ;
1510
+ const originalMBW = privates . maybeBroadcastWatch ;
1508
1511
expect ( typeof originalMBW ) . toBe ( "function" ) ;
1509
1512
1510
1513
const originalCanon = originalReader . canon ;
@@ -1534,12 +1537,12 @@ describe("Cache", () => {
1534
1537
c : "see" ,
1535
1538
} ) ;
1536
1539
1537
- expect ( originalReader ) . not . toBe ( cache [ " storeReader" ] ) ;
1538
- expect ( originalWriter ) . not . toBe ( cache [ " storeWriter" ] ) ;
1539
- expect ( originalMBW ) . not . toBe ( cache [ " maybeBroadcastWatch" ] ) ;
1540
+ expect ( originalReader ) . not . toBe ( privates . storeReader ) ;
1541
+ expect ( originalWriter ) . not . toBe ( privates . storeWriter ) ;
1542
+ expect ( originalMBW ) . not . toBe ( privates . maybeBroadcastWatch ) ;
1540
1543
// The cache.storeReader.canon is preserved by default, but can be dropped
1541
1544
// by passing resetResultIdentities:true to cache.gc.
1542
- expect ( originalCanon ) . toBe ( cache [ " storeReader" ] . canon ) ;
1545
+ expect ( originalCanon ) . toBe ( privates . storeReader . canon ) ;
1543
1546
} ) ;
1544
1547
} ) ;
1545
1548
@@ -2122,10 +2125,11 @@ describe("Cache", () => {
2122
2125
describe ( "resultCacheMaxSize" , ( ) => {
2123
2126
it ( "uses default max size on caches if resultCacheMaxSize is not configured" , ( ) => {
2124
2127
const cache = new InMemoryCache ( ) ;
2125
- expect ( cache [ "maybeBroadcastWatch" ] . options . max ) . toBe (
2128
+ const privates = $ ( cache ) ;
2129
+ expect ( privates . maybeBroadcastWatch . options . max ) . toBe (
2126
2130
defaultCacheSizes [ "inMemoryCache.maybeBroadcastWatch" ]
2127
2131
) ;
2128
- expect ( cache [ " storeReader" ] [ "executeSelectionSet" ] . options . max ) . toBe (
2132
+ expect ( privates . storeReader [ "executeSelectionSet" ] . options . max ) . toBe (
2129
2133
defaultCacheSizes [ "inMemoryCache.executeSelectionSet" ]
2130
2134
) ;
2131
2135
expect ( cache [ "getFragmentDoc" ] . options . max ) . toBe (
@@ -2136,8 +2140,9 @@ describe("resultCacheMaxSize", () => {
2136
2140
it ( "configures max size on caches when resultCacheMaxSize is set" , ( ) => {
2137
2141
const resultCacheMaxSize = 12345 ;
2138
2142
const cache = new InMemoryCache ( { resultCacheMaxSize } ) ;
2139
- expect ( cache [ "maybeBroadcastWatch" ] . options . max ) . toBe ( resultCacheMaxSize ) ;
2140
- expect ( cache [ "storeReader" ] [ "executeSelectionSet" ] . options . max ) . toBe (
2143
+ const privates = $ ( cache ) ;
2144
+ expect ( privates . maybeBroadcastWatch . options . max ) . toBe ( resultCacheMaxSize ) ;
2145
+ expect ( privates . storeReader [ "executeSelectionSet" ] . options . max ) . toBe (
2141
2146
resultCacheMaxSize
2142
2147
) ;
2143
2148
expect ( cache [ "getFragmentDoc" ] . options . max ) . toBe (
@@ -2400,7 +2405,7 @@ describe("InMemoryCache#broadcastWatches", function () {
2400
2405
[ canonicalCache , nonCanonicalCache ] . forEach ( ( cache ) => {
2401
2406
// Hack: delete every watch.lastDiff, so subsequent results will be
2402
2407
// broadcast, even though they are deeply equal to the previous results.
2403
- cache [ "watches" ] . forEach ( ( watch ) => {
2408
+ $ ( cache ) [ "watches" ] . forEach ( ( watch ) => {
2404
2409
delete watch . lastDiff ;
2405
2410
} ) ;
2406
2411
} ) ;
@@ -3813,19 +3818,20 @@ describe("ReactiveVar and makeVar", () => {
3813
3818
3814
3819
expect ( diffs . length ) . toBe ( 5 ) ;
3815
3820
3816
- expect ( cache [ "watches" ] . size ) . toBe ( 5 ) ;
3821
+ const watches = $ ( cache ) [ "watches" ] ;
3822
+ expect ( watches . size ) . toBe ( 5 ) ;
3817
3823
expect ( spy ) . not . toBeCalled ( ) ;
3818
3824
3819
3825
unwatchers . pop ( ) ! ( ) ;
3820
- expect ( cache [ " watches" ] . size ) . toBe ( 4 ) ;
3826
+ expect ( watches . size ) . toBe ( 4 ) ;
3821
3827
expect ( spy ) . not . toBeCalled ( ) ;
3822
3828
3823
3829
unwatchers . shift ( ) ! ( ) ;
3824
- expect ( cache [ " watches" ] . size ) . toBe ( 3 ) ;
3830
+ expect ( watches . size ) . toBe ( 3 ) ;
3825
3831
expect ( spy ) . not . toBeCalled ( ) ;
3826
3832
3827
3833
unwatchers . pop ( ) ! ( ) ;
3828
- expect ( cache [ " watches" ] . size ) . toBe ( 2 ) ;
3834
+ expect ( watches . size ) . toBe ( 2 ) ;
3829
3835
expect ( spy ) . not . toBeCalled ( ) ;
3830
3836
3831
3837
expect ( diffs . length ) . toBe ( 5 ) ;
@@ -3835,7 +3841,7 @@ describe("ReactiveVar and makeVar", () => {
3835
3841
expect ( unwatchers . length ) . toBe ( 3 ) ;
3836
3842
unwatchers . forEach ( ( unwatch ) => unwatch ( ) ) ;
3837
3843
3838
- expect ( cache [ " watches" ] . size ) . toBe ( 0 ) ;
3844
+ expect ( watches . size ) . toBe ( 0 ) ;
3839
3845
expect ( spy ) . toBeCalledTimes ( 1 ) ;
3840
3846
expect ( spy ) . toBeCalledWith ( cache ) ;
3841
3847
} ) ;
@@ -3865,7 +3871,8 @@ describe("ReactiveVar and makeVar", () => {
3865
3871
watch ( "a" ) ;
3866
3872
watch ( "d" ) ;
3867
3873
3868
- expect ( cache [ "watches" ] . size ) . toBe ( 5 ) ;
3874
+ const watches = $ ( cache ) [ "watches" ] ;
3875
+ expect ( watches . size ) . toBe ( 5 ) ;
3869
3876
expect ( diffCounts ) . toEqual ( {
3870
3877
a : 2 ,
3871
3878
b : 1 ,
@@ -3875,7 +3882,7 @@ describe("ReactiveVar and makeVar", () => {
3875
3882
3876
3883
unwatchers . a . forEach ( ( unwatch ) => unwatch ( ) ) ;
3877
3884
unwatchers . a . length = 0 ;
3878
- expect ( cache [ " watches" ] . size ) . toBe ( 3 ) ;
3885
+ expect ( watches . size ) . toBe ( 3 ) ;
3879
3886
3880
3887
nameVar ( "Hugh" ) ;
3881
3888
expect ( diffCounts ) . toEqual ( {
@@ -3886,7 +3893,7 @@ describe("ReactiveVar and makeVar", () => {
3886
3893
} ) ;
3887
3894
3888
3895
cache . reset ( { discardWatches : true } ) ;
3889
- expect ( cache [ " watches" ] . size ) . toBe ( 0 ) ;
3896
+ expect ( watches . size ) . toBe ( 0 ) ;
3890
3897
3891
3898
expect ( diffCounts ) . toEqual ( {
3892
3899
a : 2 ,
@@ -3926,7 +3933,7 @@ describe("ReactiveVar and makeVar", () => {
3926
3933
} ) ;
3927
3934
3928
3935
nameVar ( "Trevor" ) ;
3929
- expect ( cache [ " watches" ] . size ) . toBe ( 2 ) ;
3936
+ expect ( watches . size ) . toBe ( 2 ) ;
3930
3937
expect ( diffCounts ) . toEqual ( {
3931
3938
a : 2 ,
3932
3939
b : 2 ,
@@ -3937,7 +3944,7 @@ describe("ReactiveVar and makeVar", () => {
3937
3944
} ) ;
3938
3945
3939
3946
cache . reset ( { discardWatches : true } ) ;
3940
- expect ( cache [ " watches" ] . size ) . toBe ( 0 ) ;
3947
+ expect ( watches . size ) . toBe ( 0 ) ;
3941
3948
3942
3949
nameVar ( "Danielle" ) ;
3943
3950
expect ( diffCounts ) . toEqual ( {
@@ -3949,7 +3956,7 @@ describe("ReactiveVar and makeVar", () => {
3949
3956
f : 2 ,
3950
3957
} ) ;
3951
3958
3952
- expect ( cache [ " watches" ] . size ) . toBe ( 0 ) ;
3959
+ expect ( watches . size ) . toBe ( 0 ) ;
3953
3960
} ) ;
3954
3961
3955
3962
it ( "should recall forgotten vars once cache has watches again" , ( ) => {
@@ -3974,22 +3981,23 @@ describe("ReactiveVar and makeVar", () => {
3974
3981
expect ( diffs . length ) . toBe ( 3 ) ;
3975
3982
expect ( names ( ) ) . toEqual ( [ "Ben" , "Ben" , "Ben" ] ) ;
3976
3983
3977
- expect ( cache [ "watches" ] . size ) . toBe ( 3 ) ;
3984
+ const watches = $ ( cache ) [ "watches" ] ;
3985
+ expect ( watches . size ) . toBe ( 3 ) ;
3978
3986
expect ( spy ) . not . toBeCalled ( ) ;
3979
3987
3980
3988
unwatchers . pop ( ) ! ( ) ;
3981
- expect ( cache [ " watches" ] . size ) . toBe ( 2 ) ;
3989
+ expect ( watches . size ) . toBe ( 2 ) ;
3982
3990
expect ( spy ) . not . toBeCalled ( ) ;
3983
3991
3984
3992
unwatchers . shift ( ) ! ( ) ;
3985
- expect ( cache [ " watches" ] . size ) . toBe ( 1 ) ;
3993
+ expect ( watches . size ) . toBe ( 1 ) ;
3986
3994
expect ( spy ) . not . toBeCalled ( ) ;
3987
3995
3988
3996
nameVar ( "Hugh" ) ;
3989
3997
expect ( names ( ) ) . toEqual ( [ "Ben" , "Ben" , "Ben" , "Hugh" ] ) ;
3990
3998
3991
3999
unwatchers . pop ( ) ! ( ) ;
3992
- expect ( cache [ " watches" ] . size ) . toBe ( 0 ) ;
4000
+ expect ( watches . size ) . toBe ( 0 ) ;
3993
4001
expect ( spy ) . toBeCalledTimes ( 1 ) ;
3994
4002
expect ( spy ) . toBeCalledWith ( cache ) ;
3995
4003
@@ -3999,7 +4007,7 @@ describe("ReactiveVar and makeVar", () => {
3999
4007
4000
4008
// Call watch(false) to avoid immediate delivery of the "ignored" name.
4001
4009
unwatchers . push ( watch ( false ) ) ;
4002
- expect ( cache [ " watches" ] . size ) . toBe ( 1 ) ;
4010
+ expect ( watches . size ) . toBe ( 1 ) ;
4003
4011
expect ( names ( ) ) . toEqual ( [ "Ben" , "Ben" , "Ben" , "Hugh" ] ) ;
4004
4012
4005
4013
// This is the test that would fail if cache.watch did not call
0 commit comments