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

test(browser): Add integration tests for sessions. #4500

Merged
merged 3 commits into from
Feb 10, 2022

Conversation

onurtemizkan
Copy link
Collaborator

Resolves: #4358

I could not reproduce the case when the session status is not 'ok'.

@@ -0,0 +1,11 @@
document.getElementById('start-session').addEventListener('click', () => {
Sentry.getCurrentHub().startSession();
Copy link
Member

Choose a reason for hiding this comment

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

I would prefer if we only tested the autoSessionTracking for now, so the sessions that start in pageload/navigation. Let’s not do manual sessions for the time being.


const session = await page.evaluateHandle<Session>('window.Sentry.getCurrentHub().getScope().getSession()');

return session.jsonValue();
Copy link
Member

Choose a reason for hiding this comment

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

I would prefer if we assert on the session envelopes instead of grabbing it this way.

@github-actions
Copy link
Contributor

github-actions bot commented Feb 4, 2022

size-limit report

Path Base Size (e00b419) Current Size Change
@sentry/browser - ES5 CDN Bundle (gzipped + minified) 19.73 KB 19.73 KB -0.01% 🔽
@sentry/browser - ES5 CDN Bundle (minified) 63.06 KB 63.06 KB 0%
@sentry/browser - ES6 CDN Bundle (gzipped + minified) 18.44 KB 18.44 KB -0.01% 🔽
@sentry/browser - ES6 CDN Bundle (minified) 56.5 KB 56.5 KB 0%
@sentry/browser - Webpack (gzipped + minified) 22.16 KB 22.16 KB 0%
@sentry/browser - Webpack (minified) 75.87 KB 75.87 KB 0%
@sentry/react - Webpack (gzipped + minified) 22.19 KB 22.19 KB 0%
@sentry/nextjs Client - Webpack (gzipped + minified) 46.27 KB 46.27 KB 0%
@sentry/browser + @sentry/tracing - ES5 CDN Bundle (gzipped + minified) 28.29 KB 28.29 KB 0%

* @return {*} {Promise<SessionContext>}
*/
async function getCurrentSession(page: Page, url?: string): Promise<SessionContext> {
return (await getMultipleSentryTransactionRequests(page, 1, url))[0];
Copy link
Member

Choose a reason for hiding this comment

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

Technically this is not guaranteed to be a session right?

I think we should rename getMultipleSentryTransactionRequests -> getMultipleSentryEnvelopeRequests and directly call that in the tests. The tests can just handle picking the right request and asserting on it (they can even assert on the total amount of requests sent if needed).

Maybe we use getMultipleSentryEnvelopeRequests just for this PR, and then migrate the other test files in another PR.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, and #4527 seems to solve the confusion. I'll update the PR with proper types after that gets merged, unless this one is urgent?

Copy link
Member

Choose a reason for hiding this comment

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

Nothing using those types internally yet, I would just make the changes here and we can come back and update this after.

@onurtemizkan
Copy link
Collaborator Author

@AbhiPrasad, I updated as discussed. Will also open another PR to update the other tests to use the new helper(s). Renaming getSentryRequest | Transaction to getFirstSentryEnvelope and getFirstSentryRequest feels more accurate, as we're listening and resolving on the first one, if you agree?

@AbhiPrasad
Copy link
Member

I agree with those changes, let’s move forward with that.

@AbhiPrasad AbhiPrasad merged commit b77ec37 into master Feb 10, 2022
@AbhiPrasad AbhiPrasad deleted the onur/int-tests-browser-sessions branch February 10, 2022 17:41
@AbhiPrasad AbhiPrasad added this to the Release Stability milestone Feb 10, 2022
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.

Add integration tests for browser sessions
2 participants