Skip to content

Commit 13043b3

Browse files
committed
Clear cookies before analytics integration tests
1 parent 91e8469 commit 13043b3

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,23 @@ async function checkForEventCalls(retryCount = 0): Promise<PerformanceEntry[]> {
5050
if (callsWithEvent.length === 0) {
5151
return checkForEventCalls(retryCount + 1);
5252
} else {
53+
console.log("Events: ", JSON.stringify(callsWithEvent));
5354
return callsWithEvent;
5455
}
5556
}
5657

5758
describe('FirebaseAnalytics Integration Smoke Tests', () => {
5859
let app: FirebaseApp;
60+
61+
// Clear cookies to prevent persistence issues across tests when run in non-headless browsers.
62+
// This is required since gtag/logEvent behaviour is dependent on the session state; if an event has already been logged
63+
// in a session, the event will be sent in the request payload instead of the query string.
64+
beforeEach(() => {
65+
document.cookie.split(";").forEach((cookie) => {
66+
document.cookie = cookie.replace(/^ +/, "").replace(/=.*/, "=;expires=" + new Date().toUTCString() + ";path=/")
67+
});
68+
})
69+
5970
describe('Using getAnalytics()', () => {
6071
afterEach(() => deleteApp(app));
6172
it('logEvent() sends correct network request.', async () => {

0 commit comments

Comments
 (0)