Skip to content

Commit aa563ba

Browse files
committed
Fix test
1 parent d7846c1 commit aa563ba

File tree

2 files changed

+25
-32
lines changed

2 files changed

+25
-32
lines changed

packages-exp/analytics-exp/src/public-types.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ export interface AnalyticsCallOptions {
128128
*/
129129
export interface Analytics {
130130
/**
131-
* The FirebaseApp this Functions instance is associated with.
131+
* The FirebaseApp this Analytics instance is associated with.
132132
*/
133133
app: FirebaseApp;
134134
}

packages-exp/analytics-exp/testing/integration-tests/integration.ts

+24-31
Original file line numberDiff line numberDiff line change
@@ -34,30 +34,37 @@ try {
3434
}
3535

3636
const RETRY_INTERVAL = 1000;
37+
const TIMEOUT_MILLIS = 20000;
38+
39+
async function checkForEventCalls(retryCount = 0): Promise<PerformanceEntry[]> {
40+
if (retryCount > TIMEOUT_MILLIS / RETRY_INTERVAL) {
41+
return Promise.resolve([]);
42+
}
43+
await new Promise(resolve => setTimeout(resolve, RETRY_INTERVAL));
44+
const resources = performance.getEntriesByType('resource');
45+
performance.clearResourceTimings();
46+
const callsWithEvent = resources.filter(
47+
resource =>
48+
resource.name.includes('google-analytics.com') &&
49+
resource.name.includes('en=login')
50+
);
51+
if (callsWithEvent.length === 0) {
52+
return checkForEventCalls(retryCount + 1);
53+
} else {
54+
return callsWithEvent;
55+
}
56+
}
3757

3858
describe('FirebaseAnalytics Integration Smoke Tests', () => {
3959
let app: FirebaseApp;
4060
describe('Using getAnalytics()', () => {
4161
afterEach(() => deleteApp(app));
4262
it('logEvent() sends correct network request.', async () => {
4363
app = initializeApp(config);
44-
logEvent(getAnalytics(app), 'login', { method: 'email' });
45-
async function checkForEventCalls(): Promise<number> {
46-
await new Promise(resolve => setTimeout(resolve, RETRY_INTERVAL));
47-
const resources = performance.getEntriesByType('resource');
48-
const callsWithEvent = resources.filter(
49-
resource =>
50-
resource.name.includes('google-analytics.com') &&
51-
resource.name.includes('en=login')
52-
);
53-
if (callsWithEvent.length === 0) {
54-
return checkForEventCalls();
55-
} else {
56-
return callsWithEvent.length;
57-
}
58-
}
59-
const eventCallCount = await checkForEventCalls();
60-
expect(eventCallCount).to.equal(1);
64+
logEvent(getAnalytics(app), 'login', { method: 'phone' });
65+
const eventCalls = await checkForEventCalls();
66+
expect(eventCalls.length).to.equal(1);
67+
expect(eventCalls[0].name).to.include('method=phone');
6168
});
6269
it("Warns if measurement ID doesn't match.", done => {
6370
const warnStub = stub(console, 'warn').callsFake(() => {
@@ -75,20 +82,6 @@ describe('FirebaseAnalytics Integration Smoke Tests', () => {
7582
it('logEvent() sends correct network request.', async () => {
7683
app = initializeApp(config);
7784
logEvent(initializeAnalytics(app), 'login', { method: 'email' });
78-
async function checkForEventCalls(): Promise<PerformanceEntry[]> {
79-
await new Promise(resolve => setTimeout(resolve, RETRY_INTERVAL));
80-
const resources = performance.getEntriesByType('resource');
81-
const callsWithEvent = resources.filter(
82-
resource =>
83-
resource.name.includes('google-analytics.com') &&
84-
resource.name.includes('en=login')
85-
);
86-
if (callsWithEvent.length === 0) {
87-
return checkForEventCalls();
88-
} else {
89-
return callsWithEvent;
90-
}
91-
}
9285
const eventCalls = await checkForEventCalls();
9386
expect(eventCalls.length).to.equal(1);
9487
expect(eventCalls[0].name).to.include('method=email');

0 commit comments

Comments
 (0)