-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
feat: node transports #1414
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
Merged
Merged
feat: node transports #1414
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
ae2f1ce
feat: Introduce SentryResponse, Status, move to types
HazAT bafef7c
feat: Expose sdkinfo, Add auth header
HazAT 6d420b4
feat: Add more tests for node transports
HazAT 5daf4b8
fix: Use new lerna to make version bumping work
HazAT f6ec12a
fix: tests
HazAT 8ba527c
fix: lint
HazAT b39a636
fix: lint
HazAT File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
---|---|---|
@@ -1,7 +1,6 @@ | ||
import { Transport } from '@sentry/types'; | ||
import { expect } from 'chai'; | ||
import { SinonStub, stub } from 'sinon'; | ||
import { FetchTransport } from '../../src/transports/fetch'; | ||
import { Status, Transports } from '../../src'; | ||
|
||
const testDSN = 'https://[email protected]/42'; | ||
const transportUrl = | ||
|
@@ -15,12 +14,12 @@ const payload = { | |
}; | ||
|
||
let fetch: SinonStub; | ||
let transport: Transport; | ||
let transport: Transports.BaseTransport; | ||
|
||
describe('FetchTransport', () => { | ||
beforeEach(() => { | ||
fetch = stub(window, 'fetch'); | ||
transport = new FetchTransport({ dsn: testDSN }); | ||
transport = new Transports.FetchTransport({ dsn: testDSN }); | ||
}); | ||
|
||
afterEach(() => { | ||
|
@@ -33,14 +32,13 @@ describe('FetchTransport', () => { | |
|
||
describe('send()', async () => { | ||
it('sends a request to Sentry servers', async () => { | ||
const response = new Response('', { | ||
status: 200, | ||
}); | ||
const response = { status: 200 }; | ||
|
||
fetch.returns(Promise.resolve(response)); | ||
|
||
return transport.send(payload).then(res => { | ||
expect(res.status).equal(200); | ||
expect(res.code).equal(200); | ||
expect(res.status).equal(Status.Success); | ||
expect(fetch.calledOnce).equal(true); | ||
expect( | ||
fetch.calledWith(transportUrl, { | ||
|
@@ -54,9 +52,7 @@ describe('FetchTransport', () => { | |
}); | ||
|
||
it('rejects with non-200 status code', async () => { | ||
const response = new Response('', { | ||
status: 403, | ||
}); | ||
const response = { status: 403 }; | ||
|
||
fetch.returns(Promise.reject(response)); | ||
|
||
|
This file contains hidden or 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 |
---|---|---|
@@ -1,7 +1,6 @@ | ||
import { Transport } from '@sentry/types'; | ||
import { expect } from 'chai'; | ||
import { fakeServer, SinonFakeServer } from 'sinon'; | ||
import { XHRTransport } from '../../src/transports/xhr'; | ||
import { Transports } from '../../src'; | ||
|
||
const testDSN = 'https://[email protected]/42'; | ||
const transportUrl = | ||
|
@@ -15,13 +14,13 @@ const payload = { | |
}; | ||
|
||
let server: SinonFakeServer; | ||
let transport: Transport; | ||
let transport: Transports.BaseTransport; | ||
|
||
describe('XHRTransport', () => { | ||
beforeEach(() => { | ||
server = fakeServer.create(); | ||
server.respondImmediately = true; | ||
transport = new XHRTransport({ dsn: testDSN }); | ||
transport = new Transports.XHRTransport({ dsn: testDSN }); | ||
}); | ||
|
||
afterEach(() => { | ||
|
@@ -37,7 +36,7 @@ describe('XHRTransport', () => { | |
server.respondWith('POST', transportUrl, [200, {}, '']); | ||
|
||
return transport.send(payload).then(res => { | ||
expect(res.status).equal(200); | ||
expect(res.code).equal(200); | ||
|
||
const request = server.requests[0]; | ||
expect(server.requests.length).equal(1); | ||
|
@@ -46,16 +45,17 @@ describe('XHRTransport', () => { | |
}); | ||
}); | ||
|
||
it('rejects with non-200 status code', async () => { | ||
it('rejects with non-200 status code', done => { | ||
server.respondWith('POST', transportUrl, [403, {}, '']); | ||
|
||
return transport.send(payload).catch(res => { | ||
transport.send(payload).catch(res => { | ||
expect(res.status).equal(403); | ||
|
||
const request = server.requests[0]; | ||
expect(server.requests.length).equal(1); | ||
expect(request.method).equal('POST'); | ||
expect(JSON.parse(request.requestBody)).deep.equal(payload); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It'll break if
fetch
throws. We should put it intry/catch
clause I guessThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or will
async
wrap it inreject
call? 🤔There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
async
handles everything 💪