Skip to content

Conversation

@Mrtenz
Copy link
Member

@Mrtenz Mrtenz commented Jul 30, 2025

This adds support to snaps-jest for the snap_trackError and snap_trackEvent methods. Internally in the simulation framework, tracked errors and events are stored in state, and made available to the response as errors and events properties. This can be combined with the new toTrackError and toTrackEvent matchers to check if errors or events are tracked.

I've updated the preinstalled example tests to use the new functionality, and added an RPC method for tracking events as well.

@codecov
Copy link

codecov bot commented Jul 30, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.27%. Comparing base (55925c0) to head (dba66a3).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3546      +/-   ##
==========================================
+ Coverage   98.26%   98.27%   +0.01%     
==========================================
  Files         411      415       +4     
  Lines       11637    11717      +80     
  Branches     1814     1821       +7     
==========================================
+ Hits        11435    11515      +80     
  Misses        202      202              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@Mrtenz Mrtenz marked this pull request as ready for review July 30, 2025 11:38
@Mrtenz Mrtenz requested a review from a team as a code owner July 30, 2025 11:38
cursor[bot]

This comment was marked as outdated.

Copy link
Member

Choose a reason for hiding this comment

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

Are the tracing functions gonna be done separately? At the very least we should return some bogus data to not crash the Snap

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't know how we can make these testable in a meaningful way, but yeah I can add a response mock at least if you prefer.

cursor[bot]

This comment was marked as outdated.

* @yields Adds the error to the store.
*/
function* trackErrorImplementation(error: Error): SagaIterator {
const serialisedError = getJsonError(error);
Copy link
Member

Choose a reason for hiding this comment

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

How come we need this? Shouldn't this mirror the client implementation?

Copy link
Member Author

Choose a reason for hiding this comment

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

In the client we deserialise to an Error instance before sending the errors to sentry. I think reserialising makes it easier to test, since you can use a standard object for assertions instead of having to construct an error.

@Mrtenz Mrtenz requested a review from FrederikBolding July 30, 2025 13:36
@Mrtenz Mrtenz added this pull request to the merge queue Jul 30, 2025
Merged via the queue into main with commit 27c8e14 Jul 30, 2025
120 checks passed
@Mrtenz Mrtenz deleted the mrtenz/jest-track-error-event branch July 30, 2025 14:07
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.

3 participants