@@ -43,37 +43,35 @@ describe('E2E test - Switcher local - Snapshot:', function () {
4343 } ) ;
4444
4545 it ( 'should update snapshot' , async function ( ) {
46- //given
46+ // given
4747 fetchStub = stub ( FetchFacade , 'fetch' ) ;
4848
4949 given ( fetchStub , 0 , { json : ( ) => generateAuth ( '[auth_token]' , 5 ) , status : 200 } ) ;
5050 given ( fetchStub , 1 , { json : ( ) => generateStatus ( false ) , status : 200 } ) ; // Snapshot outdated
5151 given ( fetchStub , 2 , { json : ( ) => JSON . parse ( dataJSON ) , status : 200 } ) ;
5252
53- //test
53+ // test
5454 Client . buildContext ( { url, apiKey, domain, component, environment } , {
55- snapshotLocation : 'generated-snapshots/' ,
5655 local : true ,
5756 regexSafe : false
5857 } ) ;
5958
6059 await Client . loadSnapshot ( { watchSnapshot : true } ) ;
61- assert . isTrue ( await Client . checkSnapshot ( ) ) ;
6260
63- //restore state to avoid process leakage
64- Client . unloadSnapshot ( ) ;
65- unlinkSync ( `generated-snapshots/ ${ environment } .json` ) ;
61+ assert . equal ( Client . snapshotVersion , 0 ) ;
62+ assert . isTrue ( await Client . checkSnapshot ( ) ) ;
63+ assert . isAbove ( Client . snapshotVersion , 0 ) ;
6664 } ) ;
6765
6866 it ( 'should update snapshot - store file' , async function ( ) {
69- //given
67+ // given
7068 fetchStub = stub ( FetchFacade , 'fetch' ) ;
7169
7270 given ( fetchStub , 0 , { json : ( ) => generateAuth ( '[auth_token]' , 5 ) , status : 200 } ) ;
7371 given ( fetchStub , 1 , { json : ( ) => generateStatus ( false ) , status : 200 } ) ; // Snapshot outdated
7472 given ( fetchStub , 2 , { json : ( ) => JSON . parse ( dataJSON ) , status : 200 } ) ;
7573
76- //test
74+ // test
7775 Client . buildContext ( { url, apiKey, domain, component, environment } , {
7876 snapshotLocation : 'generated-snapshots/' ,
7977 local : true ,
@@ -84,19 +82,19 @@ describe('E2E test - Switcher local - Snapshot:', function () {
8482 assert . isTrue ( await Client . checkSnapshot ( ) ) ;
8583 assert . isTrue ( existsSync ( `generated-snapshots/${ environment } .json` ) ) ;
8684
87- //restore state to avoid process leakage
85+ // restore state to avoid process leakage
8886 Client . unloadSnapshot ( ) ;
8987 } ) ;
9088
9189 it ( 'should update snapshot during load - store file' , async function ( ) {
92- //given
90+ // given
9391 fetchStub = stub ( FetchFacade , 'fetch' ) ;
9492
9593 given ( fetchStub , 0 , { json : ( ) => generateAuth ( '[auth_token]' , 5 ) , status : 200 } ) ;
9694 given ( fetchStub , 1 , { json : ( ) => generateStatus ( false ) , status : 200 } ) ; // Snapshot outdated
9795 given ( fetchStub , 2 , { json : ( ) => JSON . parse ( dataJSON ) , status : 200 } ) ;
9896
99- //test
97+ // test
10098 Client . buildContext ( { url, apiKey, domain, component, environment } , {
10199 snapshotLocation : 'generated-snapshots/' ,
102100 local : true ,
@@ -106,92 +104,92 @@ describe('E2E test - Switcher local - Snapshot:', function () {
106104 await Client . loadSnapshot ( { watchSnapshot : true , fetchRemote : true } ) ;
107105 assert . isTrue ( existsSync ( `generated-snapshots/${ environment } .json` ) ) ;
108106
109- //restore state to avoid process leakage
107+ // restore state to avoid process leakage
110108 Client . unloadSnapshot ( ) ;
111109 } ) ;
112110
113111 it ( 'should NOT update snapshot' , async function ( ) {
114- //given
112+ // given
115113 fetchStub = stub ( FetchFacade , 'fetch' ) ;
116114
117115 given ( fetchStub , 0 , { json : ( ) => generateAuth ( '[auth_token]' , 5 ) , status : 200 } ) ;
118116 given ( fetchStub , 1 , { json : ( ) => generateStatus ( true ) , status : 200 } ) ; // No available update
119117
120- //test
118+ // test
121119 await Client . loadSnapshot ( ) ;
122120 assert . isFalse ( await Client . checkSnapshot ( ) ) ;
123121 } ) ;
124122
125123 it ( 'should NOT update snapshot - check Snapshot Error' , async function ( ) {
126124 this . timeout ( 3000 ) ;
127125
128- //given
126+ // given
129127 fetchStub = stub ( FetchFacade , 'fetch' ) ;
130128
131129 given ( fetchStub , 0 , { json : ( ) => generateAuth ( '[auth_token]' , 5 ) , status : 200 } ) ;
132130 givenError ( fetchStub , 1 , { errno : 'ECONNREFUSED' } ) ;
133131
134- //test
132+ // test
135133 Client . testMode ( ) ;
136134 await Client . loadSnapshot ( ) ;
137135 await assertReject ( assert , Client . checkSnapshot ( ) ,
138136 'Something went wrong: Connection has been refused - ECONNREFUSED' ) ;
139137 } ) ;
140138
141139 it ( 'should NOT update snapshot - resolve Snapshot Error' , async function ( ) {
142- //given
140+ // given
143141 fetchStub = stub ( FetchFacade , 'fetch' ) ;
144142
145143 given ( fetchStub , 0 , { json : ( ) => generateAuth ( '[auth_token]' , 5 ) , status : 200 } ) ;
146144 given ( fetchStub , 1 , { json : ( ) => generateStatus ( false ) , status : 200 } ) ; // Snapshot outdated
147145 givenError ( fetchStub , 2 , { errno : 'ECONNREFUSED' } ) ;
148146
149- //test
147+ // test
150148 Client . testMode ( ) ;
151149 await Client . loadSnapshot ( ) ;
152150 await assertReject ( assert , Client . checkSnapshot ( ) ,
153151 'Something went wrong: Connection has been refused - ECONNREFUSED' ) ;
154152 } ) ;
155153
156154 it ( 'should NOT check snapshot with success - Snapshot not loaded' , async function ( ) {
157- //given
155+ // given
158156 fetchStub = stub ( FetchFacade , 'fetch' ) ;
159157
160158 given ( fetchStub , 0 , { json : ( ) => generateAuth ( '[auth_token]' , 5 ) , status : 200 } ) ;
161159 given ( fetchStub , 1 , { json : ( ) => generateStatus ( true ) , status : 200 } ) ;
162160
163- //pre-load snapshot
161+ // pre-load snapshot
164162 Client . testMode ( false ) ;
165163 await Client . loadSnapshot ( ) ;
166164 assert . equal ( await Client . checkSnapshot ( ) , false ) ;
167165
168- //unload snapshot
166+ // unload snapshot
169167 Client . unloadSnapshot ( ) ;
170168
171- //test
169+ // test
172170 let error = null ;
173171 await Client . checkSnapshot ( ) . catch ( ( err ) => error = err ) ;
174172 assert . exists ( error ) ;
175173 assert . equal ( error . message , 'Something went wrong: Snapshot is not loaded. Use Client.loadSnapshot()' ) ;
176174 } ) ;
177175
178176 it ( 'should update snapshot' , async function ( ) {
179- //given
177+ // given
180178 fetchStub = stub ( FetchFacade , 'fetch' ) ;
181179
182180 given ( fetchStub , 0 , { json : ( ) => generateAuth ( '[auth_token]' , 5 ) , status : 200 } ) ;
183181 given ( fetchStub , 1 , { json : ( ) => generateStatus ( false ) , status : 200 } ) ; // Snapshot outdated
184182 given ( fetchStub , 2 , { json : ( ) => JSON . parse ( dataJSON ) , status : 200 } ) ;
185183
186- //test
184+ // test
187185 Client . buildContext ( { url, apiKey, domain, component, environment } , {
188186 snapshotLocation : 'generated-snapshots/'
189187 } ) ;
190188
191189 await Client . loadSnapshot ( ) ;
192190 assert . isNotNull ( Client . snapshot ) ;
193191
194- //restore state to avoid process leakage
192+ // restore state to avoid process leakage
195193 Client . unloadSnapshot ( ) ;
196194 unlinkSync ( `generated-snapshots/${ environment } .json` ) ;
197195 } ) ;
@@ -234,28 +232,28 @@ describe('E2E test - Fail response - Snapshot:', function () {
234232 } ) ;
235233
236234 it ( 'should NOT update snapshot - Too many requests at checkSnapshotVersion' , async function ( ) {
237- //given
235+ // given
238236 fetchStub = stub ( FetchFacade , 'fetch' ) ;
239237
240238 given ( fetchStub , 0 , { json : ( ) => generateAuth ( '[auth_token]' , 5 ) , status : 200 } ) ;
241239 given ( fetchStub , 1 , { status : 429 } ) ;
242240
243- //test
241+ // test
244242 Client . testMode ( ) ;
245243 await Client . loadSnapshot ( ) ;
246244 await assertReject ( assert , Client . checkSnapshot ( ) ,
247245 'Something went wrong: [checkSnapshotVersion] failed with status 429' ) ;
248246 } ) ;
249247
250248 it ( 'should NOT update snapshot - Too many requests at resolveSnapshot' , async function ( ) {
251- //given
249+ // given
252250 fetchStub = stub ( FetchFacade , 'fetch' ) ;
253251
254252 given ( fetchStub , 0 , { json : ( ) => generateAuth ( '[auth_token]' , 5 ) , status : 200 } ) ;
255253 given ( fetchStub , 1 , { json : ( ) => generateStatus ( false ) , status : 200 } ) ; // Snapshot outdated
256254 given ( fetchStub , 2 , { status : 429 } ) ;
257255
258- //test
256+ // test
259257 Client . buildContext ( { url, apiKey, domain, component, environment } , {
260258 snapshotLocation : 'generated-snapshots/' ,
261259 regexSafe : false
@@ -299,7 +297,7 @@ describe('E2E test - Snapshot AutoUpdater:', function () {
299297 it ( 'should auto update snapshot every second' , async function ( ) {
300298 this . timeout ( 3000 ) ;
301299
302- //given
300+ // given
303301 fetchStub = stub ( FetchFacade , 'fetch' ) ;
304302
305303 given ( fetchStub , 0 , { json : ( ) => generateAuth ( '[auth_token]' , 5 ) , status : 200 } ) ;
@@ -308,7 +306,7 @@ describe('E2E test - Snapshot AutoUpdater:', function () {
308306 given ( fetchStub , 3 , { json : ( ) => generateStatus ( false ) , status : 200 } ) ; // Loading updated version
309307 given ( fetchStub , 4 , { json : ( ) => JSON . parse ( dataJSONV2 ) , status : 200 } ) ;
310308
311- //test
309+ // test
312310 Client . buildContext ( { url, apiKey, domain, component, environment } , {
313311 snapshotLocation : 'generated-snapshots/' ,
314312 local : true ,
@@ -336,12 +334,12 @@ describe('E2E test - Snapshot AutoUpdater:', function () {
336334 this . timeout ( 3000 ) ;
337335 fetchStub = stub ( FetchFacade , 'fetch' ) ;
338336
339- //given
337+ // given
340338 given ( fetchStub , 0 , { json : ( ) => generateAuth ( '[auth_token]' , 5 ) , status : 200 } ) ;
341339 given ( fetchStub , 1 , { json : ( ) => generateStatus ( false ) , status : 200 } ) ;
342340 given ( fetchStub , 2 , { json : ( ) => JSON . parse ( dataJSON ) , status : 200 } ) ;
343341
344- //test
342+ // test
345343 Client . buildContext ( { url, apiKey, domain, component, environment } , {
346344 local : true ,
347345 regexSafe : false
@@ -354,15 +352,15 @@ describe('E2E test - Snapshot AutoUpdater:', function () {
354352
355353 await Client . loadSnapshot ( { watchSnapshot : false , fetchRemote : true } ) ;
356354
357- //next call will fail
355+ // next call will fail
358356 givenError ( fetchStub , 3 , { errno : 'ECONNREFUSED' } ) ;
359357
360358 await sleep ( 1000 ) ;
361359
362360 assert . exists ( error ) ;
363361 assert . equal ( error . message , 'Something went wrong: Connection has been refused - ECONNREFUSED' ) ;
364362
365- //tearDown
363+ // tearDown
366364 Client . terminateSnapshotAutoUpdate ( ) ;
367365 } ) ;
368366
0 commit comments