Skip to content

Try to fix flaky analytics test #3612

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 4 commits into from
Aug 19, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 6 additions & 15 deletions packages/analytics/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,9 @@ describe('FirebaseAnalytics instance tests', () => {
analyticsInstance.logEvent(EventName.ADD_PAYMENT_INFO, {
currency: 'USD'
});
// Clear event stack of async FID call.
// For IE: Need then() or else "expect" runs immediately on FID resolve
// before the other statements in initializeGAId.
await fidDeferred.promise.then();
// Clear event stack of initialization promise.
const { initializedIdPromisesMap } = getGlobalVars();
await Promise.all(Object.values(initializedIdPromisesMap));
expect(gtagStub).to.have.been.calledWith('js');
expect(gtagStub).to.have.been.calledWith(
GtagCommand.CONFIG,
Expand All @@ -101,10 +100,6 @@ describe('FirebaseAnalytics instance tests', () => {
update: true
}
);
// Clear event stack of initialization promise.
const { initializedIdPromisesMap } = getGlobalVars();
await Promise.all(Object.values(initializedIdPromisesMap));
// await Promise.resolve().then(() => {});
expect(gtagStub).to.have.been.calledWith(
GtagCommand.EVENT,
EventName.ADD_PAYMENT_INFO,
Expand Down Expand Up @@ -159,10 +154,9 @@ describe('FirebaseAnalytics instance tests', () => {
analyticsInstance.logEvent(EventName.ADD_PAYMENT_INFO, {
currency: 'USD'
});
// Clear event stack of async FID call.
// For IE: Need then() or else "expect" runs immediately on FID resolve
// before the other statements in initializeGAId.
await fidDeferred.promise.then();
// Clear event stack of initialization promise.
const { initializedIdPromisesMap } = getGlobalVars();
await Promise.all(Object.values(initializedIdPromisesMap));
expect(gtagStub).to.have.been.calledWith('js');
expect(gtagStub).to.have.been.calledWith(
GtagCommand.CONFIG,
Expand All @@ -173,9 +167,6 @@ describe('FirebaseAnalytics instance tests', () => {
update: true
}
);
// Clear event stack of initialization promise.
const { initializedIdPromisesMap } = getGlobalVars();
await Promise.all(Object.values(initializedIdPromisesMap));
expect(gtagStub).to.have.been.calledWith(
GtagCommand.EVENT,
EventName.ADD_PAYMENT_INFO,
Expand Down