-
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: retry sending events to inspector
- Loading branch information
Showing
5 changed files
with
82 additions
and
22 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// eslint-disable-next-line no-underscore-dangle | ||
global.__non_webpack_require__ = require; | ||
|
||
const spy = jest.fn(); | ||
window.XMLHttpRequest = jest.fn().mockImplementation(() => ({ | ||
addEventListener: jest.fn(), | ||
})); | ||
window.XMLHttpRequest.prototype.open = jest.fn(); | ||
window.XMLHttpRequest.prototype.send = spy; | ||
window.XMLHttpRequest.prototype.setRequestHeader = jest.fn(); | ||
|
||
const {default: track, sendBatch} = require('../../src/track'); | ||
|
||
describe('track', () => { | ||
test('should track and send batch', () => { | ||
track({}); | ||
sendBatch(); | ||
expect(spy).toBeCalledTimes(1); | ||
}); | ||
|
||
test('should batch', async () => { | ||
track({}); | ||
// Request should not be sent immediately | ||
expect(spy).toBeCalledTimes(0); | ||
// Batch should go out one second later | ||
await new Promise((r) => { | ||
setTimeout(r, 1200); | ||
}); | ||
expect(spy).toBeCalledTimes(1); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters