Skip to content

Commit 90e5528

Browse files
committed
feat: Make more private + fix integration tests with synthetic
1 parent d33b91d commit 90e5528

File tree

5 files changed

+140
-140
lines changed

5 files changed

+140
-140
lines changed

packages/browser/test/integration/test.js

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -641,8 +641,8 @@ for (var idx in frames) {
641641
assert.equal(sentryData[0].exception.values[0].value, 'test2');
642642
assert.equal(sentryData[0].exception.values[0].type, 'Error');
643643
assert.isAtLeast(sentryData[0].exception.values[0].stacktrace.frames.length, 1);
644-
assert.equal(sentryData[0].exception.mechanism.handled, false);
645-
assert.equal(sentryData[0].exception.mechanism.type, 'onunhandledrejection');
644+
assert.equal(sentryData[0].exception.values[0].mechanism.handled, false);
645+
assert.equal(sentryData[0].exception.values[0].mechanism.type, 'onunhandledrejection');
646646
done();
647647
} else {
648648
// This test will be skipped if it's not Chrome Desktop
@@ -670,8 +670,8 @@ for (var idx in frames) {
670670
assert.equal(sentryData[0].exception.values[0].value, '"test"');
671671
assert.equal(sentryData[0].exception.values[0].type, 'UnhandledRejection');
672672
assert.equal(sentryData[0].exception.values[0].stacktrace, undefined);
673-
assert.equal(sentryData[0].exception.mechanism.handled, false);
674-
assert.equal(sentryData[0].exception.mechanism.type, 'onunhandledrejection');
673+
assert.equal(sentryData[0].exception.values[0].mechanism.handled, false);
674+
assert.equal(sentryData[0].exception.values[0].mechanism.type, 'onunhandledrejection');
675675
done();
676676
} else {
677677
// This test will be skipped if it's not Chrome Desktop
@@ -699,8 +699,8 @@ for (var idx in frames) {
699699
assert.isAtMost(sentryData[0].exception.values[0].value.length, 303);
700700
assert.equal(sentryData[0].exception.values[0].type, 'UnhandledRejection');
701701
assert.equal(sentryData[0].exception.values[0].stacktrace, undefined);
702-
assert.equal(sentryData[0].exception.mechanism.handled, false);
703-
assert.equal(sentryData[0].exception.mechanism.type, 'onunhandledrejection');
702+
assert.equal(sentryData[0].exception.values[0].mechanism.handled, false);
703+
assert.equal(sentryData[0].exception.values[0].mechanism.type, 'onunhandledrejection');
704704
done();
705705
} else {
706706
// This test will be skipped if it's not Chrome Desktop
@@ -728,8 +728,8 @@ for (var idx in frames) {
728728
assert.equal(sentryData[0].exception.values[0].value, '{"a":"b"}');
729729
assert.equal(sentryData[0].exception.values[0].type, 'UnhandledRejection');
730730
assert.equal(sentryData[0].exception.values[0].stacktrace, undefined);
731-
assert.equal(sentryData[0].exception.mechanism.handled, false);
732-
assert.equal(sentryData[0].exception.mechanism.type, 'onunhandledrejection');
731+
assert.equal(sentryData[0].exception.values[0].mechanism.handled, false);
732+
assert.equal(sentryData[0].exception.values[0].mechanism.type, 'onunhandledrejection');
733733
done();
734734
} else {
735735
// This test will be skipped if it's not Chrome Desktop
@@ -764,8 +764,8 @@ for (var idx in frames) {
764764
assert.isAtMost(sentryData[0].exception.values[0].value.length, 303);
765765
assert.equal(sentryData[0].exception.values[0].type, 'UnhandledRejection');
766766
assert.equal(sentryData[0].exception.values[0].stacktrace, undefined);
767-
assert.equal(sentryData[0].exception.mechanism.handled, false);
768-
assert.equal(sentryData[0].exception.mechanism.type, 'onunhandledrejection');
767+
assert.equal(sentryData[0].exception.values[0].mechanism.handled, false);
768+
assert.equal(sentryData[0].exception.values[0].mechanism.type, 'onunhandledrejection');
769769
done();
770770
} else {
771771
// This test will be skipped if it's not Chrome Desktop
@@ -888,20 +888,20 @@ for (var idx in frames) {
888888
if (IS_LOADER) {
889889
// The async loader doesn't wrap setTimeout
890890
// so we don't receive the full mechanism
891-
assert.ok(sentryData.exception.mechanism);
891+
assert.ok(sentryData.exception.values[0].mechanism);
892892
return done();
893893
}
894894

895-
var fn = sentryData.exception.mechanism.data.function;
896-
delete sentryData.exception.mechanism.data;
895+
var fn = sentryData.exception.values[0].mechanism.data.function;
896+
delete sentryData.exception.values[0].mechanism.data;
897897

898898
if (canReadFunctionName()) {
899899
assert.equal(fn, 'setTimeout');
900900
} else {
901901
assert.equal(fn, '<anonymous>');
902902
}
903903

904-
assert.deepEqual(sentryData.exception.mechanism, {
904+
assert.deepEqual(sentryData.exception.values[0].mechanism, {
905905
type: 'instrument',
906906
handled: true,
907907
});
@@ -938,14 +938,14 @@ for (var idx in frames) {
938938
if (IS_LOADER) {
939939
// The async loader doesn't wrap addEventListener
940940
// so we don't receive the full mechanism
941-
assert.ok(sentryData.exception.mechanism);
941+
assert.ok(sentryData.exception.values[0].mechanism);
942942
return done();
943943
}
944944

945-
var handler = sentryData.exception.mechanism.data.handler;
946-
delete sentryData.exception.mechanism.data.handler;
947-
var target = sentryData.exception.mechanism.data.target;
948-
delete sentryData.exception.mechanism.data.target;
945+
var handler = sentryData.exception.values[0].mechanism.data.handler;
946+
delete sentryData.exception.values[0].mechanism.data.handler;
947+
var target = sentryData.exception.values[0].mechanism.data.target;
948+
delete sentryData.exception.values[0].mechanism.data.target;
949949

950950
if (canReadFunctionName()) {
951951
assert.equal(handler, 'namedFunction');
@@ -955,7 +955,7 @@ for (var idx in frames) {
955955

956956
// IE vs. Rest of the world
957957
assert.oneOf(target, ['Node', 'EventTarget']);
958-
assert.deepEqual(sentryData.exception.mechanism, {
958+
assert.deepEqual(sentryData.exception.values[0].mechanism, {
959959
type: 'instrument',
960960
handled: true,
961961
data: {
@@ -994,16 +994,16 @@ for (var idx in frames) {
994994

995995
if (IS_LOADER) {
996996
// The async loader doesn't wrap
997-
assert.ok(sentryData.exception.mechanism);
997+
assert.ok(sentryData.exception.values[0].mechanism);
998998
return done();
999999
}
10001000

1001-
var target = sentryData.exception.mechanism.data.target;
1002-
delete sentryData.exception.mechanism.data.target;
1001+
var target = sentryData.exception.values[0].mechanism.data.target;
1002+
delete sentryData.exception.values[0].mechanism.data.target;
10031003

10041004
// IE vs. Rest of the world
10051005
assert.oneOf(target, ['Node', 'EventTarget']);
1006-
assert.deepEqual(sentryData.exception.mechanism, {
1006+
assert.deepEqual(sentryData.exception.values[0].mechanism, {
10071007
type: 'instrument',
10081008
handled: true,
10091009
data: {

packages/core/src/integrations/dedupe.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export class Dedupe implements Integration {
2929
if (self) {
3030
// Juuust in case something goes wrong
3131
try {
32-
if (self.shouldDropEvent(currentEvent, self._previousEvent)) {
32+
if (self._shouldDropEvent(currentEvent, self._previousEvent)) {
3333
return null;
3434
}
3535
} catch (_oO) {
@@ -43,7 +43,7 @@ export class Dedupe implements Integration {
4343
}
4444

4545
/** JSDoc */
46-
public shouldDropEvent(currentEvent: Event, previousEvent?: Event): boolean {
46+
private _shouldDropEvent(currentEvent: Event, previousEvent?: Event): boolean {
4747
if (!previousEvent) {
4848
return false;
4949
}

packages/core/src/integrations/inboundfilters.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ export class InboundFilters implements Integration {
4242
if (self) {
4343
const client = hub.getClient() as Client;
4444
const clientOptions = client ? client.getOptions() : {};
45-
const options = self.mergeOptions(clientOptions);
46-
if (self.shouldDropEvent(event, options)) {
45+
const options = self._mergeOptions(clientOptions);
46+
if (self._shouldDropEvent(event, options)) {
4747
return null;
4848
}
4949
}
@@ -52,26 +52,26 @@ export class InboundFilters implements Integration {
5252
}
5353

5454
/** JSDoc */
55-
public shouldDropEvent(event: Event, options: InboundFiltersOptions): boolean {
56-
if (this.isSentryError(event, options)) {
55+
private _shouldDropEvent(event: Event, options: InboundFiltersOptions): boolean {
56+
if (this._isSentryError(event, options)) {
5757
logger.warn(`Event dropped due to being internal Sentry Error.\nEvent: ${getEventDescription(event)}`);
5858
return true;
5959
}
60-
if (this.isIgnoredError(event, options)) {
60+
if (this._isIgnoredError(event, options)) {
6161
logger.warn(
6262
`Event dropped due to being matched by \`ignoreErrors\` option.\nEvent: ${getEventDescription(event)}`,
6363
);
6464
return true;
6565
}
66-
if (this.isBlacklistedUrl(event, options)) {
66+
if (this._isBlacklistedUrl(event, options)) {
6767
logger.warn(
6868
`Event dropped due to being matched by \`blacklistUrls\` option.\nEvent: ${getEventDescription(
6969
event,
7070
)}.\nUrl: ${this._getEventFilterUrl(event)}`,
7171
);
7272
return true;
7373
}
74-
if (!this.isWhitelistedUrl(event, options)) {
74+
if (!this._isWhitelistedUrl(event, options)) {
7575
logger.warn(
7676
`Event dropped due to not being matched by \`whitelistUrls\` option.\nEvent: ${getEventDescription(
7777
event,
@@ -83,7 +83,7 @@ export class InboundFilters implements Integration {
8383
}
8484

8585
/** JSDoc */
86-
public isSentryError(event: Event, options: InboundFiltersOptions = {}): boolean {
86+
private _isSentryError(event: Event, options: InboundFiltersOptions = {}): boolean {
8787
if (!options.ignoreInternal) {
8888
return false;
8989
}
@@ -97,7 +97,7 @@ export class InboundFilters implements Integration {
9797
}
9898

9999
/** JSDoc */
100-
public isIgnoredError(event: Event, options: InboundFiltersOptions = {}): boolean {
100+
private _isIgnoredError(event: Event, options: InboundFiltersOptions = {}): boolean {
101101
if (!options.ignoreErrors || !options.ignoreErrors.length) {
102102
return false;
103103
}
@@ -109,7 +109,7 @@ export class InboundFilters implements Integration {
109109
}
110110

111111
/** JSDoc */
112-
public isBlacklistedUrl(event: Event, options: InboundFiltersOptions = {}): boolean {
112+
private _isBlacklistedUrl(event: Event, options: InboundFiltersOptions = {}): boolean {
113113
// TODO: Use Glob instead?
114114
if (!options.blacklistUrls || !options.blacklistUrls.length) {
115115
return false;
@@ -119,7 +119,7 @@ export class InboundFilters implements Integration {
119119
}
120120

121121
/** JSDoc */
122-
public isWhitelistedUrl(event: Event, options: InboundFiltersOptions = {}): boolean {
122+
private _isWhitelistedUrl(event: Event, options: InboundFiltersOptions = {}): boolean {
123123
// TODO: Use Glob instead?
124124
if (!options.whitelistUrls || !options.whitelistUrls.length) {
125125
return true;
@@ -129,7 +129,7 @@ export class InboundFilters implements Integration {
129129
}
130130

131131
/** JSDoc */
132-
public mergeOptions(clientOptions: InboundFiltersOptions = {}): InboundFiltersOptions {
132+
private _mergeOptions(clientOptions: InboundFiltersOptions = {}): InboundFiltersOptions {
133133
return {
134134
blacklistUrls: [...(this._options.blacklistUrls || []), ...(clientOptions.blacklistUrls || [])],
135135
ignoreErrors: [

packages/core/test/lib/integrations/dedupe.test.ts

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -57,35 +57,35 @@ describe('Dedupe', () => {
5757
describe('shouldDropEvent(messageEvent)', () => {
5858
it('should not drop if there was no previous event', () => {
5959
const event = clone(messageEvent);
60-
expect(dedupe.shouldDropEvent(event)).toBe(false);
60+
expect((dedupe as any)._shouldDropEvent(event)).toBe(false);
6161
});
6262

6363
it('should not drop if events have different messages', () => {
6464
const eventA = clone(messageEvent);
6565
const eventB = clone(messageEvent);
6666
eventB.message = 'EvilMorty';
67-
expect(dedupe.shouldDropEvent(eventA, eventB)).toBe(false);
67+
expect((dedupe as any)._shouldDropEvent(eventA, eventB)).toBe(false);
6868
});
6969

7070
it('should not drop if events have same messages, but different stacktraces', () => {
7171
const eventA = clone(messageEvent);
7272
const eventB = clone(messageEvent);
7373
eventB.stacktrace.frames[0].colno = 1337;
74-
expect(dedupe.shouldDropEvent(eventA, eventB)).toBe(false);
74+
expect((dedupe as any)._shouldDropEvent(eventA, eventB)).toBe(false);
7575
});
7676

7777
it('should drop if there are two events with same messages and no fingerprints', () => {
7878
const eventA = clone(messageEvent);
7979
delete eventA.fingerprint;
8080
const eventB = clone(messageEvent);
8181
delete eventB.fingerprint;
82-
expect(dedupe.shouldDropEvent(eventA, eventB)).toBe(true);
82+
expect((dedupe as any)._shouldDropEvent(eventA, eventB)).toBe(true);
8383
});
8484

8585
it('should drop if there are two events with same messages and same fingerprints', () => {
8686
const eventA = clone(messageEvent);
8787
const eventB = clone(messageEvent);
88-
expect(dedupe.shouldDropEvent(eventA, eventB)).toBe(true);
88+
expect((dedupe as any)._shouldDropEvent(eventA, eventB)).toBe(true);
8989
});
9090

9191
it('should not drop if there are two events with same message but different fingerprints', () => {
@@ -94,56 +94,56 @@ describe('Dedupe', () => {
9494
eventA.fingerprint = ['Birdperson'];
9595
const eventC = clone(messageEvent);
9696
delete eventC.fingerprint;
97-
expect(dedupe.shouldDropEvent(eventA, eventB)).toBe(false);
98-
expect(dedupe.shouldDropEvent(eventA, eventC)).toBe(false);
99-
expect(dedupe.shouldDropEvent(eventB, eventC)).toBe(false);
97+
expect((dedupe as any)._shouldDropEvent(eventA, eventB)).toBe(false);
98+
expect((dedupe as any)._shouldDropEvent(eventA, eventC)).toBe(false);
99+
expect((dedupe as any)._shouldDropEvent(eventB, eventC)).toBe(false);
100100
});
101101
});
102102

103103
describe('shouldDropEvent(exceptionEvent)', () => {
104104
it('should not drop if there was no previous event', () => {
105105
const event = clone(exceptionEvent);
106-
expect(dedupe.shouldDropEvent(event)).toBe(false);
106+
expect((dedupe as any)._shouldDropEvent(event)).toBe(false);
107107
});
108108

109109
it('should drop when events type, value and stacktrace are the same', () => {
110110
const event = clone(exceptionEvent);
111-
expect(dedupe.shouldDropEvent(event, event)).toBe(true);
111+
expect((dedupe as any)._shouldDropEvent(event, event)).toBe(true);
112112
});
113113

114114
it('should not drop if types are different', () => {
115115
const eventA = clone(exceptionEvent);
116116
const eventB = clone(exceptionEvent);
117117
eventB.exception.values[0].type = 'TypeError';
118-
expect(dedupe.shouldDropEvent(eventA, eventB)).toBe(false);
118+
expect((dedupe as any)._shouldDropEvent(eventA, eventB)).toBe(false);
119119
});
120120

121121
it('should not drop if values are different', () => {
122122
const eventA = clone(exceptionEvent);
123123
const eventB = clone(exceptionEvent);
124124
eventB.exception.values[0].value = 'Expected number, got string';
125-
expect(dedupe.shouldDropEvent(eventA, eventB)).toBe(false);
125+
expect((dedupe as any)._shouldDropEvent(eventA, eventB)).toBe(false);
126126
});
127127

128128
it('should not drop if stacktraces are different', () => {
129129
const eventA = clone(exceptionEvent);
130130
const eventB = clone(exceptionEvent);
131131
eventB.exception.values[0].stacktrace.frames[0].colno = 1337;
132-
expect(dedupe.shouldDropEvent(eventA, eventB)).toBe(false);
132+
expect((dedupe as any)._shouldDropEvent(eventA, eventB)).toBe(false);
133133
});
134134

135135
it('should drop if there are two events with same exception and no fingerprints', () => {
136136
const eventA = clone(exceptionEvent);
137137
delete eventA.fingerprint;
138138
const eventB = clone(exceptionEvent);
139139
delete eventB.fingerprint;
140-
expect(dedupe.shouldDropEvent(eventA, eventB)).toBe(true);
140+
expect((dedupe as any)._shouldDropEvent(eventA, eventB)).toBe(true);
141141
});
142142

143143
it('should drop if there are two events with same exception and same fingerprints', () => {
144144
const eventA = clone(exceptionEvent);
145145
const eventB = clone(exceptionEvent);
146-
expect(dedupe.shouldDropEvent(eventA, eventB)).toBe(true);
146+
expect((dedupe as any)._shouldDropEvent(eventA, eventB)).toBe(true);
147147
});
148148

149149
it('should not drop if there are two events with same exception but different fingerprints', () => {
@@ -152,9 +152,9 @@ describe('Dedupe', () => {
152152
eventA.fingerprint = ['Birdperson'];
153153
const eventC = clone(exceptionEvent);
154154
delete eventC.fingerprint;
155-
expect(dedupe.shouldDropEvent(eventA, eventB)).toBe(false);
156-
expect(dedupe.shouldDropEvent(eventA, eventC)).toBe(false);
157-
expect(dedupe.shouldDropEvent(eventB, eventC)).toBe(false);
155+
expect((dedupe as any)._shouldDropEvent(eventA, eventB)).toBe(false);
156+
expect((dedupe as any)._shouldDropEvent(eventA, eventC)).toBe(false);
157+
expect((dedupe as any)._shouldDropEvent(eventB, eventC)).toBe(false);
158158
});
159159
});
160160
});

0 commit comments

Comments
 (0)