Skip to content

Commit 8db6659

Browse files
committed
Fix tests
1 parent ed65564 commit 8db6659

File tree

5 files changed

+18
-19
lines changed

5 files changed

+18
-19
lines changed

packages/browser/src/client.ts

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { BaseClient, Scope, SDK_VERSION } from '@sentry/core';
22
import { AttachmentItem, ClientOptions, Event, EventHint, Options, Severity, SeverityLevel } from '@sentry/types';
3-
import { attachmentItemFromAttachment, getGlobalObject, logger } from '@sentry/utils';
3+
import { getGlobalObject, logger } from '@sentry/utils';
44

55
import { eventFromException, eventFromMessage } from './eventbuilder';
66
import { IS_DEBUG_BUILD } from './flags';
@@ -122,11 +122,4 @@ export class BrowserClient extends BaseClient<BrowserClientOptions> {
122122
}
123123
super._sendEvent(event, attachments);
124124
}
125-
126-
/**
127-
* @inheritDoc
128-
*/
129-
protected _getAttachments(scope: Scope | undefined): AttachmentItem[] {
130-
return (scope?.getAttachments() || []).map(a => attachmentItemFromAttachment(a));
131-
}
132125
}

packages/core/src/baseclient.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import {
1616
Transport,
1717
} from '@sentry/types';
1818
import {
19+
attachmentItemFromAttachment,
1920
checkOrSetAlreadyCaught,
2021
dateTimestampInSeconds,
2122
isPlainObject,
@@ -656,6 +657,11 @@ export abstract class BaseClient<O extends ClientOptions> implements Client<O> {
656657
);
657658
}
658659

660+
/** */
661+
protected _getAttachments(scope: Scope | undefined): AttachmentItem[] {
662+
return (scope?.getAttachments() || []).map(a => attachmentItemFromAttachment(a));
663+
}
664+
659665
/**
660666
* @inheritDoc
661667
*/
@@ -671,9 +677,6 @@ export abstract class BaseClient<O extends ClientOptions> implements Client<O> {
671677
_level?: Severity | SeverityLevel,
672678
_hint?: EventHint,
673679
): PromiseLike<Event>;
674-
675-
/** */
676-
protected abstract _getAttachments(scope: Scope | undefined): AttachmentItem[];
677680
}
678681

679682
/**

packages/node/src/client.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ export class NodeClient extends BaseClient<NodeClientOptions> {
155155
* @inheritDoc
156156
*/
157157
protected _getAttachments(scope: Scope | undefined): AttachmentItem[] {
158-
// TODO: load attachment from path...
158+
// TODO: load any attachments from paths...
159159
return (scope?.getAttachments() || []).map(a => attachmentItemFromAttachment(a));
160160
}
161161
}

packages/utils/src/envelope.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,10 @@ export function serializeEnvelope(envelope: Envelope): string | Uint8Array {
4747
return hasBinaryAttachment ? serializeBinaryEnvelope(envelope) : serializeStringEnvelope(envelope);
4848
}
4949

50-
function serializeStringEnvelope(envelope: Envelope): string {
50+
/**
51+
* Serializes an envelope to a string.
52+
*/
53+
export function serializeStringEnvelope(envelope: Envelope): string {
5154
const [headers, items] = envelope;
5255
const serializedHeaders = JSON.stringify(headers);
5356

packages/utils/test/envelope.test.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { EventEnvelope } from '@sentry/types';
22

3-
import { addItemToEnvelope, createEnvelope, getEnvelopeType, serializeEnvelope } from '../src/envelope';
3+
import { addItemToEnvelope, createEnvelope, getEnvelopeType, serializeStringEnvelope } from '../src/envelope';
44
import { parseEnvelope } from './testutils';
55

66
describe('envelope', () => {
@@ -17,10 +17,10 @@ describe('envelope', () => {
1717
});
1818
});
1919

20-
describe('serializeEnvelope()', () => {
20+
describe('serializeStringEnvelope()', () => {
2121
it('serializes an envelope', () => {
2222
const env = createEnvelope<EventEnvelope>({ event_id: 'aa3ff046696b4bc6b609ce6d28fde9e2', sent_at: '123' }, []);
23-
expect(serializeEnvelope(env)).toMatchInlineSnapshot(
23+
expect(serializeStringEnvelope(env)).toMatchInlineSnapshot(
2424
'"{\\"event_id\\":\\"aa3ff046696b4bc6b609ce6d28fde9e2\\",\\"sent_at\\":\\"123\\"}"',
2525
);
2626
});
@@ -29,15 +29,15 @@ describe('envelope', () => {
2929
describe('addItemToEnvelope()', () => {
3030
it('adds an item to an envelope', () => {
3131
const env = createEnvelope<EventEnvelope>({ event_id: 'aa3ff046696b4bc6b609ce6d28fde9e2', sent_at: '123' }, []);
32-
const parsedEnvelope = parseEnvelope(serializeEnvelope(env));
32+
const parsedEnvelope = parseEnvelope(serializeStringEnvelope(env));
3333
expect(parsedEnvelope).toHaveLength(1);
3434
expect(parsedEnvelope[0]).toEqual({ event_id: 'aa3ff046696b4bc6b609ce6d28fde9e2', sent_at: '123' });
3535

3636
const newEnv = addItemToEnvelope<EventEnvelope>(env, [
3737
{ type: 'event' },
3838
{ event_id: 'aa3ff046696b4bc6b609ce6d28fde9e2' },
3939
]);
40-
const parsedNewEnvelope = parseEnvelope(serializeEnvelope(newEnv));
40+
const parsedNewEnvelope = parseEnvelope(serializeStringEnvelope(newEnv));
4141
expect(parsedNewEnvelope).toHaveLength(3);
4242
expect(parsedNewEnvelope[0]).toEqual({ event_id: 'aa3ff046696b4bc6b609ce6d28fde9e2', sent_at: '123' });
4343
expect(parsedNewEnvelope[1]).toEqual({ type: 'event' });
@@ -49,7 +49,7 @@ describe('envelope', () => {
4949
it('returns the type of the envelope', () => {
5050
const env = createEnvelope<EventEnvelope>({ event_id: 'aa3ff046696b4bc6b609ce6d28fde9e2', sent_at: '123' }, [
5151
[{ type: 'event' }, { event_id: 'aa3ff046696b4bc6b609ce6d28fde9e2' }],
52-
[{ type: 'attachment', filename: 'me.txt' }, '123456'],
52+
[{ type: 'attachment', filename: 'me.txt', length: 6 }, new Uint8Array(6)],
5353
]);
5454
expect(getEnvelopeType(env)).toEqual('event');
5555
});

0 commit comments

Comments
 (0)