-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
test(browser): Add e2e tests for the @sentry/browser
package
#13125
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
Conversation
The tests for |
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.
Hey @Zen-cronic thanks a lot for opening this PR!
Let us know when this is ready to review or if you have questions along the way. I gave your current draft a quick review and have two suggestions:
- to add this test to CI, we need to add an entry for the test app in the
.github/build.yml
matrix - Ideally, we not only test errors but also spans, specifically pageload and navigation spans. You already added
browserTracingIntegration
to yourSentry.init
call, so we should get these events as well. I see you're already perfectly using our usual test pattern so you can take some other performance test files as example.
Great work!
just FYI: I assigned myself to this PR for internal tracking purposes since I'm gonna review it. So no worries, I'm not taking over or anything. Please continue as before :) |
Thanks for the heads up! I ran into this issue though:
There could be something lacking in my test setup, but test('Should set correct transaction', async ({ page }) => {
// `pageload` transaction
const transactionPromise = waitForTransaction('default-browser', async transactionEvent => {
return !!transactionEvent?.transaction && transactionEvent.contexts?.trace?.op === 'pageload';
});
await page.goto(`/`);
// `waitForTransaction` hangs here because `transaction` (or `span`) event is not emitted,
// so the code past this line is never executed.
const pageLoadTransaction = await transactionPromise;
// ...assertions
}); |
@Zen-cronic You can run the Also it's helpful to log whatever comes into your |
@@ -0,0 +1,12 @@ | |||
import * as Sentry from '@sentry/react'; |
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.
Should be @sentry/browser
instead.
@Zen-cronic anything I can help you with or are you fine for the moment? Don't mean to rush you btw, so just let me know :) |
Hey @Lms24 thanks for looking out! I got stuck after some more debugging and testing. Here's what I've tried and observed:
^The last point seems really important, because the same "bug" is found in an already existing package. Some possible root causes:
Let me know what you think |
Thanks for the update! I set a reminder to take a look tomorrow. Perhaps there really is a bug that we need to fix. |
Sounds great! |
12ec8b5
to
b6dcb74
Compare
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.
Hey @Zen-cronic I took a look at the test app and found the reason why transactions were not sent (see comments). I also took the liberty to change some other small things and rebase the PR to the current develop
head.
Now before we merge this, there's one thing I think we should still test, which is that we send a navigation span/transaction as well. For this to test, we need to perform a soft navigation in the browser which we can easiest do with one of these actions:
- clicking on an element that redirects you to an anchor link (e.g.
/#somewhere
) - calling something like
window.history.pushState({}, '', '/test')
Would you be interested in adding this test? If not just let me know then I'll do it.
Again, great work!
integrations: [Sentry.browserTracingIntegration()], | ||
tracesSampleRate: 1.0, | ||
release: 'e2e-test', | ||
environment: 'qa', |
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.
just FYI, you couldn't have known this: setting the environment to 'qa'
is something we do that, if we actually want to send events from this app to Sentry, we can make sure it arrives and isn't dynamically sampled/dropped by the Sentry backend.
Sentry.init({ | ||
dsn: process.env.E2E_TEST_DSN, | ||
integrations: [Sentry.browserTracingIntegration()], | ||
tracesSampleRate: 1.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.
For spans and transactions to be emitted, you also need to set tracesSampleRate
to >0. In case of e2e tests, for consistent results, we set it to 1
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.
This really was the missing link! Only now do i notice that all the e2e suites that test for spans and transactions have this option enabled to 1.0.
@@ -0,0 +1,14 @@ | |||
import * as Sentry from '@sentry/browser'; |
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.
Changed to @sentry/browser
as you already identified :)
// so the code past this line is never executed. | ||
const pageLoadTransaction = await transactionPromise; | ||
|
||
expect(pageLoadTransaction).toEqual({ |
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.
I thought I'd assert on quite a few fields here since we rarely do it this detailed and I'm curious if we get inconsistencies/flakes in this simple app already. We might need to adjust some checks if they get flaky but at least locally, this 100% consistent.
@@ -859,6 +859,7 @@ jobs: | |||
'create-remix-app-express', | |||
'create-remix-app-express-legacy', | |||
'create-remix-app-express-vite-dev', | |||
'default-browser', |
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.
I added the test app to our CI e2e testing matrix
I'd definitely like to take it up. Thanks for all the detailed review! |
hey @Lms24, the pr is ready whenever you're available. I believe there's no lint issues bcuz running Let me know if there's anything more needed in this pr. |
@sentry/browser
package@sentry/browser
package
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.
Hey, thanks a lot! The navigation test looks good to me. Let's just move it into performance.test.ts
and remove the transaction.test.ts
file in favour of it. Then I'll merge the PR. Thanks!
dev-packages/e2e-tests/test-applications/default-browser/tests/transactions.test.ts
Outdated
Show resolved
Hide resolved
dev-packages/e2e-tests/test-applications/default-browser/tests/transactions.test.ts
Outdated
Show resolved
Hide resolved
Alrighty, all fixed now. |
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.
Thanks a lot @Zen-cronic! We'll make sure to give you a shoutout in the next release :)
Will merge this soon!
No worries @Lms24 and thanks for your guidance. Glad to have helped! |
- tracesSampleRate: 1 - environment: 'qa' - add to CI
- Update the simple web app to include soft navigation action - Include tests for `pageload` and `navigation` transactions/spans
d2e459d
to
ebf9dd9
Compare
This PR adds the external contributor to the CHANGELOG.md file, so that they are credited for their contribution. See #13125 --- Co-authored-by: Lukas Stracke <[email protected]>
Addresses #12662
Added e2e tests for
@sentry/browser
indev-packages/e2e-tests/test-applications
nameddefault-browser
.yarn lint
) & (yarn test
).