Skip to content

Commit

Permalink
test(ui): Enable sentry jest integration (#70821)
Browse files Browse the repository at this point in the history
  • Loading branch information
scttcper authored May 14, 2024
1 parent d896596 commit 1a25154
Show file tree
Hide file tree
Showing 4 changed files with 423 additions and 409 deletions.
7 changes: 4 additions & 3 deletions jest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,8 @@ const config: Config.InitialOptions = {
*/
clearMocks: true,

testEnvironment: 'jsdom',
// To disable the sentry jest integration, set this to 'jsdom'
testEnvironment: '@sentry/jest-environment/jsdom',
testEnvironmentOptions: {
sentryConfig: {
init: {
Expand All @@ -284,8 +285,8 @@ const config: Config.InitialOptions = {
: false,
// Use production env to reduce sampling of commits on master
environment: CI ? (IS_MASTER_BRANCH ? 'ci:master' : 'ci:pull_request') : 'local',
tracesSampleRate: CI ? 1 : 0.5,
profilesSampleRate: CI ? 0.1 : 0,
tracesSampleRate: CI ? 0.75 : 0,
profilesSampleRate: 0,
transportOptions: {keepAlive: true},
},
transactionOptions: {
Expand Down
15 changes: 7 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
"@types/diff": "5.0.2",
"@types/dompurify": "^3.0.5",
"@types/invariant": "^2.2.35",
"@types/jest": "^29.5.3",
"@types/jest": "29.5.12",
"@types/js-beautify": "^1.14.3",
"@types/js-cookie": "^3.0.2",
"@types/lodash": "^4.14.182",
Expand Down Expand Up @@ -177,25 +177,24 @@
"@biomejs/biome": "^1.7.0",
"@codecov/webpack-plugin": "^0.0.1-beta.6",
"@pmmmwh/react-refresh-webpack-plugin": "0.5.11",
"@sentry/jest-environment": "^4.0.0",
"@sentry/jest-environment": "6.0.0",
"@sentry/profiling-node": "^8.0.0",
"@styled/typescript-styled-plugin": "^1.0.1",
"@testing-library/jest-dom": "^6.4.2",
"@testing-library/jest-dom": "6.4.5",
"@testing-library/react": "^14.2.1",
"@testing-library/user-event": "^14.5.2",
"@types/node": "^20.11.7",
"babel-gettext-extractor": "^4.1.3",
"babel-jest": "^29.6.2",
"babel-jest": "29.7.0",
"benchmark": "^2.1.4",
"eslint": "8.57.0",
"eslint-config-sentry-app": "2.7.0",
"html-webpack-plugin": "^5.5.0",
"jest": "29.6.2",
"jest": "29.7.0",
"jest-canvas-mock": "^2.5.2",
"jest-environment-jsdom": "^29.6.2",
"jest-fail-on-console": "^3.1.1",
"jest-environment-jsdom": "29.7.0",
"jest-fail-on-console": "3.3.0",
"jest-junit": "16.0.0",
"jest-sentry-environment": "3.0.0",
"postcss-styled-syntax": "0.6.4",
"react-refresh": "0.14.0",
"stylelint": "16.2.1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,39 +3,37 @@ import {
ProblemSpan,
TransactionEventBuilder,
} from 'sentry-test/performance/utils';
import {render, screen, userEvent} from 'sentry-test/reactTestingLibrary';

import * as useApi from 'sentry/utils/useApi';
import {act, render, screen, userEvent} from 'sentry-test/reactTestingLibrary';

import {SpanEvidencePreview} from './spanEvidencePreview';

describe('SpanEvidencePreview', () => {
beforeEach(() => {
jest.useFakeTimers();
jest.resetAllMocks();

MockApiClient.clearMockResponses();
MockApiClient.addMockResponse({
url: '/organizations/org-slug/issues/group-id/',
});
});

it('does not fetch before hover', () => {
const api = new MockApiClient();
jest.spyOn(useApi, 'default').mockReturnValue(api);
const spy = jest.spyOn(api, 'requestPromise');
it('does not fetch before hover', async () => {
const mock = MockApiClient.addMockResponse({
url: `/organizations/org-slug/issues/group-id/events/recommended/`,
body: {},
});

render(<SpanEvidencePreview groupId="group-id">Hover me</SpanEvidencePreview>);

jest.runAllTimers();
await act(tick);

expect(spy).not.toHaveBeenCalled();
expect(mock).not.toHaveBeenCalled();
});

it('shows error when request fails', async () => {
const api = new MockApiClient();
jest.spyOn(useApi, 'default').mockReturnValue(api);
jest.spyOn(api, 'requestPromise').mockRejectedValue(new Error());
MockApiClient.addMockResponse({
url: `/organizations/org-slug/issues/group-id/events/recommended/`,
body: {},
statusCode: 500,
});

render(<SpanEvidencePreview groupId="group-id">Hover me</SpanEvidencePreview>);

Expand Down
Loading

0 comments on commit 1a25154

Please sign in to comment.