@@ -108,18 +108,30 @@ export const expectedHashWithFilter = '2ce5cc38'; // for SDK key '<fake-token-rf
108108
109109export default function ( fetchMock , assert ) {
110110
111- assert . test ( t => { // Testing when we start from scratch
111+ assert . test ( t => { // Testing when we start from scratch, with an initial localStorage write operation fail (should retry splitChanges with -1)
112112 const testUrls = {
113113 sdk : 'https://sdk.baseurl/readyFromCacheEmpty' ,
114114 events : 'https://events.baseurl/readyFromCacheEmpty'
115115 } ;
116116 localStorage . clear ( ) ;
117+
118+ // simulate a localStorage failure when saving a FF
119+ const originalSetItem = localStorage . setItem ;
120+ localStorage . setItem = ( key , value ) => {
121+ if ( key . includes ( '.split.' ) ) {
122+ localStorage . setItem = originalSetItem ;
123+ throw new Error ( 'localStorage.setItem failed' ) ;
124+ }
125+ return originalSetItem . call ( localStorage , key , value ) ;
126+ } ;
127+
117128 t . plan ( 4 ) ;
118129
119- fetchMock . get ( testUrls . sdk + '/splitChanges?s=1.3&since=-1&rbSince=-1' , { status : 200 , body : splitChangesMock1 } ) ;
120- fetchMock . get ( testUrls . sdk + '/memberships/nicolas%40split.io' , { status : 200 , body : membershipsNicolas } ) ;
121- fetchMock . get ( testUrls . sdk + '/memberships/nicolas2%40split.io' , { status : 200 , body : { 'ms' : { } } } ) ;
122- fetchMock . get ( testUrls . sdk + '/memberships/nicolas3%40split.io' , { status : 200 , body : { 'ms' : { } } } ) ;
130+ fetchMock . getOnce ( testUrls . sdk + '/splitChanges?s=1.3&since=-1&rbSince=-1' , { status : 200 , body : splitChangesMock1 } ) ;
131+ fetchMock . getOnce ( testUrls . sdk + '/splitChanges?s=1.3&since=-1&rbSince=-1' , { status : 200 , body : splitChangesMock1 } ) ;
132+ fetchMock . getOnce ( testUrls . sdk + '/memberships/nicolas%40split.io' , { status : 200 , body : membershipsNicolas } ) ;
133+ fetchMock . getOnce ( testUrls . sdk + '/memberships/nicolas2%40split.io' , { status : 200 , body : { 'ms' : { } } } ) ;
134+ fetchMock . getOnce ( testUrls . sdk + '/memberships/nicolas3%40split.io' , { status : 200 , body : { 'ms' : { } } } ) ;
123135
124136 const splitio = SplitFactory ( {
125137 ...baseConfig ,
0 commit comments