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

CHORE(NPM) - bump @sentry/react from 7.114.0 to 8.7.0 #148

Merged
merged 3 commits into from
Jun 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apps/parsley/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
"@leafygreen-ui/toggle": "10.0.4",
"@leafygreen-ui/tooltip": "10.0.10",
"@leafygreen-ui/typography": "19.0.0",
"@sentry/react": "7.114.0",
"@sentry/react": "8.7.0",
"@sentry/types": "7.114.0",
"ansi_up": "6.0.2",
"graphql": "16.8.1",
Expand Down
29 changes: 17 additions & 12 deletions apps/parsley/src/components/ErrorHandling/initialize.test.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
import * as Sentry from "@sentry/react";
import { init, isInitialized } from "@sentry/react";
import { mockEnvironmentVariables } from "test_utils/utils";
import { initializeErrorHandling } from ".";

const { cleanup, mockEnv } = mockEnvironmentVariables();

describe("should initialize error handlers according to release stage", () => {
beforeEach(() => {
vi.spyOn(Sentry, "init").mockImplementation(vi.fn());
});
vi.mock("@sentry/react", async (importOriginal) => {
const actual = await importOriginal();
return {
// @ts-expect-error
...actual,
init: vi.fn(),
isInitialized: vi.fn().mockReturnValue(false),
};
});

describe("should initialize error handlers according to release stage", () => {
afterEach(() => {
vi.restoreAllMocks();
cleanup();
Expand All @@ -19,7 +25,7 @@ describe("should initialize error handlers according to release stage", () => {
mockEnv("REACT_APP_RELEASE_STAGE", "production");
initializeErrorHandling();

expect(Sentry.init).not.toHaveBeenCalled();
expect(vi.mocked(init)).not.toHaveBeenCalled();
});

it("production", () => {
Expand All @@ -28,7 +34,7 @@ describe("should initialize error handlers according to release stage", () => {
mockEnv("REACT_APP_PARSLEY_SENTRY_DSN", "fake-sentry-key");
initializeErrorHandling();

expect(Sentry.init).toHaveBeenCalledWith({
expect(vi.mocked(init)).toHaveBeenCalledWith({
beforeBreadcrumb: expect.any(Function),
debug: false,
dsn: "fake-sentry-key",
Expand All @@ -44,7 +50,7 @@ describe("should initialize error handlers according to release stage", () => {
mockEnv("REACT_APP_PARSLEY_SENTRY_DSN", "fake-sentry-key");
initializeErrorHandling();

expect(Sentry.init).toHaveBeenCalledWith({
expect(vi.mocked(init)).toHaveBeenCalledWith({
beforeBreadcrumb: expect.any(Function),
debug: true,
dsn: "fake-sentry-key",
Expand All @@ -60,7 +66,7 @@ describe("should initialize error handlers according to release stage", () => {
mockEnv("REACT_APP_PARSLEY_SENTRY_DSN", "fake-sentry-key");
initializeErrorHandling();

expect(Sentry.init).toHaveBeenCalledWith({
expect(vi.mocked(init)).toHaveBeenCalledWith({
beforeBreadcrumb: expect.any(Function),
debug: true,
dsn: "fake-sentry-key",
Expand All @@ -73,7 +79,6 @@ describe("should initialize error handlers according to release stage", () => {

describe("should not initialize if the client is already running", () => {
beforeEach(() => {
vi.spyOn(Sentry, "init").mockImplementation(vi.fn());
mockEnv("NODE_ENV", "production");
});

Expand All @@ -83,8 +88,8 @@ describe("should not initialize if the client is already running", () => {
});

it("does not initialize Sentry twice", () => {
vi.spyOn(Sentry, "isInitialized").mockReturnValue(true);
vi.mocked(isInitialized).mockReturnValue(true);
initializeErrorHandling();
expect(Sentry.init).not.toHaveBeenCalled();
expect(vi.mocked(init)).not.toHaveBeenCalled();
});
});
45 changes: 24 additions & 21 deletions apps/parsley/src/utils/errorReporting/errorReporting.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as Sentry from "@sentry/react";
import { addBreadcrumb, captureException, setTags } from "@sentry/react";
import { mockEnvironmentVariables } from "test_utils/utils";
import {
SentryBreadcrumb,
Expand All @@ -8,10 +8,20 @@ import {

const { cleanup, mockEnv } = mockEnvironmentVariables();

vi.mock("@sentry/react", async (importOriginal) => {
const actual = await importOriginal();
return {
// @ts-expect-error
...actual,
addBreadcrumb: vi.fn(),
captureException: vi.fn(),
setTags: vi.fn(),
};
});

describe("error reporting", () => {
beforeEach(() => {
vi.spyOn(console, "error").mockImplementation(() => {});
vi.spyOn(Sentry, "captureException");
});
afterEach(() => {
cleanup();
Expand All @@ -31,24 +41,22 @@ describe("error reporting", () => {
err,
severity: "warning",
});
expect(Sentry.captureException).not.toHaveBeenCalled();
expect(vi.mocked(captureException)).not.toHaveBeenCalled();
});

it("should report errors to Sentry when in production", () => {
mockEnv("NODE_ENV", "production");
vi.spyOn(Sentry, "captureException").mockImplementation(vi.fn());

const err = new Error("test error");
const result = reportError(err);
result.severe();
expect(Sentry.captureException).toHaveBeenCalledWith(err);
expect(vi.mocked(captureException)).toHaveBeenCalledWith(err);
result.warning();
expect(Sentry.captureException).toHaveBeenCalledWith(err);
expect(vi.mocked(captureException)).toHaveBeenCalledWith(err);
});

it("supports context field", () => {
mockEnv("NODE_ENV", "production");
vi.spyOn(Sentry, "captureException").mockImplementation(vi.fn());
const err = {
message: "GraphQL Error",
name: "Error Name",
Expand All @@ -57,15 +65,13 @@ describe("error reporting", () => {
const context = { anything: "foo" };
const result = reportError(err, { context });
result.severe();
expect(Sentry.captureException).toHaveBeenCalledWith(err);
expect(vi.mocked(captureException)).toHaveBeenCalledWith(err);
result.warning();
expect(Sentry.captureException).toHaveBeenCalledWith(err);
expect(vi.mocked(captureException)).toHaveBeenCalledWith(err);
});

it("supports tags", () => {
mockEnv("NODE_ENV", "production");
vi.spyOn(Sentry, "captureException").mockImplementation(vi.fn());
vi.spyOn(Sentry, "setTags").mockImplementation(vi.fn());
const err = {
message: "GraphQL Error",
name: "Error Name",
Expand All @@ -74,18 +80,17 @@ describe("error reporting", () => {
const tags = { spruce: "true" };
const result = reportError(err, { tags });
result.severe();
expect(Sentry.captureException).toHaveBeenCalledWith(err);
expect(Sentry.setTags).toHaveBeenCalledWith(tags);
expect(vi.mocked(captureException)).toHaveBeenCalledWith(err);
expect(vi.mocked(setTags)).toHaveBeenCalledWith(tags);
result.warning();
expect(Sentry.captureException).toHaveBeenCalledWith(err);
expect(Sentry.setTags).toHaveBeenCalledWith(tags);
expect(vi.mocked(captureException)).toHaveBeenCalledWith(err);
expect(vi.mocked(setTags)).toHaveBeenCalledWith(tags);
});
});

describe("breadcrumbs", () => {
beforeEach(() => {
vi.spyOn(console, "debug").mockImplementation(() => {});
vi.spyOn(Sentry, "addBreadcrumb");
});
afterEach(() => {
cleanup();
Expand All @@ -103,20 +108,19 @@ describe("breadcrumbs", () => {
metadata,
type,
});
expect(Sentry.addBreadcrumb).not.toHaveBeenCalled();
expect(vi.mocked(addBreadcrumb)).not.toHaveBeenCalled();
});

it("should report breadcrumbs to Sentry when in production", () => {
vi.useFakeTimers().setSystemTime(new Date("2020-01-01"));
mockEnv("NODE_ENV", "production");
vi.spyOn(Sentry, "addBreadcrumb").mockImplementation(vi.fn());

const message = "my message";
const type = SentryBreadcrumb.Info;
const metadata = { status_code: 401 };

leaveBreadcrumb(message, metadata, type);
expect(Sentry.addBreadcrumb).toHaveBeenCalledWith({
expect(vi.mocked(addBreadcrumb)).toHaveBeenCalledWith({
data: { status_code: 401 },
message,
timestamp: 1577836800,
Expand All @@ -129,7 +133,6 @@ describe("breadcrumbs", () => {
vi.useFakeTimers().setSystemTime(new Date("2020-01-01"));
vi.spyOn(console, "warn").mockImplementation(() => {});
mockEnv("NODE_ENV", "production");
vi.spyOn(Sentry, "addBreadcrumb").mockImplementation(vi.fn());

const message = "navigation message";
const type = SentryBreadcrumb.Navigation;
Expand All @@ -144,7 +147,7 @@ describe("breadcrumbs", () => {
2,
"Navigation breadcrumbs should include a 'to' metadata field.",
);
expect(Sentry.addBreadcrumb).toHaveBeenCalledWith({
expect(vi.mocked(addBreadcrumb)).toHaveBeenCalledWith({
data: {},
message,
timestamp: 1577836800,
Expand Down
2 changes: 1 addition & 1 deletion apps/spruce/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@
"@leafygreen-ui/tooltip": "10.0.10",
"@leafygreen-ui/typography": "19.0.0",
"@rjsf/core": "4.2.3",
"@sentry/react": "7.114.0",
"@sentry/react": "8.7.0",
"@sentry/types": "7.114.0",
"ansi_up": "6.0.2",
"antd": "4.20.0",
Expand Down
14 changes: 11 additions & 3 deletions apps/spruce/src/components/ErrorHandling/ErrorBoundary.test.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,22 @@
import * as Sentry from "@sentry/react";
import { captureException } from "@sentry/react";
import { render, screen } from "test_utils";
import { mockEnvironmentVariables } from "test_utils/utils";
import { ErrorBoundary } from "./ErrorBoundary";

const { cleanup } = mockEnvironmentVariables();

vi.mock("@sentry/react", async (importOriginal) => {
const actual = await importOriginal();
return {
// @ts-expect-error
...actual,
captureException: vi.fn(),
};
});

describe("default error boundary", () => {
beforeEach(() => {
vi.spyOn(console, "error").mockImplementation(() => {});
vi.spyOn(Sentry, "captureException");
});

afterEach(() => {
Expand Down Expand Up @@ -46,6 +54,6 @@ describe("default error boundary", () => {
componentStack: expect.any(String),
}),
});
expect(Sentry.captureException).not.toHaveBeenCalled();
expect(vi.mocked(captureException)).not.toHaveBeenCalled();
});
});
29 changes: 18 additions & 11 deletions apps/spruce/src/components/ErrorHandling/initialize.test.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
import * as Sentry from "@sentry/react";
import { init, isInitialized } from "@sentry/react";
import { mockEnvironmentVariables } from "test_utils/utils";
import { initializeErrorHandling } from ".";

const { cleanup, mockEnv } = mockEnvironmentVariables();

vi.mock("@sentry/react", async (importOriginal) => {
const actual = await importOriginal();
return {
// @ts-expect-error
...actual,
init: vi.fn(),
isInitialized: vi.fn().mockReturnValue(false),
};
});

describe("should initialize error handlers according to release stage", () => {
beforeEach(() => {
vi.spyOn(Sentry, "init").mockImplementation(vi.fn());
});
beforeEach(() => {});

afterEach(() => {
vi.restoreAllMocks();
Expand All @@ -20,7 +28,7 @@ describe("should initialize error handlers according to release stage", () => {
mockEnv("REACT_APP_RELEASE_STAGE", "production");
initializeErrorHandling();

expect(Sentry.init).not.toHaveBeenCalled();
expect(vi.mocked(init)).not.toHaveBeenCalled();
});

it("production", () => {
Expand All @@ -30,7 +38,7 @@ describe("should initialize error handlers according to release stage", () => {
mockEnv("REACT_APP_SPRUCE_SENTRY_DSN", "fake-sentry-key");
initializeErrorHandling();

expect(Sentry.init).toHaveBeenCalledWith({
expect(vi.mocked(init)).toHaveBeenCalledWith({
beforeBreadcrumb: expect.any(Function),
dsn: "fake-sentry-key",
debug: false,
Expand All @@ -47,7 +55,7 @@ describe("should initialize error handlers according to release stage", () => {
mockEnv("REACT_APP_SPRUCE_SENTRY_DSN", "fake-sentry-key");
initializeErrorHandling();

expect(Sentry.init).toHaveBeenCalledWith({
expect(vi.mocked(init)).toHaveBeenCalledWith({
beforeBreadcrumb: expect.any(Function),
dsn: "fake-sentry-key",
debug: true,
Expand All @@ -64,7 +72,7 @@ describe("should initialize error handlers according to release stage", () => {
mockEnv("REACT_APP_SPRUCE_SENTRY_DSN", "fake-sentry-key");
initializeErrorHandling();

expect(Sentry.init).toHaveBeenCalledWith({
expect(vi.mocked(init)).toHaveBeenCalledWith({
beforeBreadcrumb: expect.any(Function),
dsn: "fake-sentry-key",
debug: true,
Expand All @@ -77,7 +85,6 @@ describe("should initialize error handlers according to release stage", () => {

describe("should not initialize if the client is already running", () => {
beforeEach(() => {
vi.spyOn(Sentry, "init").mockImplementation(vi.fn());
mockEnv("NODE_ENV", "production");
});

Expand All @@ -87,8 +94,8 @@ describe("should not initialize if the client is already running", () => {
});

it("does not initialize Sentry twice", () => {
vi.spyOn(Sentry, "isInitialized").mockReturnValue(true);
vi.mocked(isInitialized).mockReturnValue(true);
initializeErrorHandling();
expect(Sentry.init).not.toHaveBeenCalled();
expect(vi.mocked(init)).not.toHaveBeenCalled();
});
});
Loading
Loading