@@ -983,8 +983,9 @@ describe('resetToPackagedBundle', () => {
983983 sharedState . marked = true ;
984984 const client = new Pushy ( { appKey : 'demo-app' } ) ;
985985
986- await client . resetToPackagedBundle ( ) ;
986+ const result = await client . resetToPackagedBundle ( ) ;
987987
988+ expect ( result ) . toBe ( true ) ;
988989 expect ( resetToPackagedBundle ) . toHaveBeenCalledTimes ( 1 ) ;
989990 expect ( sharedState . downloadedHash ) . toBeUndefined ( ) ;
990991 expect ( sharedState . marked ) . toBe ( false ) ;
@@ -1005,30 +1006,48 @@ describe('resetToPackagedBundle', () => {
10051006 expect ( restartApp ) . toHaveBeenCalledTimes ( 1 ) ;
10061007 } ) ;
10071008
1008- test ( 'throws RESET_FAILED when the native module lacks the method' , async ( ) => {
1009- // Simulates new JS arriving via hot update onto an older binary.
1009+ test ( 'resolves false with RESET_FAILED via onError when the native module lacks the method' , async ( ) => {
1010+ // Simulates new JS arriving via hot update onto an older binary. Like the
1011+ // other update-flow APIs this must not throw by default.
10101012 setupClientMocks ( { resetToPackagedBundle : null } ) ;
10111013 const { Pushy } = await importFreshClient ( 'reset-unsupported' ) ;
10121014 const client = new Pushy ( { appKey : 'demo-app' } ) ;
1015+ const seen : any [ ] = [ ] ;
1016+ client . onError ( ( err : any ) => seen . push ( err ) ) ;
1017+
1018+ const result = await client . resetToPackagedBundle ( ) ;
1019+
1020+ expect ( result ) . toBe ( false ) ;
1021+ expect ( seen ) . toHaveLength ( 1 ) ;
1022+ expect ( seen [ 0 ] . code ) . toBe ( 'RESET_FAILED' ) ;
1023+ } ) ;
1024+
1025+ test ( 'throwError option makes an unsupported reset throw' , async ( ) => {
1026+ setupClientMocks ( { resetToPackagedBundle : null } ) ;
1027+ const { Pushy } = await importFreshClient ( 'reset-unsupported-throw' ) ;
1028+ const client = new Pushy ( { appKey : 'demo-app' , throwError : true } ) ;
10131029
10141030 await expect ( client . resetToPackagedBundle ( ) ) . rejects . toMatchObject ( {
10151031 code : 'RESET_FAILED' ,
10161032 } ) ;
10171033 } ) ;
10181034
1019- test ( 'propagates native failures with the RESET_FAILED code and keeps state' , async ( ) => {
1035+ test ( 'resolves false on native failure and keeps state' , async ( ) => {
10201036 const resetToPackagedBundle = mock ( ( ) =>
10211037 Promise . reject ( Error ( 'disk full' ) ) ,
10221038 ) ;
10231039 setupClientMocks ( { resetToPackagedBundle } ) ;
10241040 const { Pushy, sharedState } = await importFreshClient ( 'reset-native-fail' ) ;
10251041 sharedState . downloadedHash = 'stale-hash' ;
10261042 const client = new Pushy ( { appKey : 'demo-app' } ) ;
1043+ const seen : any [ ] = [ ] ;
1044+ client . onError ( ( err : any ) => seen . push ( err ) ) ;
10271045
1028- await expect ( client . resetToPackagedBundle ( ) ) . rejects . toMatchObject ( {
1029- code : 'RESET_FAILED' ,
1030- message : 'disk full' ,
1031- } ) ;
1046+ const result = await client . resetToPackagedBundle ( ) ;
1047+
1048+ expect ( result ) . toBe ( false ) ;
1049+ expect ( seen [ 0 ] . code ) . toBe ( 'RESET_FAILED' ) ;
1050+ expect ( seen [ 0 ] . message ) . toBe ( 'disk full' ) ;
10321051 // The native reset did not happen, so the bookkeeping must not be wiped.
10331052 expect ( sharedState . downloadedHash ) . toBe ( 'stale-hash' ) ;
10341053 } ) ;
0 commit comments