Skip to content

Commit bca5d32

Browse files
committed
chore(browser): Clean up open handles when running Jest
- 143 from XMLHttpRequest.send - ~20 from getRequestPerformanceEntry retry timeouts in fetch-wrapper-invariants
1 parent 1d3f14c commit bca5d32

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

packages/browser/src/__tests__/extensions/replay/external/fetch-wrapper-invariants.test.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@ function setupWrappedFetch(downstreamFetch: typeof fetch): { wrappedFetch: typeo
4040
}
4141

4242
describe('fetch wrapper', () => {
43+
// Use fake timers to prevent getRequestPerformanceEntry retry timeouts
44+
// from keeping the Jest worker alive after tests complete.
45+
beforeEach(() => jest.useFakeTimers())
46+
afterEach(() => jest.useRealTimers())
47+
4348
describe('does not throw for valid inputs', () => {
4449
let wrappedFetch: typeof fetch
4550
let cleanup: () => void

packages/browser/src/__tests__/setup.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,10 @@ beforeEach(() => {
77
console.warn = (...args) => {
88
throw new Error(`Unexpected console.warn: ${args}`)
99
}
10+
11+
// Prevent jsdom XHR requests from creating open handles (TLSWRAP/Timeout)
12+
// that keep Jest from exiting. No unit tests need real HTTP responses.
13+
if (typeof XMLHttpRequest !== 'undefined') {
14+
jest.spyOn(XMLHttpRequest.prototype, 'send').mockImplementation(() => {})
15+
}
1016
})

0 commit comments

Comments
 (0)