-
Notifications
You must be signed in to change notification settings - Fork 211
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: Support `URL` type in `XHR.open` telemetry * feat: Support `URL` object in `fetch` telemetry * test: XHR test * test: Fetch telemetry tests
- Loading branch information
1 parent
6f83da1
commit 848d5f0
Showing
2 changed files
with
79 additions
and
3 deletions.
There are no files selected for viewing
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,69 @@ | ||
/* globals expect */ | ||
/* globals describe */ | ||
/* globals it */ | ||
/* globals sinon */ | ||
|
||
var Instrumenter = require('../src/browser/telemetry'); | ||
|
||
describe('instrumentNetwork', function () { | ||
it('should capture XHR requests with string URL', function (done) { | ||
var callback = sinon.spy(); | ||
var windowMock = { | ||
XMLHttpRequest: function () { } | ||
} | ||
|
||
windowMock.XMLHttpRequest.prototype.open = function () { } | ||
windowMock.XMLHttpRequest.prototype.send = function () { } | ||
|
||
var i = createInstrumenter(callback, windowMock) | ||
i.instrumentNetwork() | ||
|
||
var xhr = new windowMock.XMLHttpRequest(); | ||
xhr.open('GET', 'http://first.call') | ||
xhr.send() | ||
xhr.onreadystatechange() | ||
|
||
expect(callback.callCount).to.eql(1) | ||
expect(callback.args[0][0].url).to.eql('http://first.call') | ||
|
||
i.deinstrumentNetwork() | ||
i = createInstrumenter(callback, windowMock) | ||
i.instrumentNetwork() | ||
var xhr = new windowMock.XMLHttpRequest(); | ||
xhr.open('GET', new URL('http://second.call')) | ||
xhr.send() | ||
xhr.onreadystatechange() | ||
expect(callback.callCount).to.eql(2) | ||
expect(callback.args[1][0].url).to.eql('http://second.call/') | ||
|
||
done() | ||
}) | ||
|
||
it('should capture XHR requests with string URL', function (done) { | ||
var callback = sinon.spy(); | ||
var windowMock = { | ||
fetch: function () { return Promise.resolve() } | ||
} | ||
|
||
var i = createInstrumenter(callback, windowMock); | ||
i.instrumentNetwork() | ||
|
||
windowMock.fetch('http://first.call') | ||
expect(callback.callCount).to.eql(1) | ||
expect(callback.args[0][0].url).to.eql('http://first.call') | ||
|
||
i.deinstrumentNetwork() | ||
i = createInstrumenter(callback, windowMock) | ||
i.instrumentNetwork() | ||
|
||
windowMock.fetch(new URL('http://second.call')) | ||
expect(callback.callCount).to.eql(2) | ||
expect(callback.args[1][0].url).to.eql('http://second.call/') | ||
|
||
done() | ||
}) | ||
}) | ||
|
||
function createInstrumenter(callback, windowMock) { | ||
return new Instrumenter({ scrubFields: [] }, { captureNetwork: callback }, { wrap: function () { }, client: { notifier: { diagnostic: {} } } }, windowMock); | ||
} |