|
2 | 2 | * @vitest-environment jsdom |
3 | 3 | */ |
4 | 4 |
|
| 5 | +import { getCurrentScope, makeSession, setCurrentClient } from '@sentry/core/browser'; |
5 | 6 | import { afterEach, describe, expect, it, vi } from 'vitest'; |
6 | 7 | import { applyDefaultOptions, BrowserClient } from '../src/client'; |
7 | 8 | import { WINDOW } from '../src/helpers'; |
@@ -49,6 +50,51 @@ describe('BrowserClient', () => { |
49 | 50 | expect(flushOutcomesSpy).not.toHaveBeenCalled(); |
50 | 51 | expect(flushSpy).toHaveBeenCalledTimes(1); |
51 | 52 | }); |
| 53 | + |
| 54 | + describe('session status on unhandled errors', () => { |
| 55 | + afterEach(() => { |
| 56 | + getCurrentScope().setSession(undefined); |
| 57 | + getCurrentScope().setClient(undefined); |
| 58 | + }); |
| 59 | + |
| 60 | + it('sets the session status to "unhandled" for an unhandled exception', () => { |
| 61 | + client = new BrowserClient(getDefaultBrowserClientOptions()); |
| 62 | + setCurrentClient(client); |
| 63 | + |
| 64 | + const session = makeSession(); |
| 65 | + getCurrentScope().setSession(session); |
| 66 | + |
| 67 | + client.captureException(new Error('test'), { mechanism: { handled: false } }); |
| 68 | + |
| 69 | + expect(session.status).toBe('unhandled'); |
| 70 | + expect(session.errors).toBe(1); |
| 71 | + }); |
| 72 | + |
| 73 | + it('sets the session status to "unhandled" for a fatal event', () => { |
| 74 | + client = new BrowserClient(getDefaultBrowserClientOptions()); |
| 75 | + setCurrentClient(client); |
| 76 | + |
| 77 | + const session = makeSession(); |
| 78 | + getCurrentScope().setSession(session); |
| 79 | + |
| 80 | + client.captureEvent({ message: 'test', level: 'fatal' }); |
| 81 | + |
| 82 | + expect(session.status).toBe('unhandled'); |
| 83 | + }); |
| 84 | + |
| 85 | + it('keeps the session status "ok" for a handled exception', () => { |
| 86 | + client = new BrowserClient(getDefaultBrowserClientOptions()); |
| 87 | + setCurrentClient(client); |
| 88 | + |
| 89 | + const session = makeSession(); |
| 90 | + getCurrentScope().setSession(session); |
| 91 | + |
| 92 | + client.captureException(new Error('test')); |
| 93 | + |
| 94 | + expect(session.status).toBe('ok'); |
| 95 | + expect(session.errors).toBe(1); |
| 96 | + }); |
| 97 | + }); |
52 | 98 | }); |
53 | 99 |
|
54 | 100 | describe('applyDefaultOptions', () => { |
|
0 commit comments