-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(v7): Add
tunnel
support to multiplexed transport (#11851)
- Loading branch information
Showing
4 changed files
with
72 additions
and
21 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
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 |
---|---|---|
|
@@ -2,6 +2,7 @@ import { TextDecoder, TextEncoder } from 'util'; | |
import type { | ||
BaseTransportOptions, | ||
ClientReport, | ||
Envelope, | ||
EventEnvelope, | ||
EventItem, | ||
TransactionEvent, | ||
|
@@ -48,7 +49,7 @@ const CLIENT_REPORT_ENVELOPE = createClientReportEnvelope( | |
123456, | ||
); | ||
|
||
type Assertion = (url: string, release: string | undefined, body: string | Uint8Array) => void; | ||
type Assertion = (url: string, release: string | undefined, body: Envelope) => void; | ||
|
||
const createTestTransport = (...assertions: Assertion[]): ((options: BaseTransportOptions) => Transport) => { | ||
return (options: BaseTransportOptions) => | ||
|
@@ -59,9 +60,10 @@ const createTestTransport = (...assertions: Assertion[]): ((options: BaseTranspo | |
throw new Error('No assertion left'); | ||
} | ||
|
||
const event = eventFromEnvelope(parseEnvelope(request.body, new TextEncoder(), new TextDecoder()), ['event']); | ||
const env = parseEnvelope(request.body, new TextEncoder(), new TextDecoder()); | ||
const event = eventFromEnvelope(env, ['event']); | ||
|
||
assertion(options.url, event?.release, request.body); | ||
assertion(options.url, event?.release, env); | ||
resolve({ statusCode: 200 }); | ||
}); | ||
}); | ||
|
@@ -107,11 +109,12 @@ describe('makeMultiplexedTransport', () => { | |
}); | ||
|
||
it('DSN can be overridden via match callback', async () => { | ||
expect.assertions(1); | ||
expect.assertions(2); | ||
|
||
const makeTransport = makeMultiplexedTransport( | ||
createTestTransport(url => { | ||
createTestTransport((url, _, env) => { | ||
expect(url).toBe(DSN2_URL); | ||
expect(env[0].dsn).toBe(DSN2); | ||
}), | ||
() => [DSN2], | ||
); | ||
|
@@ -121,12 +124,13 @@ describe('makeMultiplexedTransport', () => { | |
}); | ||
|
||
it('DSN and release can be overridden via match callback', async () => { | ||
expect.assertions(2); | ||
expect.assertions(3); | ||
|
||
const makeTransport = makeMultiplexedTransport( | ||
createTestTransport((url, release) => { | ||
createTestTransport((url, release, env) => { | ||
expect(url).toBe(DSN2_URL); | ||
expect(release).toBe('[email protected]'); | ||
expect(env[0].dsn).toBe(DSN2); | ||
}), | ||
() => [{ dsn: DSN2, release: '[email protected]' }], | ||
); | ||
|
@@ -135,6 +139,22 @@ describe('makeMultiplexedTransport', () => { | |
await transport.send(ERROR_ENVELOPE); | ||
}); | ||
|
||
it('URL can be overridden by tunnel option', async () => { | ||
expect.assertions(3); | ||
|
||
const makeTransport = makeMultiplexedTransport( | ||
createTestTransport((url, release, env) => { | ||
expect(url).toBe('http://google.com'); | ||
expect(release).toBe('[email protected]'); | ||
expect(env[0].dsn).toBe(DSN2); | ||
}), | ||
() => [{ dsn: DSN2, release: '[email protected]' }], | ||
); | ||
|
||
const transport = makeTransport({ url: DSN1_URL, ...transportOptions, tunnel: 'http://google.com' }); | ||
await transport.send(ERROR_ENVELOPE); | ||
}); | ||
|
||
it('match callback can return multiple DSNs', async () => { | ||
expect.assertions(2); | ||
|
||
|
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