Skip to content
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

Merged
merged 4 commits into from
Jan 24, 2025

Conversation

cy-moi
Copy link
Contributor

@cy-moi cy-moi commented Jan 8, 2025

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

  • Local
  • Staging
  • Unit
  • End to end

I have gone over the contributing documentation.

@cy-moi cy-moi changed the title Congyao/rum 7963 add aid e2e test and cleanup [RUM 7963]Add anonymous user id e2e test and cleanup Jan 8, 2025
@codecov-commenter
Copy link

codecov-commenter commented Jan 8, 2025

Codecov Report

All modified and coverable lines are covered by tests βœ…

Project coverage is 93.68%. Comparing base (bfffdaf) to head (a8749e7).

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.
πŸ“’ Have feedback on the report? Share it here.

Base automatically changed from v6 to main January 9, 2025 09:14
@cy-moi cy-moi changed the title [RUM 7963]Add anonymous user id e2e test and cleanup πŸ‘·β€β™€οΈ [RUM-7963] Add anonymous user id e2e test and cleanup Jan 9, 2025
@cy-moi cy-moi marked this pull request as ready for review January 20, 2025 13:53
@cy-moi cy-moi requested a review from a team as a code owner January 20, 2025 13:53
Comment on lines 84 to 86
await browser.execute(() => {
window.DD_RUM!.addAction('foo')
})
Copy link
Member

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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

πŸ’¬ suggestion: ‏use findSessionCookie here

Comment on lines 57 to 58
const prevSessionCookie = await findSessionCookie()
const anonymousId = prevSessionCookie?.match(/aid=[a-z0-9-]+/)
Copy link
Member

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.

Comment on lines 64 to 66
if (anonymousId) {
expect(await findSessionCookie()).toContain(anonymousId[0])
}
Copy link
Member

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

Suggested change
if (anonymousId) {
expect(await findSessionCookie()).toContain(anonymousId[0])
}
expect(await findSessionCookie()).toContain(anonymousId![0])

Copy link

cit-pr-commenter bot commented Jan 22, 2025

Bundles Sizes Evolution

πŸ“¦ Bundle Name Base Size Local Size 𝚫 𝚫% Status
Rum 145.98 KiB 145.98 KiB 0 B 0.00% βœ…
Logs 51.06 KiB 51.06 KiB 0 B 0.00% βœ…
Rum Slim 104.77 KiB 104.77 KiB 0 B 0.00% βœ…
Worker 24.50 KiB 24.50 KiB 0 B 0.00% βœ…
πŸš€ CPU Performance
Action Name Base Average Cpu Time (ms) Local Average Cpu Time (ms) 𝚫
addglobalcontext 0.003 0.003 0.000
addaction 0.039 0.042 0.003
addtiming 0.001 0.001 0.000
adderror 0.046 0.053 0.007
startstopsessionreplayrecording 0.008 0.012 0.004
startview 0.414 0.424 0.009
logmessage 0.022 0.023 0.001
🧠 Memory Performance
Action Name Base Consumption Memory (bytes) Local Consumption Memory (bytes) 𝚫 (bytes)
addglobalcontext 27.33 KiB 28.35 KiB 1.02 KiB
addaction 54.12 KiB 57.62 KiB 3.51 KiB
addtiming 26.15 KiB 26.08 KiB -67 B
adderror 59.09 KiB 60.53 KiB 1.44 KiB
startstopsessionreplayrecording 24.90 KiB 25.83 KiB 959 B
startview 413.20 KiB 420.59 KiB 7.39 KiB
logmessage 60.18 KiB 63.31 KiB 3.13 KiB

πŸ”— RealWorld

@thomas-lebeau thomas-lebeau self-assigned this Jan 23, 2025
@cy-moi cy-moi force-pushed the congyao/RUM-7963-add-aid-e2e-test-and-cleanup branch from c1b513e to fb948a4 Compare January 23, 2025 15:21
@cy-moi cy-moi merged commit 1440c99 into main Jan 24, 2025
19 checks passed
@cy-moi cy-moi deleted the congyao/RUM-7963-add-aid-e2e-test-and-cleanup branch January 24, 2025 12:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants