Skip to content

Conversation

@Mrtenz
Copy link
Member

@Mrtenz Mrtenz commented Jul 30, 2025

This adds support for snap_startTrace and snap_endTrace to snaps-jest, and a toTrace matcher to go with it.

@codecov
Copy link

codecov bot commented Jul 30, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.28%. Comparing base (27c8e14) to head (6c856d8).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #3547   +/-   ##
=======================================
  Coverage   98.27%   98.28%           
=======================================
  Files         415      417    +2     
  Lines       11717    11765   +48     
  Branches     1821     1827    +6     
=======================================
+ Hits        11515    11563   +48     
  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.

});
}

case 'trace': {
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 had to add this because we clear the trackables state for every request. We could consider not clearing performance traces between requests as well.

Copy link
Member

Choose a reason for hiding this comment

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

Would it be a lot of work to keep pendingTraces between runs?

Copy link
Member

Choose a reason for hiding this comment

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

Unsure whether most usage would be during a single request tbh 🤔

Copy link
Member Author

Choose a reason for hiding this comment

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

We explicitly clear it, so it would be easy to keep it. Just unsure about the expectations.

Copy link
Member

Choose a reason for hiding this comment

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

Do we have no existing state between requests?

Copy link
Member Author

Choose a reason for hiding this comment

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

Right now all the notifications and trackables are cleared:

store.dispatch(clearNotifications());
store.dispatch(clearTrackables());

But Snap state isn't.

Copy link
Member

Choose a reason for hiding this comment

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

Hmm. Up to you whether you think it makes sense to persist it between runs, we can always easily change the behavior.

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

This comment was marked as outdated.

cursor[bot]

This comment was marked as outdated.

},
endTrace: (state, action: PayloadAction<EndTraceParams>) => {
const endTrace = castDraft(action.payload);
const index = state.pendingTraces.findIndex(
Copy link
Member

Choose a reason for hiding this comment

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

Do we need logic to handle multiple pending traces with the same name/id?

Copy link
Member Author

Choose a reason for hiding this comment

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

Other than changing it to LIFO like Cursor suggested, I'm not sure what we should change. Unless you think new traces should override existing ones if the name/ID is the same? I have no idea how Sentry handles it, but generally I would expect that Snaps don't run multiple traces at the same time with the same name.

Copy link
Member

@FrederikBolding FrederikBolding Jul 31, 2025

Choose a reason for hiding this comment

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

Do we need to match on both name and ID? Are we expecting that Snaps will pass both (our example does not)?

Copy link
Member Author

Choose a reason for hiding this comment

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

The name is required, but ID is optional. For matching, just passing a name in both cases will work (since undefined === undefined), but if the ID in the end request is different it will fail.

Copy link
Member

Choose a reason for hiding this comment

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

Perhaps fair enough to expect the same parameters on both sides

Copy link
Member

Choose a reason for hiding this comment

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

But I think there is a chance we have to adjust this based on usage

clearTrackables: (state) => {
state.events = [];
state.errors = [];
state.traces = [];
Copy link
Member

@FrederikBolding FrederikBolding Jul 31, 2025

Choose a reason for hiding this comment

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

Suggested change
state.traces = [];
state.traces = [];
// We are not resetting `pendingTraces` to let them persist between requests.

Copy link
Member Author

Choose a reason for hiding this comment

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

Not sure if this is necessary since it's documented in the test as well

@Mrtenz Mrtenz enabled auto-merge July 31, 2025 09:02
@Mrtenz Mrtenz added this pull request to the merge queue Jul 31, 2025
Merged via the queue into main with commit 69ad505 Jul 31, 2025
120 checks passed
@Mrtenz Mrtenz deleted the mrtenz/jest-trace branch July 31, 2025 09:10
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