@@ -25,7 +25,17 @@ import {
2525 SimpleSpanProcessor ,
2626 WebTracerProvider
2727} from '@opentelemetry/sdk-trace-web' ;
28- import { captureError , flush } from './api' ;
28+ import {
29+ FirebaseApp ,
30+ initializeApp ,
31+ _registerComponent ,
32+ _addOrOverwriteComponent
33+ } from '@firebase/app' ;
34+ import { Component , ComponentType } from '@firebase/component' ;
35+ import { FirebaseAppCheckInternal } from '@firebase/app-check-interop-types' ;
36+ import { captureError , flush , getTelemetry } from './api' ;
37+ import { TelemetryService } from './service' ;
38+ import { registerTelemetry } from './register' ;
2939
3040const PROJECT_ID = 'my-project' ;
3141const APP_ID = 'my-appid' ;
@@ -65,6 +75,33 @@ describe('Top level API', () => {
6575 emittedLogs . length = 0 ;
6676 } ) ;
6777
78+ describe ( 'getTelemetry()' , ( ) => {
79+ it ( 'works without options' , ( ) => {
80+ expect ( getTelemetry ( getFakeApp ( ) ) ) . to . be . instanceOf ( TelemetryService ) ;
81+ // Two instances are the same
82+ expect ( getTelemetry ( getFakeApp ( ) ) ) . to . equal ( getTelemetry ( getFakeApp ( ) ) ) ;
83+ } ) ;
84+
85+ it ( 'works with options: no endpointUrl' , ( ) => {
86+ expect ( getTelemetry ( getFakeApp ( ) , { } ) ) . to . equal (
87+ getTelemetry ( getFakeApp ( ) )
88+ ) ;
89+ } ) ;
90+
91+ it ( 'works with options: endpointUrl set' , ( ) => {
92+ const app = getFakeApp ( ) ;
93+ expect ( getTelemetry ( app , { endpointUrl : 'http://endpoint1' } ) ) . to . equal (
94+ getTelemetry ( app , { endpointUrl : 'http://endpoint1' } )
95+ ) ;
96+ expect (
97+ getTelemetry ( app , { endpointUrl : 'http://endpoint1' } )
98+ ) . not . to . equal ( getTelemetry ( app , { endpointUrl : 'http://endpoint2' } ) ) ;
99+ expect (
100+ getTelemetry ( app , { endpointUrl : 'http://endpoint1' } )
101+ ) . not . to . equal ( getTelemetry ( app , { } ) ) ;
102+ } ) ;
103+ } ) ;
104+
68105 describe ( 'captureError()' , ( ) => {
69106 it ( 'should capture an Error object correctly' , ( ) => {
70107 const error = new Error ( 'This is a test error' ) ;
@@ -189,3 +226,32 @@ describe('Top level API', () => {
189226 } ) ;
190227 } ) ;
191228} ) ;
229+
230+ function getFakeApp ( ) : FirebaseApp {
231+ registerTelemetry ( ) ;
232+ _registerComponent (
233+ new Component (
234+ 'app-check-internal' ,
235+ ( ) => {
236+ return { } as FirebaseAppCheckInternal ;
237+ } ,
238+ ComponentType . PUBLIC
239+ )
240+ ) ;
241+ const app = initializeApp ( { } ) ;
242+ _addOrOverwriteComponent (
243+ app ,
244+ //@ts -ignore
245+ new Component (
246+ 'heartbeat' ,
247+ // @ts -ignore
248+ ( ) => {
249+ return {
250+ triggerHeartbeat : ( ) => { }
251+ } ;
252+ } ,
253+ ComponentType . PUBLIC
254+ )
255+ ) ;
256+ return app ;
257+ }
0 commit comments