|
| 1 | +import { describe, test } from "@jest/globals"; |
| 2 | +import { expect } from "expect"; |
| 3 | + |
| 4 | +import { |
| 5 | + EventContext, |
| 6 | + EventPluginContext, |
| 7 | + ExceptionlessClient |
| 8 | +} from "@exceptionless/core"; |
| 9 | + |
| 10 | +import { BrowserIgnoreExtensionErrorsPlugin } from "../../src/plugins/BrowserIgnoreExtensionErrorsPlugin.js"; |
| 11 | + |
| 12 | +describe("BrowserIgnoreExtensionErrorsPlugin", () => { |
| 13 | + let client: ExceptionlessClient; |
| 14 | + let plugin: BrowserIgnoreExtensionErrorsPlugin; |
| 15 | + |
| 16 | + beforeEach(() => { |
| 17 | + client = new ExceptionlessClient(); |
| 18 | + plugin = new BrowserIgnoreExtensionErrorsPlugin(); |
| 19 | + }); |
| 20 | + |
| 21 | + const run = async (stackTrace?: string | undefined): Promise<EventPluginContext> => { |
| 22 | + const error = new Error("Test"); |
| 23 | + if (stackTrace) { |
| 24 | + error.stack = stackTrace; |
| 25 | + } |
| 26 | + |
| 27 | + const eventContext = new EventContext(); |
| 28 | + eventContext.setException(error); |
| 29 | + |
| 30 | + const context = new EventPluginContext(client, { type: "error" }, eventContext); |
| 31 | + |
| 32 | + await plugin.run(context); |
| 33 | + return context; |
| 34 | + } |
| 35 | + |
| 36 | + test("should not cancel empty stack trace", async () => { |
| 37 | + const context = await run(); |
| 38 | + expect(context.cancelled).toBe(false); |
| 39 | + }); |
| 40 | + |
| 41 | + test("should not cancel normal stack trace", async () => { |
| 42 | + const context = await run("at t() in https://test/Content/js/Exceptionless/exceptionless.min.js:line 1:col 260"); |
| 43 | + expect(context.cancelled).toBe(false); |
| 44 | + }); |
| 45 | + |
| 46 | + test("should cancel browser extension stack trace", async () => { |
| 47 | + const context = await run("at Object.initialize() in chrome-extension://bmagokdooijbeehmkpknfglimnifench/firebug-lite.js:line 6289:col 29"); |
| 48 | + expect(context.cancelled).toBe(true); |
| 49 | + }); |
| 50 | +}); |
0 commit comments