-
Notifications
You must be signed in to change notification settings - Fork 940
Make initialize methods for each product idempotent #5272
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 7 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
2b9d984
Set up provider and add Analytics
hsubox76 122c9ef
Add app check
hsubox76 e5d4b53
Fix app check
hsubox76 65d2407
Fix app check
hsubox76 55df388
Update API reports
hsubox76 a98ed5b
Add changeset for component
hsubox76 3871f26
Merge branch 'ch-idempotent' of https://github.com/firebase/firebase-…
hsubox76 b295a78
Address PR comments
hsubox76 62b7def
prettier
hsubox76 e74ba6e
API change
hsubox76 6dfbed1
Fix link comment
hsubox76 d46d84b
Fix typing issue
hsubox76 12c7eed
Make initializePerformance() idempotent (#5278)
hsubox76 b12abae
Make initializeFirestore() idempotent (#5280)
hsubox76 01b3d37
Stub init function
hsubox76 893febd
prettier
hsubox76 7cba1e6
Rename internal initializeAnalytics
hsubox76 9c4aca6
Make initializeAuth() idempotent (#5279)
hsubox76 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@firebase/component': patch | ||
--- | ||
|
||
Store instance initialization options on the Provider. |
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,135 @@ | ||
/** | ||
* @license | ||
* Copyright 2019 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 } from 'chai'; | ||
import { SinonFakeTimers, stub, useFakeTimers } from 'sinon'; | ||
import '../testing/setup'; | ||
import { getFullApp } from '../testing/get-fake-firebase-services'; | ||
import { getAnalytics, initializeAnalytics } from './api'; | ||
import { FirebaseApp, deleteApp } from '@firebase/app-exp'; | ||
import { AnalyticsError } from './errors'; | ||
import { removeGtagScript } from '../testing/gtag-script-util'; | ||
import * as getConfig from './get-config'; | ||
const fakeAppParams = { appId: 'abcdefgh12345:23405', apiKey: 'AAbbCCdd12345' }; | ||
|
||
const fakeDynamicConfig = stub( | ||
getConfig, | ||
'fetchDynamicConfigWithRetry' | ||
).resolves({ | ||
appId: 'FAKE_APP_ID', | ||
measurementId: 'FAKE_MEASUREMENT_ID' | ||
}); | ||
|
||
// Fake indexedDB.open() request | ||
let fakeRequest = { | ||
onsuccess: () => {}, | ||
result: { | ||
close: () => {} | ||
} | ||
}; | ||
let idbOpenStub = stub(); | ||
|
||
// Stub indexedDB.open() because sinon's clock does not know | ||
// how to wait for the real indexedDB callbacks to resolve. | ||
function stubIdbOpen(): void { | ||
(fakeRequest = { | ||
onsuccess: () => {}, | ||
result: { | ||
close: () => {} | ||
} | ||
}), | ||
(idbOpenStub = stub(indexedDB, 'open').returns(fakeRequest as any)); | ||
hsubox76 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
describe('FirebaseAnalytics API tests', () => { | ||
let app: FirebaseApp; | ||
let clock: SinonFakeTimers; | ||
|
||
beforeEach(() => { | ||
stubIdbOpen(); | ||
clock = useFakeTimers(); | ||
}); | ||
|
||
afterEach(async () => { | ||
clock.restore(); | ||
idbOpenStub.restore(); | ||
removeGtagScript(); | ||
if (app) { | ||
return deleteApp(app); | ||
} | ||
}); | ||
|
||
after(() => { | ||
delete window['gtag']; | ||
delete window['dataLayer']; | ||
fakeDynamicConfig.restore(); | ||
}); | ||
|
||
it('initializeAnalytics() returns an Analytics instance', async () => { | ||
app = getFullApp(fakeAppParams); | ||
const analyticsInstance = initializeAnalytics(app); | ||
expect(analyticsInstance.app).to.equal(app); | ||
await clock.runAllAsync(); | ||
Feiyang1 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}); | ||
it('initializeAnalytics() with same (no) options returns same instance', async () => { | ||
app = getFullApp(fakeAppParams); | ||
const analyticsInstance = initializeAnalytics(app); | ||
const newInstance = initializeAnalytics(app); | ||
expect(analyticsInstance).to.equal(newInstance); | ||
await clock.runAllAsync(); | ||
}); | ||
it('initializeAnalytics() with same options returns same instance', () => { | ||
app = getFullApp(fakeAppParams); | ||
const analyticsInstance = initializeAnalytics(app, { | ||
config: { 'send_page_view': false } | ||
}); | ||
const newInstance = initializeAnalytics(app, { | ||
config: { 'send_page_view': false } | ||
}); | ||
expect(analyticsInstance).to.equal(newInstance); | ||
}); | ||
it('initializeAnalytics() with different options throws', () => { | ||
app = getFullApp(fakeAppParams); | ||
initializeAnalytics(app, { | ||
config: { 'send_page_view': false } | ||
}); | ||
expect(() => | ||
initializeAnalytics(app, { | ||
config: { 'send_page_view': true } | ||
}) | ||
).to.throw(AnalyticsError.ALREADY_INITIALIZED); | ||
}); | ||
it('initializeAnalytics() with different options (one undefined) throws', () => { | ||
app = getFullApp(fakeAppParams); | ||
initializeAnalytics(app); | ||
expect(() => | ||
initializeAnalytics(app, { | ||
config: { 'send_page_view': true } | ||
}) | ||
).to.throw(AnalyticsError.ALREADY_INITIALIZED); | ||
}); | ||
it('getAnalytics() returns same instance created by previous getAnalytics()', () => { | ||
app = getFullApp(fakeAppParams); | ||
const analyticsInstance = getAnalytics(app); | ||
expect(getAnalytics(app)).to.equal(analyticsInstance); | ||
}); | ||
it('getAnalytics() returns same instance created by initializeAnalytics()', () => { | ||
app = getFullApp(fakeAppParams); | ||
const analyticsInstance = initializeAnalytics(app); | ||
expect(getAnalytics(app)).to.equal(analyticsInstance); | ||
}); | ||
}); |
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
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
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.