Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Fetch support #898

Merged
merged 17 commits into from
Jan 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions src/__tests__/extensions/replay/sessionrecording.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -536,7 +536,6 @@ describe('SessionRecording', () => {
$window_id: 'windowId',
},
{
transport: 'XHR',
method: 'POST',
endpoint: '/s/',
_noTruncate: true,
Expand Down Expand Up @@ -575,7 +574,6 @@ describe('SessionRecording', () => {
},
{
method: 'POST',
transport: 'XHR',
endpoint: '/s/',
_noTruncate: true,
_batchKey: 'recordings',
Expand Down Expand Up @@ -660,7 +658,6 @@ describe('SessionRecording', () => {
},
{
method: 'POST',
transport: 'XHR',
endpoint: '/s/',
_noTruncate: true,
_batchKey: 'recordings',
Expand Down Expand Up @@ -1288,7 +1285,6 @@ describe('SessionRecording', () => {
_noTruncate: true,
endpoint: '/s/',
method: 'POST',
transport: 'XHR',
}
)
expect(sessionRecording['buffer']).toEqual({
Expand Down
18 changes: 9 additions & 9 deletions src/__tests__/retry-queue.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const defaultRequestOptions: CaptureOptions = {
}

describe('RetryQueue', () => {
const onXHRError = jest.fn().mockImplementation(console.error)
const onRequestError = jest.fn().mockImplementation(console.error)
const rateLimiter = new RateLimiter()
let retryQueue: RetryQueue

Expand All @@ -26,7 +26,7 @@ describe('RetryQueue', () => {
})

beforeEach(() => {
retryQueue = new RetryQueue(onXHRError, rateLimiter)
retryQueue = new RetryQueue(onRequestError, rateLimiter)
assignableWindow.XMLHttpRequest = jest.fn().mockImplementation(xhrMockClass)
assignableWindow.navigator.sendBeacon = jest.fn()

Expand Down Expand Up @@ -112,7 +112,7 @@ describe('RetryQueue', () => {
expect(retryQueue.queue.length).toEqual(0)

expect(assignableWindow.XMLHttpRequest).toHaveBeenCalledTimes(4)
expect(onXHRError).toHaveBeenCalledTimes(0)
expect(onRequestError).toHaveBeenCalledTimes(0)
})

it('does not process event retry requests when events are rate limited', () => {
Expand Down Expand Up @@ -144,7 +144,7 @@ describe('RetryQueue', () => {
// clears queue
expect(retryQueue.queue.length).toEqual(0)
expect(assignableWindow.XMLHttpRequest).toHaveBeenCalledTimes(1)
expect(onXHRError).toHaveBeenCalledTimes(0)
expect(onRequestError).toHaveBeenCalledTimes(0)
})

it('does not process recording retry requests when they are rate limited', () => {
Expand Down Expand Up @@ -176,7 +176,7 @@ describe('RetryQueue', () => {
// clears queue
expect(retryQueue.queue.length).toEqual(0)
expect(assignableWindow.XMLHttpRequest).toHaveBeenCalledTimes(2)
expect(onXHRError).toHaveBeenCalledTimes(0)
expect(onRequestError).toHaveBeenCalledTimes(0)
})

it('tries to send requests via beacon on unload', () => {
Expand All @@ -201,12 +201,12 @@ describe('RetryQueue', () => {
expect(assignableWindow.navigator.sendBeacon).toHaveBeenCalledTimes(0)
})

it('when you flush the queue onXHRError is passed to xhr', () => {
const xhrSpy = jest.spyOn(SendRequest, 'xhr')
it('when you flush the queue onError is passed to xhr', () => {
const xhrSpy = jest.spyOn(SendRequest, 'request')
enqueueRequests()
retryQueue.flush()
fastForwardTimeAndRunTimer()
expect(xhrSpy).toHaveBeenCalledWith(expect.objectContaining({ onXHRError: onXHRError }))
expect(xhrSpy).toHaveBeenCalledWith(expect.objectContaining({ onError: onRequestError }))
})

it('enqueues requests when offline and flushes immediately when online again', () => {
Expand All @@ -220,7 +220,7 @@ describe('RetryQueue', () => {
// requests aren't attempted when we're offline
expect(assignableWindow.XMLHttpRequest).toHaveBeenCalledTimes(0)
// doesn't log that it is offline from the retry queue
expect(onXHRError).toHaveBeenCalledTimes(0)
expect(onRequestError).toHaveBeenCalledTimes(0)

// queue stays the same
expect(retryQueue.queue.length).toEqual(4)
Expand Down
Loading
Loading