Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
Lms24 committed Jul 10, 2024
1 parent 95700ba commit b787cb7
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/browser/src/sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ function shouldShowBrowserExtensionError(): boolean {
const isDedicatedExtensionPage =
!!runtimeId && WINDOW === WINDOW.top && extensionProtocols.some(protocol => href.startsWith(`${protocol}//`));

// Running in NW.js, which appears like a browser extension but isn't is also fine
// Running the SDK in NW.js, which appears like a browser extension but isn't, is also fine
// see: https://github.com/getsentry/sentry-javascript/issues/12668
const isNWjs = typeof windowWithMaybeExtension.nw !== 'undefined';

Expand Down
13 changes: 13 additions & 0 deletions packages/browser/test/unit/sdk.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ describe('init', () => {
afterEach(() => {
Object.defineProperty(WINDOW, 'chrome', { value: undefined, writable: true });
Object.defineProperty(WINDOW, 'browser', { value: undefined, writable: true });
Object.defineProperty(WINDOW, 'nw', { value: undefined, writable: true });
});

it('logs a browser extension error if executed inside a Chrome extension', () => {
Expand Down Expand Up @@ -210,6 +211,18 @@ describe('init', () => {
consoleErrorSpy.mockRestore();
});

it("doesn't log a browser extension error if executed inside an NW.js environment", () => {
const consoleErrorSpy = jest.spyOn(console, 'error').mockImplementation(() => {});

Object.defineProperty(WINDOW, 'nw', { value: {} });

init(options);

expect(consoleErrorSpy).not.toHaveBeenCalled();

consoleErrorSpy.mockRestore();
});

it("doesn't return a client on initialization error", () => {
const consoleErrorSpy = jest.spyOn(console, 'error').mockImplementation(() => {});

Expand Down

0 comments on commit b787cb7

Please sign in to comment.