@@ -88,19 +88,31 @@ const expectedHashWithFilter = 'fdf7bd89'; // for SDK key '<fake-token-rfc>', fi
8888
8989export default function ( fetchMock , assert ) {
9090
91- assert . test ( t => { // Testing when we start from scratch
91+ assert . test ( t => { // Testing when we start from scratch, with an initial localStorage write operation fail (should retry splitChanges with -1)
9292 const testUrls = {
9393 sdk : 'https://sdk.baseurl/readyFromCacheEmpty' ,
9494 events : 'https://events.baseurl/readyFromCacheEmpty'
9595 } ;
9696 localStorage . clear ( ) ;
97+
98+ // simulate a localStorage failure when saving a FF
99+ const originalSetItem = localStorage . setItem ;
100+ localStorage . setItem = ( key , value ) => {
101+ if ( key . includes ( '.split.' ) ) {
102+ localStorage . setItem = originalSetItem ;
103+ throw new Error ( 'localStorage.setItem failed' ) ;
104+ }
105+ return originalSetItem . call ( localStorage , key , value ) ;
106+ } ;
107+
97108 t . plan ( 3 ) ;
98109
99- fetchMock . get ( testUrls . sdk + '/splitChanges?s=1.1&since=-1' , { status : 200 , body : splitChangesMock1 } ) ;
100- fetchMock . get ( testUrls . sdk + '/splitChanges?s=1.1&since=1457552620999' , { status : 200 , body : splitChangesMock2 } ) ;
101- fetchMock . get ( testUrls . sdk + '/mySegments/nicolas%40split.io' , { status : 200 , body : mySegmentsNicolas } ) ;
102- fetchMock . get ( testUrls . sdk + '/mySegments/nicolas2%40split.io' , { status : 200 , body : { 'mySegments' : [ ] } } ) ;
103- fetchMock . get ( testUrls . sdk + '/mySegments/nicolas3%40split.io' , { status : 200 , body : { 'mySegments' : [ ] } } ) ;
110+ fetchMock . getOnce ( testUrls . sdk + '/splitChanges?s=1.1&since=-1' , { status : 200 , body : splitChangesMock1 } ) ;
111+ fetchMock . getOnce ( testUrls . sdk + '/splitChanges?s=1.1&since=-1' , { status : 200 , body : splitChangesMock1 } ) ;
112+ fetchMock . getOnce ( testUrls . sdk + '/splitChanges?s=1.1&since=1457552620999' , { status : 200 , body : splitChangesMock2 } ) ;
113+ fetchMock . getOnce ( testUrls . sdk + '/mySegments/nicolas%40split.io' , { status : 200 , body : mySegmentsNicolas } ) ;
114+ fetchMock . getOnce ( testUrls . sdk + '/mySegments/nicolas2%40split.io' , { status : 200 , body : { 'mySegments' : [ ] } } ) ;
115+ fetchMock . getOnce ( testUrls . sdk + '/mySegments/nicolas3%40split.io' , { status : 200 , body : { 'mySegments' : [ ] } } ) ;
104116
105117 const splitio = SplitFactory ( {
106118 ...baseConfig ,
0 commit comments