8000 Fix broken native integrations and karma tests config · lordnox/sentry-javascript@8cde53b · GitHub
[go: up one dir, main page]

Skip to content
This repository was archived by the owner on Jan 8, 2025. It is now read-only.

Commit 8cde53b

Browse files
committed
Fix broken native integrations and karma tests config
1 parent 7f9908a commit 8cde53b

File tree

8 files changed

+36
-32
lines changed

8 files changed

+36
-32
lines changed

packages/browser/karma.config.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,17 @@ module.exports = function(config) {
99
reporters: ['mocha', 'karma-typescript'],
1010

1111
basePath: process.cwd(),
12-
files: ['test/**/*.ts', 'src/**/*.ts'],
12+
files: ['test/**/*.ts', 'src/**/*.+(js|ts)'],
1313
preprocessors: {
14-
'**/*.ts': ['karma-typescript'],
14+
'**/*.+(js|ts)': ['karma-typescript'],
1515
},
1616

1717
karmaTypescriptConfig: {
1818
tsconfig: 'tsconfig.json',
19+
compilerOptions: {
20+
declaration: false,
21+
allowJs: true,
22+
},
1923
bundlerOptions: {
2024
sourceMap: true,
2125
transforms: [require('karma-typescript-es6-transform')()],

packages/browser/src/integrations/globalhandlers.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export class GlobalHandlers implements Integration {
1616
*/
1717
public name: string = 'GlobalHandlers';
1818
public constructor(
19-
private options: {
19+
private readonly options: {
2020
onerror: boolean;
2121
onunhandledrejection: boolean;
2222
} = {

packages/browser/src/integrations/trycatch.ts

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export class TryCatch implements Integration {
1515

1616
/** JSDoc */
1717
private wrapTimeFunction(original: () => void): () => number {
18-
return (...args: any[]): number => {
18+
return function(this: any, ...args: any[]): number {
1919
const originalCallback = args[0];
2020
args[0] = wrap(originalCallback, {
2121
mechanism: {
@@ -29,8 +29,8 @@ export class TryCatch implements Integration {
2929

3030
/** JSDoc */
3131
private wrapRAF(original: any): (callback: () => void) => any {
32-
return (callback: () => void) =>
33-
original(
32+
return function(this: any, callback: () => void): () => void {
33+
return original(
3434
wrap(callback, {
3535
mechanism: {
3636
data: {
@@ -41,6 +41,7 @@ export class TryCatch implements Integration {
4141
},
4242
}),
4343
);
44+
};
4445
}
4546

4647
/** JSDoc */
@@ -52,17 +53,15 @@ export class TryCatch implements Integration {
5253
return;
5354
}
5455

55-
fill(
56-
proto,
57-
'addEventListener',
58-
(
59-
original: () => void,
60-
): ((eventName: string, fn: EventListenerObject, capture?: boolean, secure?: boolean) => any) => (
56+
fill(proto, 'addEventListener', function(
57+
original: () => void,
58+
): (eventName: string, fn: EventListenerObject, options?: boolean | AddEventListenerOptions) => void {
59+
return function(
60+
this: any,
6161
eventName: string,
6262
fn: EventListenerObject,
63-
capture?: boolean,
64-
secure?: boolean,
65-
): any => {
63+
options?: boolean | AddEventListenerOptions,
64+
): (eventName: string, fn: EventListenerObject, capture?: boolean, secure?: boolean) => void {
6665
try {
6766
fn.handleEvent = wrap(fn.handleEvent.bind(fn), {
6867
mechanism: {
@@ -130,29 +129,27 @@ export class TryCatch implements Integration {
130129
},
131130
before,
132131
),
133-
capture,
134-
secure,
132+
options,
135133
);
136-
},
137-
);
134+
};
135+
});
138136

139137
fill(prot F438 o, 'removeEventListener', function(
140138
original: () => void,
141-
): (this: any, eventName: string, fn: EventListenerObject, capture?: boolean, secure?: boolean) => () => void {
139+
): (this: any, eventName: string, fn: EventListenerObject, options?: boolean | EventListenerOptions) => () => void {
142140
return function(
143141
this: any,
144142
eventName: string,
145143
fn: EventListenerObject,
146-
capture?: boolean,
147-
secure?: boolean,
144+
options?: boolean | EventListenerOptions,
148145
): () => void {
149146
let callback = (fn as any) as SentryWrappedFunction;
150147
try {
151148
callback = callback && (callback.__sentry_wrapper__ || callback);
152149
} catch (e) {
153150
// ignore, accessing __sentry_wrapper__ will throw in some Selenium environments
154151
}
155-
return original.call(this, eventName, callback, capture, secure);
152+
return original.call(this, eventName, callback, options);
156153
};
157154
});
158155
}

packages/browser/src/parsers.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ export function eventFromStacktrace(stacktrace: TraceKitStackTrace): SentryEvent
5353

5454
/** JSDoc */
5555
export function prepareFramesForEvent(stack: TraceKitStackFrame[]): StackFrame[] {
56-
if (!stack) {
56+
if (!stack || !stack.length) {
5757
return [];
5858
}
5959

packages/browser/test/index.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,10 +108,10 @@ describe('SentryBrowser', () => {
108108
new BrowserClient({
109109
afterSend: (event: SentryEvent) => {
110110
expect(event.exception).to.not.be.undefined;
111-
expect(event.exception!.values[0]).to.not.be.undefined;
112-
expect(event.exception!.values[0].type).to.equal('Error');
113-
expect(event.exception!.values[0].value).to.equal('test');
114-
expect(event.exception!.values[0].stacktrace).to.not.be.empty;
111+
expect(event.exception!.values![0]).to.not.be.undefined;
112+
expect(event.exception!.values![0].type).to.equal('Error');
113+
expect(event.exception!.values![0].value).to.equal('test');
114+
expect(event.exception!.values![0].stacktrace).to.not.be.empty;
115115
done();
116116
},
117117
dsn,

packages/core/test/lib/base.test.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ jest.mock('@sentry/utils/misc', () => ({
1010
uuid4(): string {
1111
return '42';
1212
},
13+
getGlobalObject(): object {
14+
return {};
15+
},
1316
}));
1417

1518
jest.mock('@sentry/utils/string', () => ({

packages/node/src/backend.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export class NodeBackend implements Backend {
2525
* @inheritDoc
2626
*/
2727
public async eventFromException(exception: any, syntheticException: Error | null): Promise<SentryEvent> {
28-
let ex: Error = exception;
28+
let ex: any = exception;
2929

3030
if (!isError(exception)) {
3131
if (isPlainObject(exception)) {
@@ -40,15 +40,15 @@ export class NodeBackend implements Backend {
4040
});
4141

4242
ex = syntheticException || new Error(message);
43-
ex.message = message;
43+
(ex as Error).message = message;
4444
} else {
4545
// This handles when someone does: `throw "something awesome";`
4646
// We use synthesized Error here so we can extract a (rough) stack trace.
4747
ex = syntheticException || new Error(exception as string);
4848
}
4949
}
5050

51-
const event: SentryEvent = await parseError(ex);
51+
const event: SentryEvent = await parseError(ex as Error);
5252

5353
return event;
5454
}

packages/node/src/parsers.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ export async function parseError(error: ExtendedError): Promise<SentryEvent> {
204204

205205
/** JSDoc */
206206
export function prepareFramesForEvent(stack: StackFrame[]): StackFrame[] {
207-
if (!stack) {
207+
if (!stack || !stack.length) {
208208
return [];
209209
}
210210

0 commit comments

Comments
 (0)
0