File tree Expand file tree Collapse file tree 8 files changed +21
-37
lines changed Expand file tree Collapse file tree 8 files changed +21
-37
lines changed Original file line number Diff line number Diff line change @@ -35,7 +35,7 @@ const fakeDynamicConfig = stub(
35
35
} ) ;
36
36
37
37
// Fake indexedDB.open() request
38
- let fakeRequest = {
38
+ const fakeRequest = {
39
39
onsuccess : ( ) => { } ,
40
40
result : {
41
41
close : ( ) => { }
@@ -46,13 +46,7 @@ let idbOpenStub = stub();
46
46
// Stub indexedDB.open() because sinon's clock does not know
47
47
// how to wait for the real indexedDB callbacks to resolve.
48
48
function stubIdbOpen ( ) : void {
49
- ( fakeRequest = {
50
- onsuccess : ( ) => { } ,
51
- result : {
52
- close : ( ) => { }
53
- }
54
- } ) ,
55
- ( idbOpenStub = stub ( indexedDB , 'open' ) . returns ( fakeRequest as any ) ) ;
49
+ idbOpenStub = stub ( indexedDB , 'open' ) . returns ( fakeRequest as any ) ;
56
50
}
57
51
58
52
describe ( 'FirebaseAnalytics API tests' , ( ) => {
@@ -79,12 +73,6 @@ describe('FirebaseAnalytics API tests', () => {
79
73
fakeDynamicConfig . restore ( ) ;
80
74
} ) ;
81
75
82
- it ( 'initializeAnalytics() returns an Analytics instance' , async ( ) => {
83
- app = getFullApp ( fakeAppParams ) ;
84
- const analyticsInstance = initializeAnalytics ( app ) ;
85
- expect ( analyticsInstance . app ) . to . equal ( app ) ;
86
- await clock . runAllAsync ( ) ;
87
- } ) ;
88
76
it ( 'initializeAnalytics() with same (no) options returns same instance' , async ( ) => {
89
77
app = getFullApp ( fakeAppParams ) ;
90
78
const analyticsInstance = initializeAnalytics ( app ) ;
Original file line number Diff line number Diff line change @@ -99,12 +99,7 @@ export function initializeAnalytics(
99
99
) ;
100
100
if ( analyticsProvider . isInitialized ( ) ) {
101
101
const existingInstance = analyticsProvider . getImmediate ( ) ;
102
- if (
103
- deepEqual (
104
- options . config || { } ,
105
- ( analyticsProvider . getOptions ( ) as AnalyticsSettings ) ?. config || { }
106
- )
107
- ) {
102
+ if ( deepEqual ( options , analyticsProvider . getOptions ( ) ) ) {
108
103
return existingInstance ;
109
104
} else {
110
105
throw ERROR_FACTORY . create ( AnalyticsError . ALREADY_INITIALIZED ) ;
Original file line number Diff line number Diff line change @@ -36,7 +36,6 @@ const ERRORS: ErrorMap<AnalyticsError> = {
36
36
' already exists. ' +
37
37
'Only one Firebase Analytics instance can be created for each appId.' ,
38
38
[ AnalyticsError . ALREADY_INITIALIZED ] :
39
- 'Firebase Analytics has already been initialized with these options. ' +
40
39
'initializeAnalytics() cannot be called again with different options than those ' +
41
40
'it was initially called with. It can be called again with the same options to ' +
42
41
'return the existing instance, or getAnalytics() can be used ' +
Original file line number Diff line number Diff line change @@ -48,7 +48,7 @@ let clock: sinon.SinonFakeTimers;
48
48
let fakeInstallations : _FirebaseInstallationsInternal ;
49
49
50
50
// Fake indexedDB.open() request
51
- let fakeRequest = {
51
+ const fakeRequest = {
52
52
onsuccess : ( ) => { } ,
53
53
result : {
54
54
close : ( ) => { }
@@ -67,13 +67,7 @@ function stubFetch(status: number, body: object): void {
67
67
// Stub indexedDB.open() because sinon's clock does not know
68
68
// how to wait for the real indexedDB callbacks to resolve.
69
69
function stubIdbOpen ( ) : void {
70
- ( fakeRequest = {
71
- onsuccess : ( ) => { } ,
72
- result : {
73
- close : ( ) => { }
74
- }
75
- } ) ,
76
- ( idbOpenStub = stub ( indexedDB , 'open' ) . returns ( fakeRequest as any ) ) ;
70
+ idbOpenStub = stub ( indexedDB , 'open' ) . returns ( fakeRequest as any ) ;
77
71
}
78
72
79
73
describe ( 'FirebaseAnalytics instance tests' , ( ) => {
Original file line number Diff line number Diff line change @@ -43,7 +43,7 @@ declare global {
43
43
}
44
44
}
45
45
46
- export function registerAnalytics ( ) : void {
46
+ function registerAnalytics ( ) : void {
47
47
_registerComponent (
48
48
new Component (
49
49
ANALYTICS_TYPE ,
Original file line number Diff line number Diff line change @@ -22,7 +22,7 @@ import {
22
22
} from '@firebase/app-exp' ;
23
23
import { Component , ComponentType } from '@firebase/component' ;
24
24
import { _FirebaseInstallationsInternal } from '@firebase/installations-exp' ;
25
- import { registerAnalytics } from '../src' ;
25
+ import { AnalyticsService } from '../src/factory ' ;
26
26
27
27
const fakeConfig = {
28
28
projectId : 'projectId' ,
@@ -63,12 +63,20 @@ export function getFullApp(fakeAppParams?: {
63
63
apiKey ?: string ;
64
64
measurementId ?: string ;
65
65
} ) : FirebaseApp {
66
- registerAnalytics ( ) ;
67
66
_registerComponent (
68
67
new Component (
69
68
'installations-exp-internal' ,
70
69
( ) => {
71
- return getFakeInstallations ( ) ;
70
+ return { } as _FirebaseInstallationsInternal ;
71
+ } ,
72
+ ComponentType . PUBLIC
73
+ )
74
+ ) ;
75
+ _registerComponent (
76
+ new Component (
77
+ 'analytics-exp' ,
78
+ ( ) => {
79
+ return { } as AnalyticsService ;
72
80
} ,
73
81
ComponentType . PUBLIC
74
82
)
Original file line number Diff line number Diff line change @@ -33,8 +33,8 @@ const ERRORS: ErrorMap<AppCheckError> = {
33
33
[ AppCheckError . ALREADY_INITIALIZED ] :
34
34
'You have already called initializeAppCheck() for FirebaseApp {$appName} with ' +
35
35
'different options. To avoid this error, call initializeAppCheck() with the ' +
36
- 'same options as when it was originally called, or call getAppCheck() to return the' +
37
- ' already initialized instance.' ,
36
+ 'same options as when it was originally called. This will return the ' +
37
+ 'already initialized instance.' ,
38
38
[ AppCheckError . USE_BEFORE_ACTIVATION ] :
39
39
'App Check is being used before initializeAppCheck() is called for FirebaseApp {$appName}. ' +
40
40
'Call initializeAppCheck() before instantiating other Firebase services.' ,
Original file line number Diff line number Diff line change @@ -38,7 +38,7 @@ export class Provider<T extends Name> {
38
38
string ,
39
39
Deferred < NameServiceMapping [ T ] >
40
40
> = new Map ( ) ;
41
- private readonly instancesOptions : Map < string , InitializeOptions > = new Map ( ) ;
41
+ private readonly instancesOptions : Map < string , Record < string , unknown > > = new Map ( ) ;
42
42
private onInitCallbacks : Map < string , Set < OnInitCallBack < T > > > = new Map ( ) ;
43
43
44
44
constructor (
@@ -219,7 +219,7 @@ export class Provider<T extends Name> {
219
219
return this . instances . has ( identifier ) ;
220
220
}
221
221
222
- getOptions ( identifier : string = DEFAULT_ENTRY_NAME ) : InitializeOptions {
222
+ getOptions ( identifier : string = DEFAULT_ENTRY_NAME ) : Record < string , unknown > {
223
223
return this . instancesOptions . get ( identifier ) || { } ;
224
224
}
225
225
You can’t perform that action at this time.
0 commit comments