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(feedback): Write some test for feedback utils and error returns #12519

Closed
wants to merge 4 commits into from

Conversation

ryan953
Copy link
Member

@ryan953 ryan953 commented Jun 17, 2024

Before submitting a pull request, please take a look at our
Contributing guidelines and verify:

  • If you've added code that should be tested, please add tests.
  • Ensure your code lints and the test suite passes (yarn lint) & (yarn test).

@ryan953 ryan953 requested a review from a team as a code owner June 17, 2024 21:32
const timeout = setTimeout(() => reject('Unable to determine if Feedback was correctly sent.'), 5_000);

const timeout = setTimeout(() => {
reject(new Error('Unable to determine if Feedback was correctly sent.'));
Copy link
Member Author

Choose a reason for hiding this comment

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

This updates the thrown type to be Error instead of string so that users can consistently check & optionally render error values.

Now all problems return as Error objects, and can be used like:

try {
  await sendFeedback(...);
} catch (error) {
  console.log(error.message); // instead of: `'message' in error ? error.message : error`
}

Copy link
Member

Choose a reason for hiding this comment

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

Hmm, will this break for us (+ existing users) that expect the rejection to be a string? I think we use the rejected value directly as the error message in our error toast.

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 removed the return/error type changes.

Comment on lines +9 to +14
const isolationUser = getIsolationScope().getUser();
if (isolationUser && Object.keys(isolationUser).length) {
return isolationUser;
}
const globalUser = getGlobalScope().getUser();
return globalUser;
Copy link
Member Author

Choose a reason for hiding this comment

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

testing these two scopes was hard to do directly :(

it('should return the empty user if no explicit user is set', () => {
getCurrentScope().setUser(null);

expect(getUser()).toEqual({ email: undefined, id: undefined, ip_address: undefined, username: undefined });
Copy link
Member Author

Choose a reason for hiding this comment

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

getUser() surprisingly has the return type User | undefined but when nothing is set we're getting a default empty user.

@ryan953 ryan953 requested a review from billyvg June 18, 2024 21:20
import { getCurrentScope, getGlobalScope, getIsolationScope } from '@sentry/core';
import type { User } from '@sentry/types';

export function getUser(): User | undefined {
Copy link
Member

Choose a reason for hiding this comment

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

Wonder if we do anything similar in other integrations

Copy link
Contributor

size-limit report 📦

Path Size
@sentry/browser 22.22 KB (0%)
@sentry/browser (incl. Tracing) 33.31 KB (0%)
@sentry/browser (incl. Tracing, Replay) 69.09 KB (0%)
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 62.42 KB (0%)
@sentry/browser (incl. Tracing, Replay with Canvas) 73.15 KB (0%)
@sentry/browser (incl. Tracing, Replay, Feedback) 85.76 KB (+0.49% 🔺)
@sentry/browser (incl. Tracing, Replay, Feedback, metrics) 87.62 KB (+0.48% 🔺)
@sentry/browser (incl. metrics) 26.5 KB (0%)
@sentry/browser (incl. Feedback) 38.87 KB (+1.08% 🔺)
@sentry/browser (incl. sendFeedback) 26.85 KB (-0.01% 🔽)
@sentry/browser (incl. FeedbackAsync) 31.45 KB (-0.01% 🔽)
@sentry/react 24.97 KB (0%)
@sentry/react (incl. Tracing) 36.36 KB (0%)
@sentry/vue 26.33 KB (0%)
@sentry/vue (incl. Tracing) 35.17 KB (0%)
@sentry/svelte 22.36 KB (0%)
CDN Bundle 23.42 KB (0%)
CDN Bundle (incl. Tracing) 35.05 KB (0%)
CDN Bundle (incl. Tracing, Replay) 69.18 KB (0%)
CDN Bundle (incl. Tracing, Replay, Feedback) 74.38 KB (+0.01% 🔺)
CDN Bundle - uncompressed 68.8 KB (0%)
CDN Bundle (incl. Tracing) - uncompressed 103.66 KB (0%)
CDN Bundle (incl. Tracing, Replay) - uncompressed 214.13 KB (0%)
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 226.79 KB (+0.01% 🔺)
@sentry/nextjs (client) 36.24 KB (0%)
@sentry/sveltekit (client) 33.95 KB (0%)
@sentry/node 113.27 KB (+0.01% 🔺)
@sentry/node - without tracing 90.65 KB (0%)
@sentry/aws-serverless 99.74 KB (+0.01% 🔺)

@ryan953
Copy link
Member Author

ryan953 commented Jul 30, 2024

stale

@ryan953 ryan953 closed this Jul 30, 2024
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.

2 participants