-
Notifications
You must be signed in to change notification settings - Fork 143
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
π·ββοΈ [RUM-7963] Add anonymous user id e2e test and cleanup #3268
Conversation
Codecov ReportAll modified and coverable lines are covered by tests β
Additional details and impacted files@@ Coverage Diff @@
## main #3268 +/- ##
==========================================
- Coverage 93.70% 93.68% -0.02%
==========================================
Files 290 290
Lines 7652 7654 +2
Branches 1745 1745
==========================================
+ Hits 7170 7171 +1
- Misses 482 483 +1 β View full report in Codecov by Sentry. |
await browser.execute(() => { | ||
window.DD_RUM!.addAction('foo') | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
β question: βnot sure to see why we need this?
@@ -10,7 +10,12 @@ export async function renewSession() { | |||
} | |||
|
|||
export async function expireSession() { | |||
await setCookie(SESSION_STORE_KEY, 'isExpired=1', SESSION_TIME_OUT_DELAY) | |||
// mock expire session with anonymous id | |||
const cookies = await browser.getCookies(SESSION_STORE_KEY) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
π¬ suggestion: βuse findSessionCookie
here
const prevSessionCookie = await findSessionCookie() | ||
const anonymousId = prevSessionCookie?.match(/aid=[a-z0-9-]+/) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
π¬ suggestion: βI think parsing the session cookie in findSessionCookie
could make tests easier to implement, with less regexes
Something as simple as
export async function findSessionCookie(): Record<string, string> | undefined {
const cookies = await browser.getCookies(SESSION_STORE_KEY)
// In some case, the session cookie is returned but with an empty value. Let's consider it expired
// in this case.
const rawValue = cookies[0]?.value
if (!rawValue) return
return Object.fromEntries(rawValue.split('&').map(part => part.split("=")))
}
Then in tests:
const anonymousId = (await findSessionCookie())?.aid
Same in unit tests, I think having a utility to quickly parse the cookie instead of relying on regexes would be better.
if (anonymousId) { | ||
expect(await findSessionCookie()).toContain(anonymousId[0]) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
π¬ suggestion: βFMU you have the if (anonymousId)
to make TS happy. I don't think we should have this condition:
- even if
anonymousId
should always be truthy (since we have the assertion above), it makes the test a bit confusing - you actually want to make the test fail if it was falsy, and not just silently skip the assertion
I think using !
is fine here
if (anonymousId) { | |
expect(await findSessionCookie()).toContain(anonymousId[0]) | |
} | |
expect(await findSessionCookie()).toContain(anonymousId![0]) |
Bundles Sizes Evolution
π CPU Performance
π§ Memory Performance
π RealWorld |
c1b513e
to
fb948a4
Compare
Motivation
Add e2e tests for anonymous user id and clean up existing tests to distinguish anonymous id from session id in cookies.
Changes
Added new e2e tests
Changed current tests matching regex
Testing
I have gone over the contributing documentation.