Skip to content

Commit 6dd2ac1

Browse files
committed
fix(core,browser): bump @hawk.so/types and align tests with default
dedupe window - bump @hawk.so/types to 0.6.4 in core and browser, dropping the temporary CatcherMessage.count declaration merging now that it ships natively - export EventDedupeTransport's default window as DEFAULT_EVENT_DEDUPE_WINDOW_MS - switch the Catcher test suite to fake timers so tests account for the debounce window Catcher wires in by default, instead of assuming synchronous delivery to the underlying transport - update the repeated-string-message expectation to match debounce merging duplicate messages into a single occurrence with count
1 parent ad58dce commit 6dd2ac1

16 files changed

Lines changed: 92 additions & 32 deletions

packages/browser/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
"web-vitals": "^5.1.0"
4646
},
4747
"devDependencies": {
48-
"@hawk.so/types": "0.5.8",
48+
"@hawk.so/types": "0.6.4",
4949
"@vitest/coverage-v8": "^4.0.18",
5050
"jsdom": "^28.0.0",
5151
"vite": "^7.3.1",

packages/browser/tests/catcher.addons.test.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { describe, it, expect, vi, beforeEach } from 'vitest';
1+
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
22
import type * as HawkCore from '@hawk.so/core';
33
import { BrowserBreadcrumbStore } from '../src/addons/breadcrumbs';
44
import { wait, createTransport, getLastPayload, createCatcher } from './catcher.helpers';
@@ -21,6 +21,11 @@ describe('Catcher', () => {
2121
localStorage.clear();
2222
mockParse.mockResolvedValue([]);
2323
breadcrumbStore.instance?.destroy();
24+
vi.useFakeTimers();
25+
});
26+
27+
afterEach(() => {
28+
vi.useRealTimers();
2429
});
2530

2631
// ── Environment addons ────────────────────────────────────────────────────

packages/browser/tests/catcher.before-send.test.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { describe, it, expect, vi } from 'vitest';
1+
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
22
import { createCatcher, createTransport, wait, getLastPayload } from './catcher.helpers';
33

44
vi.mock('@hawk.so/core', async (importOriginal) => {
@@ -7,6 +7,14 @@ vi.mock('@hawk.so/core', async (importOriginal) => {
77
});
88

99
describe('Catcher', () => {
10+
beforeEach(() => {
11+
vi.useFakeTimers();
12+
});
13+
14+
afterEach(() => {
15+
vi.useRealTimers();
16+
});
17+
1018
it('should send event as-is when beforeSend returns it unchanged', async () => {
1119
const { sendSpy, transport } = createTransport();
1220
const hawk = createCatcher(transport, { beforeSend: (event) => event });

packages/browser/tests/catcher.breadcrumbs.test.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { describe, it, expect, vi, beforeEach } from 'vitest';
1+
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
22
import { BrowserBreadcrumbStore } from '../src/addons/breadcrumbs';
33
import { wait, createTransport, getLastPayload, createCatcher } from './catcher.helpers';
44

@@ -13,6 +13,11 @@ describe('Catcher', () => {
1313
localStorage.clear();
1414
mockParse.mockResolvedValue([]);
1515
(BrowserBreadcrumbStore as any).instance?.destroy();
16+
vi.useFakeTimers();
17+
});
18+
19+
afterEach(() => {
20+
vi.useRealTimers();
1621
});
1722

1823
// ── Breadcrumbs trail ─────────────────────────────────────────────────────

packages/browser/tests/catcher.context.test.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { describe, it, expect, vi, beforeEach } from 'vitest';
1+
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
22
import { BrowserBreadcrumbStore } from '../src/addons/breadcrumbs';
33
import { wait, createTransport, getLastPayload, createCatcher } from './catcher.helpers';
44

@@ -13,6 +13,11 @@ describe('Catcher', () => {
1313
localStorage.clear();
1414
mockParse.mockResolvedValue([]);
1515
(BrowserBreadcrumbStore as any).instance?.destroy();
16+
vi.useFakeTimers();
17+
});
18+
19+
afterEach(() => {
20+
vi.useRealTimers();
1621
});
1722

1823
// ── Context enrichment ────────────────────────────────────────────────────

packages/browser/tests/catcher.global-handlers.test.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ describe('Catcher', () => {
1414
localStorage.clear();
1515
mockParse.mockResolvedValue([]);
1616
(BrowserBreadcrumbStore as any).instance?.destroy();
17+
vi.useFakeTimers();
18+
});
19+
20+
afterEach(() => {
21+
vi.useRealTimers();
1722
});
1823

1924
// ── Global error handlers ─────────────────────────────────────────────────

packages/browser/tests/catcher.helpers.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,16 @@ import { vi } from 'vitest';
22
import Catcher from '../src/catcher';
33
import type { Transport } from '../src';
44
import type { MessageProcessor } from '@hawk.so/core';
5+
import { DEFAULT_EVENT_DEDUPE_WINDOW_MS } from '@hawk.so/core';
56

67
export const TEST_TOKEN = 'eyJpbnRlZ3JhdGlvbklkIjoiOTU3MmQyOWQtNWJhZS00YmYyLTkwN2MtZDk5ZDg5MGIwOTVmIiwic2VjcmV0IjoiZTExODFiZWItMjdlMS00ZDViLWEwZmEtZmUwYTM1Mzg5OWMyIn0=';
7-
export const wait = (): Promise<void> => new Promise((r) => setTimeout(r, 0));
8+
9+
/**
10+
* Advances past the Catcher's default EventDedupeTransport window so buffered
11+
* events are forwarded to the underlying transport. Requires fake timers
12+
* (`vi.useFakeTimers()`) to be active in the calling test file.
13+
*/
14+
export const wait = (): Promise<void> => vi.advanceTimersByTimeAsync(DEFAULT_EVENT_DEDUPE_WINDOW_MS);
815

916
export function createTransport() {
1017
const sendSpy = vi.fn().mockResolvedValue(undefined);

packages/browser/tests/catcher.message-processor.test.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { describe, expect, it, vi } from 'vitest';
1+
import { describe, expect, it, vi, beforeEach, afterEach } from 'vitest';
22
import { createCatcher, createTransport, getLastPayload, injectProcessor, wait } from './catcher.helpers';
33
import { MessageProcessor, ProcessingPayload } from '@hawk.so/core';
44

@@ -10,6 +10,14 @@ vi.mock('../src/modules/stackParser', () => ({
1010
}));
1111

1212
describe('Catcher', () => {
13+
beforeEach(() => {
14+
vi.useFakeTimers();
15+
});
16+
17+
afterEach(() => {
18+
vi.useRealTimers();
19+
});
20+
1321
describe('message processor', () => {
1422
it('should send original message when processor does not modify it', async () => {
1523
const { sendSpy, transport } = createTransport();

packages/browser/tests/catcher.release.test.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { describe, expect, it, vi } from "vitest";
1+
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
22
import { createCatcher, createTransport, getLastPayload, wait } from "./catcher.helpers";
33

44
vi.mock('@hawk.so/core', async (importOriginal) => {
@@ -7,6 +7,14 @@ vi.mock('@hawk.so/core', async (importOriginal) => {
77
});
88

99
describe('Catcher', () => {
10+
beforeEach(() => {
11+
vi.useFakeTimers();
12+
});
13+
14+
afterEach(() => {
15+
vi.useRealTimers();
16+
});
17+
1018
it('should include release version when configured', async () => {
1119
const { sendSpy, transport } = createTransport();
1220

packages/browser/tests/catcher.test.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ describe('Catcher', () => {
1717
localStorage.clear();
1818
mockParse.mockResolvedValue([]);
1919
(BrowserBreadcrumbStore as any).instance?.destroy();
20+
vi.useFakeTimers();
21+
});
22+
23+
afterEach(() => {
24+
vi.useRealTimers();
2025
});
2126

2227
// ── Constructor variants ──────────────────────────────────────────────────
@@ -114,15 +119,16 @@ describe('Catcher', () => {
114119
expect(sendSpy).toHaveBeenCalledTimes(2);
115120
});
116121

117-
it('should send payload for same strings without deduplication', async () => {
122+
it('should merge repeated identical string occurrences into a single send with count', async () => {
118123
const { sendSpy, transport } = createTransport();
119124
const hawk = createCatcher(transport);
120125

121126
hawk.send('reason');
122127
hawk.send('reason');
123128
await wait();
124129

125-
expect(sendSpy).toHaveBeenCalledTimes(2);
130+
expect(sendSpy).toHaveBeenCalledTimes(1);
131+
expect(sendSpy.mock.calls[0][0].count).toBe(2);
126132
});
127133
});
128134

0 commit comments

Comments
 (0)