-
Notifications
You must be signed in to change notification settings - Fork 976
React error collection support #9269
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 5 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
af297a6
WIP react support
andrewbrook 894e970
WIP react support with sub-package
andrewbrook fcad227
Fix package structure; capture client errors
andrewbrook 391c2e8
Implement and test FirebaseTelemetry component
andrewbrook 6dace8a
docgen
andrewbrook f834a96
Refactor to use React component function
andrewbrook a3583c9
Fixed API extraction for subpath
andrewbrook 08d4de9
Format
andrewbrook 2067d79
Fix declaration file
andrewbrook d40fa1c
Fix public typings
andrewbrook 157cf6b
Fix public typings
andrewbrook 04b7f7f
Fix public typings
andrewbrook File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"extends": "../../config/api-extractor.json", | ||
"mainEntryPointFilePath": "<projectFolder>/dist/react/src/react/index.d.ts", | ||
"dtsRollup": { | ||
"enabled": true, | ||
"untrimmedFilePath": "<projectFolder>/dist/react/index.d.ts" | ||
}, | ||
"apiReport": { | ||
"enabled": false | ||
}, | ||
"docModel": { | ||
"enabled": false | ||
}, | ||
"tsdocMetadata": { | ||
"enabled": false | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
/** | ||
* @license | ||
* Copyright 2025 Google LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
import { expect, use } from 'chai'; | ||
import sinonChai from 'sinon-chai'; | ||
import chaiAsPromised from 'chai-as-promised'; | ||
import { restore, stub } from 'sinon'; | ||
import * as app from '@firebase/app'; | ||
import * as telemetry from '../api'; | ||
import { FirebaseApp } from '@firebase/app'; | ||
import { Telemetry } from '../public-types'; | ||
import { FirebaseTelemetry } from '.'; | ||
import React from 'react'; | ||
import { render } from '@testing-library/react'; | ||
|
||
use(sinonChai); | ||
use(chaiAsPromised); | ||
|
||
describe('FirebaseTelemetry', () => { | ||
let getTelemetryStub: sinon.SinonStub; | ||
let captureErrorStub: sinon.SinonStub; | ||
let initializeAppStub: sinon.SinonStub; | ||
let fakeApp: FirebaseApp; | ||
let fakeTelemetry: Telemetry; | ||
|
||
beforeEach(() => { | ||
fakeApp = { name: 'fakeApp' } as FirebaseApp; | ||
fakeTelemetry = {} as Telemetry; | ||
|
||
initializeAppStub = stub(app, 'initializeApp').returns(fakeApp); | ||
getTelemetryStub = stub(telemetry, 'getTelemetry').returns(fakeTelemetry); | ||
captureErrorStub = stub(telemetry, 'captureError'); | ||
}); | ||
|
||
afterEach(() => { | ||
restore(); | ||
}); | ||
|
||
it('gets telemetry with the default app if no firebaseOptions are provided', () => { | ||
render(<FirebaseTelemetry />); | ||
expect(getTelemetryStub).to.have.been.called; | ||
expect(initializeAppStub).not.to.have.been.called; | ||
}); | ||
|
||
it('initializes a new app and gets telemetry if firebaseOptions are provided', () => { | ||
const firebaseOptions = { apiKey: 'test' }; | ||
render(<FirebaseTelemetry firebaseOptions={firebaseOptions} />); | ||
expect(initializeAppStub).to.have.been.calledWith(firebaseOptions); | ||
expect(getTelemetryStub).to.have.been.calledWith(fakeApp); | ||
}); | ||
|
||
it('captures window errors', done => { | ||
render(<FirebaseTelemetry />); | ||
const error = new Error('test error'); | ||
window.onerror = () => { | ||
// Prevent error from bubbling up to test suite | ||
}; | ||
window.addEventListener('error', (event: ErrorEvent) => { | ||
// Registers another listener (sequential) to confirm behaviour. | ||
expect(captureErrorStub).to.have.been.calledWith(fakeTelemetry, error); | ||
done(); | ||
}); | ||
window.dispatchEvent(new ErrorEvent('error', { error })); | ||
}); | ||
|
||
it('captures unhandled promise rejections', () => { | ||
render(<FirebaseTelemetry />); | ||
const reason = new Error('test rejection'); | ||
const promise = Promise.reject(reason); | ||
promise.catch(() => {}); | ||
window.dispatchEvent( | ||
new PromiseRejectionEvent('unhandledrejection', { reason, promise }) | ||
); | ||
expect(captureErrorStub).to.have.been.calledWith(fakeTelemetry, reason); | ||
}); | ||
|
||
it('renders children', () => { | ||
const { getByText } = render( | ||
<FirebaseTelemetry> | ||
<span>here are my children</span> | ||
</FirebaseTelemetry> | ||
); | ||
expect(getByText('here are my children')).to.exist; | ||
}); | ||
|
||
it('fails silently when getTelemetry fails', () => { | ||
const error = new Error('getTelemetry failed'); | ||
getTelemetryStub.throws(error); | ||
const consoleWarnStub = stub(console, 'warn'); | ||
|
||
expect(() => render(<FirebaseTelemetry />)).not.to.throw(); | ||
expect(consoleWarnStub).to.have.been.calledWith( | ||
'Firebase Telemetry was not initialized:\n', | ||
error | ||
); | ||
}); | ||
}); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.