@@ -64,6 +64,7 @@ function mockServiceFactory(app: FirebaseApp): FirebaseServiceInterface {
64
64
65
65
describe ( 'FirebaseApp' , ( ) => {
66
66
let mockApp : FirebaseApp ;
67
+ let clock : sinon . SinonFakeTimers ;
67
68
let getTokenStub : sinon . SinonStub ;
68
69
let firebaseNamespace : FirebaseNamespace ;
69
70
let firebaseNamespaceInternals : FirebaseNamespaceInternals ;
@@ -75,7 +76,7 @@ describe('FirebaseApp', () => {
75
76
expires_in : 3600 ,
76
77
} ) ;
77
78
78
- this . clock = sinon . useFakeTimers ( 1000 ) ;
79
+ clock = sinon . useFakeTimers ( 1000 ) ;
79
80
80
81
mockApp = mocks . app ( ) ;
81
82
@@ -90,7 +91,7 @@ describe('FirebaseApp', () => {
90
91
91
92
afterEach ( ( ) => {
92
93
getTokenStub . restore ( ) ;
93
- this . clock . restore ( ) ;
94
+ clock . restore ( ) ;
94
95
if ( firebaseConfigVar ) {
95
96
process . env [ FIREBASE_CONFIG_VAR ] = firebaseConfigVar ;
96
97
} else {
@@ -675,7 +676,7 @@ describe('FirebaseApp', () => {
675
676
676
677
it ( 'returns the cached token given no arguments' , ( ) => {
677
678
return mockApp . INTERNAL . getToken ( true ) . then ( ( token1 ) => {
678
- this . clock . tick ( 1000 ) ;
679
+ clock . tick ( 1000 ) ;
679
680
return mockApp . INTERNAL . getToken ( ) . then ( ( token2 ) => {
680
681
expect ( token1 ) . to . deep . equal ( token2 ) ;
681
682
expect ( getTokenStub ) . to . have . been . calledOnce ;
@@ -685,7 +686,7 @@ describe('FirebaseApp', () => {
685
686
686
687
it ( 'returns a new token with force refresh' , ( ) => {
687
688
return mockApp . INTERNAL . getToken ( true ) . then ( ( token1 ) => {
688
- this . clock . tick ( 1000 ) ;
689
+ clock . tick ( 1000 ) ;
689
690
return mockApp . INTERNAL . getToken ( true ) . then ( ( token2 ) => {
690
691
expect ( token1 ) . to . not . deep . equal ( token2 ) ;
691
692
expect ( getTokenStub ) . to . have . been . calledTwice ;
@@ -698,15 +699,15 @@ describe('FirebaseApp', () => {
698
699
return mockApp . INTERNAL . getToken ( true ) . then ( ( token1 ) => {
699
700
// Forward the clock to five minutes and one second before expiry.
700
701
const expiryInMilliseconds = token1 . expirationTime - Date . now ( ) ;
701
- this . clock . tick ( expiryInMilliseconds - ( 5 * ONE_MINUTE_IN_MILLISECONDS ) - 1000 ) ;
702
+ clock . tick ( expiryInMilliseconds - ( 5 * ONE_MINUTE_IN_MILLISECONDS ) - 1000 ) ;
702
703
703
704
return mockApp . INTERNAL . getToken ( ) . then ( ( token2 ) => {
704
705
// Ensure the token has not been proactively refreshed.
705
706
expect ( token1 ) . to . deep . equal ( token2 ) ;
706
707
expect ( getTokenStub ) . to . have . been . calledOnce ;
707
708
708
709
// Forward the clock to exactly five minutes before expiry.
709
- this . clock . tick ( 1000 ) ;
710
+ clock . tick ( 1000 ) ;
710
711
711
712
return mockApp . INTERNAL . getToken ( ) . then ( ( token3 ) => {
712
713
// Ensure the token was proactively refreshed.
@@ -727,10 +728,10 @@ describe('FirebaseApp', () => {
727
728
728
729
// Forward the clock to exactly five minutes before expiry.
729
730
const expiryInMilliseconds = token1 . expirationTime - Date . now ( ) ;
730
- this . clock . tick ( expiryInMilliseconds - ( 5 * ONE_MINUTE_IN_MILLISECONDS ) ) ;
731
+ clock . tick ( expiryInMilliseconds - ( 5 * ONE_MINUTE_IN_MILLISECONDS ) ) ;
731
732
732
733
// Forward the clock to exactly four minutes before expiry.
733
- this . clock . tick ( 60 * 1000 ) ;
734
+ clock . tick ( 60 * 1000 ) ;
734
735
735
736
// Restore the stubbed getAccessToken() method.
736
737
getTokenStub . restore ( ) ;
@@ -745,7 +746,7 @@ describe('FirebaseApp', () => {
745
746
expect ( getTokenStub ) . to . have . not . been . called ;
746
747
747
748
// Forward the clock to exactly three minutes before expiry.
748
- this . clock . tick ( 60 * 1000 ) ;
749
+ clock . tick ( 60 * 1000 ) ;
749
750
750
751
return mockApp . INTERNAL . getToken ( ) . then ( ( token3 ) => {
751
752
// Ensure the token was proactively refreshed.
@@ -772,7 +773,7 @@ describe('FirebaseApp', () => {
772
773
773
774
// Forward the clock to exactly five minutes before expiry.
774
775
const expiryInMilliseconds = token . expirationTime - Date . now ( ) ;
775
- this . clock . tick ( expiryInMilliseconds - ( 5 * ONE_MINUTE_IN_MILLISECONDS ) ) ;
776
+ clock . tick ( expiryInMilliseconds - ( 5 * ONE_MINUTE_IN_MILLISECONDS ) ) ;
776
777
777
778
// Due to synchronous timing issues when the timer is mocked, make a call to getToken()
778
779
// without forcing a refresh to ensure there is enough time for the underlying token refresh
@@ -786,7 +787,7 @@ describe('FirebaseApp', () => {
786
787
expect ( token ) . to . deep . equal ( originalToken ) ;
787
788
788
789
// Forward the clock to four minutes before expiry.
789
- this . clock . tick ( ONE_MINUTE_IN_MILLISECONDS ) ;
790
+ clock . tick ( ONE_MINUTE_IN_MILLISECONDS ) ;
790
791
791
792
// See note above about calling getToken().
792
793
return mockApp . INTERNAL . getToken ( ) ;
@@ -798,7 +799,7 @@ describe('FirebaseApp', () => {
798
799
expect ( token ) . to . deep . equal ( originalToken ) ;
799
800
800
801
// Forward the clock to three minutes before expiry.
801
- this . clock . tick ( ONE_MINUTE_IN_MILLISECONDS ) ;
802
+ clock . tick ( ONE_MINUTE_IN_MILLISECONDS ) ;
802
803
803
804
// See note above about calling getToken().
804
805
return mockApp . INTERNAL . getToken ( ) ;
@@ -810,7 +811,7 @@ describe('FirebaseApp', () => {
810
811
expect ( token ) . to . deep . equal ( originalToken ) ;
811
812
812
813
// Forward the clock to two minutes before expiry.
813
- this . clock . tick ( ONE_MINUTE_IN_MILLISECONDS ) ;
814
+ clock . tick ( ONE_MINUTE_IN_MILLISECONDS ) ;
814
815
815
816
// See note above about calling getToken().
816
817
return mockApp . INTERNAL . getToken ( ) ;
@@ -822,7 +823,7 @@ describe('FirebaseApp', () => {
822
823
expect ( token ) . to . deep . equal ( originalToken ) ;
823
824
824
825
// Forward the clock to one minute before expiry.
825
- this . clock . tick ( ONE_MINUTE_IN_MILLISECONDS ) ;
826
+ clock . tick ( ONE_MINUTE_IN_MILLISECONDS ) ;
826
827
827
828
// See note above about calling getToken().
828
829
return mockApp . INTERNAL . getToken ( ) ;
@@ -834,7 +835,7 @@ describe('FirebaseApp', () => {
834
835
expect ( token ) . to . deep . equal ( originalToken ) ;
835
836
836
837
// Forward the clock to expiry.
837
- this . clock . tick ( ONE_MINUTE_IN_MILLISECONDS ) ;
838
+ clock . tick ( ONE_MINUTE_IN_MILLISECONDS ) ;
838
839
839
840
// See note above about calling getToken().
840
841
return mockApp . INTERNAL . getToken ( ) ;
@@ -852,7 +853,7 @@ describe('FirebaseApp', () => {
852
853
return mockApp . INTERNAL . getToken ( true ) . then ( ( token1 ) => {
853
854
// Forward the clock to five minutes and one second before expiry.
854
855
let expiryInMilliseconds = token1 . expirationTime - Date . now ( ) ;
855
- this . clock . tick ( expiryInMilliseconds - ( 5 * ONE_MINUTE_IN_MILLISECONDS ) - 1000 ) ;
856
+ clock . tick ( expiryInMilliseconds - ( 5 * ONE_MINUTE_IN_MILLISECONDS ) - 1000 ) ;
856
857
857
858
// Force a token refresh.
858
859
return mockApp . INTERNAL . getToken ( true ) . then ( ( token2 ) => {
@@ -861,7 +862,7 @@ describe('FirebaseApp', () => {
861
862
expect ( getTokenStub ) . to . have . been . calledTwice ;
862
863
863
864
// Forward the clock to exactly five minutes before the original token's expiry.
864
- this . clock . tick ( 1000 ) ;
865
+ clock . tick ( 1000 ) ;
865
866
866
867
return mockApp . INTERNAL . getToken ( ) . then ( ( token3 ) => {
867
868
// Ensure the token hasn't changed, meaning the proactive refresh was canceled.
@@ -870,7 +871,7 @@ describe('FirebaseApp', () => {
870
871
871
872
// Forward the clock to exactly five minutes before the refreshed token's expiry.
872
873
expiryInMilliseconds = token3 . expirationTime - Date . now ( ) ;
873
- this . clock . tick ( expiryInMilliseconds - ( 5 * ONE_MINUTE_IN_MILLISECONDS ) ) ;
874
+ clock . tick ( expiryInMilliseconds - ( 5 * ONE_MINUTE_IN_MILLISECONDS ) ) ;
874
875
875
876
return mockApp . INTERNAL . getToken ( ) . then ( ( token4 ) => {
876
877
// Ensure the token was proactively refreshed.
@@ -896,11 +897,11 @@ describe('FirebaseApp', () => {
896
897
return mockApp . INTERNAL . getToken ( true ) . then ( ( token1 ) => {
897
898
898
899
// Move the clock forward to three minutes and one second before expiry.
899
- this . clock . tick ( 9 * 1000 ) ;
900
+ clock . tick ( 9 * 1000 ) ;
900
901
expect ( getTokenStub . callCount ) . to . equal ( 1 ) ;
901
902
902
903
// Move the clock forward to exactly three minutes before expiry.
903
- this . clock . tick ( 1000 ) ;
904
+ clock . tick ( 1000 ) ;
904
905
905
906
// Expect the underlying getAccessToken() method to have been called once.
906
907
expect ( getTokenStub . callCount ) . to . equal ( 2 ) ;
@@ -974,7 +975,7 @@ describe('FirebaseApp', () => {
974
975
return mockApp . INTERNAL . getToken ( ) . then ( ( token : FirebaseAccessToken ) => {
975
976
expect ( addAuthTokenListenerSpy ) . to . have . been . calledOnce . and . calledWith ( token . accessToken ) ;
976
977
977
- this . clock . tick ( 1000 ) ;
978
+ clock . tick ( 1000 ) ;
978
979
979
980
return mockApp . INTERNAL . getToken ( true ) ;
980
981
} ) . then ( ( token : FirebaseAccessToken ) => {
@@ -1016,7 +1017,7 @@ describe('FirebaseApp', () => {
1016
1017
1017
1018
mockApp . INTERNAL . removeAuthTokenListener ( addAuthTokenListenerSpies [ 0 ] ) ;
1018
1019
1019
- this . clock . tick ( 1000 ) ;
1020
+ clock . tick ( 1000 ) ;
1020
1021
1021
1022
return mockApp . INTERNAL . getToken ( true ) ;
1022
1023
} ) . then ( ( token : FirebaseAccessToken ) => {
0 commit comments