-
-
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.
ref(core): Actually ensure attachments are added to the envelope (#5159)
This patch fixes a bug where attachments were previously not added to the envelope that would be sent to Sentry. Additionally, it adds a test that ensures that the attachments actually make it into the raw envelope.
- Loading branch information
1 parent
36599a3
commit 747f1df
Showing
2 changed files
with
43 additions
and
2 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,38 @@ | ||
import { parseEnvelope } from '@sentry/utils/test/testutils'; | ||
import { TextEncoder } from 'util'; | ||
|
||
import { createTransport } from '../../src/transports/base'; | ||
import { getDefaultTestClientOptions, TestClient } from '../mocks/client'; | ||
|
||
describe('Attachments', () => { | ||
beforeEach(() => { | ||
TestClient.sendEventCalled = undefined; | ||
TestClient.instance = undefined; | ||
}); | ||
|
||
afterEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
test('actually end up in envelope', async () => { | ||
expect.assertions(4); | ||
|
||
const options = getDefaultTestClientOptions({ | ||
dsn: 'https://username@domain/123', | ||
enableSend: true, | ||
transport: () => | ||
createTransport({ recordDroppedEvent: () => undefined, textEncoder: new TextEncoder() }, async req => { | ||
const [, items] = parseEnvelope(req.body); | ||
expect(items.length).toEqual(2); | ||
// Second envelope item should be the attachment | ||
expect(items[1][0]).toEqual({ type: 'attachment', length: 50000, filename: 'empty.bin' }); | ||
expect(items[1][1]).toBeInstanceOf(Uint8Array); | ||
expect((items[1][1] as Uint8Array).length).toEqual(50_000); | ||
return {}; | ||
}), | ||
}); | ||
|
||
const client = new TestClient(options); | ||
client.captureEvent({}, { attachments: [{ filename: 'empty.bin', data: new Uint8Array(50_000) }] }); | ||
}); | ||
}); |