Skip to content

Commit 62649ef

Browse files
committed
fix tracekit tests
1 parent 1481855 commit 62649ef

File tree

9 files changed

+68
-54
lines changed

9 files changed

+68
-54
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// Convert an Error-like object into something TS recognizes as an `Error`, getting around read-only properties
2+
export function makeMockError(obj: { [key: string]: any; message: string; name: string; stack?: string }): Error {
3+
const anyObj = obj as any;
4+
anyObj.constructor = { name: obj.name };
5+
return anyObj as Error;
6+
}

packages/browser/test/unit/tracekit/chromium.test.ts

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import { exceptionFromError } from '../../../src/eventbuilder';
22
import { defaultStackParser as parser } from '../../../src/stack-parsers';
3+
import { makeMockError } from '../helper/error-object';
34

45
describe('Tracekit - Chrome Tests', () => {
56
it('should parse Chrome error with no location', () => {
67
const NO_LOCATION = { message: 'foo', name: 'bar', stack: 'error\n at Array.forEach (native)' };
7-
const ex = exceptionFromError(parser, NO_LOCATION);
8+
const ex = exceptionFromError(parser, makeMockError(NO_LOCATION));
89

910
expect(ex).toEqual({
1011
value: 'foo',
@@ -26,7 +27,7 @@ describe('Tracekit - Chrome Tests', () => {
2627
' at http://path/to/file.js:24:4',
2728
};
2829

29-
const ex = exceptionFromError(parser, CHROME_15);
30+
const ex = exceptionFromError(parser, makeMockError(CHROME_15));
3031

3132
expect(ex).toEqual({
3233
value: "Object #<Object> has no method 'undef'",
@@ -53,7 +54,7 @@ describe('Tracekit - Chrome Tests', () => {
5354
' at I.e.fn.(anonymous function) [as index] (http://localhost:8080/file.js:10:3651)',
5455
};
5556

56-
const ex = exceptionFromError(parser, CHROME_36);
57+
const ex = exceptionFromError(parser, makeMockError(CHROME_36));
5758

5859
expect(ex).toEqual({
5960
value: 'Default error',
@@ -99,7 +100,7 @@ describe('Tracekit - Chrome Tests', () => {
99100
' at TESTTESTTEST.proxiedMethod(webpack:///./~/react-proxy/modules/createPrototypeProxy.js?:44:30)',
100101
};
101102

102-
const ex = exceptionFromError(parser, CHROME_XX_WEBPACK);
103+
const ex = exceptionFromError(parser, makeMockError(CHROME_XX_WEBPACK));
103104

104105
expect(ex).toEqual({
105106
value: "Cannot read property 'error' of undefined",
@@ -152,7 +153,7 @@ describe('Tracekit - Chrome Tests', () => {
152153
'at http://localhost:8080/file.js:31:13\n',
153154
};
154155

155-
const ex = exceptionFromError(parser, CHROME_48_EVAL);
156+
const ex = exceptionFromError(parser, makeMockError(CHROME_48_EVAL));
156157

157158
expect(ex).toEqual({
158159
value: 'message string',
@@ -184,7 +185,7 @@ describe('Tracekit - Chrome Tests', () => {
184185
' at n.handle (blob:http%3A//localhost%3A8080/abfc40e9-4742-44ed-9dcd-af8f99a29379:7:2863)',
185186
};
186187

187-
const ex = exceptionFromError(parser, CHROME_48_BLOB);
188+
const ex = exceptionFromError(parser, makeMockError(CHROME_48_BLOB));
188189

189190
expect(ex).toEqual({
190191
value: 'Error: test',
@@ -247,7 +248,7 @@ describe('Tracekit - Chrome Tests', () => {
247248
at examplescheme://examplehost/cd351f7250857e22ceaa.worker.js:70179:15`,
248249
};
249250

250-
const ex = exceptionFromError(parser, CHROMIUM_EMBEDDED_FRAMEWORK_CUSTOM_SCHEME);
251+
const ex = exceptionFromError(parser, makeMockError(CHROMIUM_EMBEDDED_FRAMEWORK_CUSTOM_SCHEME));
251252

252253
expect(ex).toEqual({
253254
value: 'message string',
@@ -277,7 +278,7 @@ describe('Tracekit - Chrome Tests', () => {
277278
at http://localhost:5000/test:24:7`,
278279
};
279280

280-
const ex = exceptionFromError(parser, CHROME73_NATIVE_CODE_EXCEPTION);
281+
const ex = exceptionFromError(parser, makeMockError(CHROME73_NATIVE_CODE_EXCEPTION));
281282

282283
expect(ex).toEqual({
283284
value: 'test',
@@ -310,7 +311,7 @@ describe('Tracekit - Chrome Tests', () => {
310311
at http://localhost:5000/:50:19`,
311312
};
312313

313-
const ex = exceptionFromError(parser, CHROME73_EVAL_EXCEPTION);
314+
const ex = exceptionFromError(parser, makeMockError(CHROME73_EVAL_EXCEPTION));
314315

315316
expect(ex).toEqual({
316317
value: 'bad',
@@ -342,7 +343,7 @@ describe('Tracekit - Chrome Tests', () => {
342343
at test (http://localhost:5000/:33:23)`,
343344
};
344345

345-
const ex = exceptionFromError(parser, CHROME_109_ASYNC_URL);
346+
const ex = exceptionFromError(parser, makeMockError(CHROME_109_ASYNC_URL));
346347

347348
expect(ex).toEqual({
348349
value: 'bad',
@@ -368,7 +369,7 @@ describe('Tracekit - Chrome Tests', () => {
368369
at Global code (http://localhost:5000/test:24:7)`,
369370
};
370371

371-
const ex = exceptionFromError(parser, EDGE44_NATIVE_CODE_EXCEPTION);
372+
const ex = exceptionFromError(parser, makeMockError(EDGE44_NATIVE_CODE_EXCEPTION));
372373

373374
expect(ex).toEqual({
374375
value: 'test',
@@ -401,7 +402,7 @@ describe('Tracekit - Chrome Tests', () => {
401402
at Anonymous function (http://localhost:5000/:50:8)`,
402403
};
403404

404-
const ex = exceptionFromError(parser, EDGE44_EVAL_EXCEPTION);
405+
const ex = exceptionFromError(parser, makeMockError(EDGE44_EVAL_EXCEPTION));
405406

406407
expect(ex).toEqual({
407408
value: 'aha',
@@ -437,7 +438,7 @@ describe('Tracekit - Chrome Tests', () => {
437438
at TESTTESTTEST.someMethod (C:\\Users\\user\\path\\to\\file.js:295:108)`,
438439
};
439440

440-
const ex = exceptionFromError(parser, CHROME_ELECTRON_RENDERER);
441+
const ex = exceptionFromError(parser, makeMockError(CHROME_ELECTRON_RENDERER));
441442

442443
expect(ex).toEqual({
443444
value: "Cannot read property 'error' of undefined",
@@ -469,7 +470,7 @@ describe('Tracekit - Chrome Tests', () => {
469470
at commitLayoutEffects (react-dom.development.js?f8c1:23426:1)`,
470471
};
471472

472-
const ex = exceptionFromError(parser, EXCEPTION);
473+
const ex = exceptionFromError(parser, makeMockError(EXCEPTION));
473474

474475
expect(ex).toEqual({
475476
value: 'aha',
@@ -535,7 +536,7 @@ describe('Tracekit - Chrome Tests', () => {
535536
at Array.reduce(<anonymous>)`,
536537
};
537538

538-
const ex = exceptionFromError(parser, EXCEPTION);
539+
const ex = exceptionFromError(parser, makeMockError(EXCEPTION));
539540

540541
expect(ex).toEqual({
541542
value: 'aha',
@@ -582,7 +583,7 @@ describe('Tracekit - Chrome Tests', () => {
582583
at more (http://localhost:5000/(some)/(thing)/index.html:25:7)`,
583584
};
584585

585-
const ex = exceptionFromError(parser, CHROME_BRACES_URL);
586+
const ex = exceptionFromError(parser, makeMockError(CHROME_BRACES_URL));
586587

587588
expect(ex).toEqual({
588589
value: 'bad',
@@ -620,7 +621,7 @@ describe('Tracekit - Chrome Tests', () => {
620621
at http://localhost:5000/:50:19`,
621622
};
622623

623-
const ex = exceptionFromError(parser, LONG_FRAME);
624+
const ex = exceptionFromError(parser, makeMockError(LONG_FRAME));
624625

625626
expect(ex).toEqual({
626627
value: 'bad',

packages/browser/test/unit/tracekit/firefox.test.ts

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { exceptionFromError } from '../../../src/eventbuilder';
22
import { defaultStackParser as parser } from '../../../src/stack-parsers';
3+
import { makeMockError } from '../helper/error-object';
34

45
describe('Tracekit - Firefox Tests', () => {
56
it('should parse Firefox 3 error', () => {
@@ -19,7 +20,7 @@ describe('Tracekit - Firefox Tests', () => {
1920
'',
2021
};
2122

22-
const ex = exceptionFromError(parser, FIREFOX_3);
23+
const ex = exceptionFromError(parser, makeMockError(FIREFOX_3));
2324

2425
expect(ex).toEqual({
2526
value: 'this.undef is not a function',
@@ -55,7 +56,7 @@ describe('Tracekit - Firefox Tests', () => {
5556
'',
5657
};
5758

58-
const ex = exceptionFromError(parser, FIREFOX_7);
59+
const ex = exceptionFromError(parser, makeMockError(FIREFOX_7));
5960

6061
expect(ex).toEqual({
6162
value: 'bar',
@@ -87,7 +88,7 @@ describe('Tracekit - Firefox Tests', () => {
8788
lineNumber: 48,
8889
};
8990

90-
const ex = exceptionFromError(parser, FIREFOX_14);
91+
const ex = exceptionFromError(parser, makeMockError(FIREFOX_14));
9192

9293
expect(ex).toEqual({
9394
value: 'x is null',
@@ -116,7 +117,7 @@ describe('Tracekit - Firefox Tests', () => {
116117
columnNumber: 12,
117118
};
118119

119-
const ex = exceptionFromError(parser, FIREFOX_31);
120+
const ex = exceptionFromError(parser, makeMockError(FIREFOX_31));
120121

121122
expect(ex).toEqual({
122123
value: 'Default error',
@@ -151,7 +152,7 @@ describe('Tracekit - Firefox Tests', () => {
151152
result: 2147500037,
152153
};
153154

154-
const ex = exceptionFromError(parser, FIREFOX_44_NS_EXCEPTION);
155+
const ex = exceptionFromError(parser, makeMockError(FIREFOX_44_NS_EXCEPTION));
155156

156157
expect(ex).toEqual({
157158
value: 'No error message',
@@ -186,7 +187,7 @@ describe('Tracekit - Firefox Tests', () => {
186187
name: 'TypeError',
187188
};
188189

189-
const ex = exceptionFromError(parser, FIREFOX_50_RESOURCE_URL);
190+
const ex = exceptionFromError(parser, makeMockError(FIREFOX_50_RESOURCE_URL));
190191

191192
expect(ex).toEqual({
192193
value: 'this.props.raw[this.state.dataSource].rows is undefined',
@@ -234,7 +235,7 @@ describe('Tracekit - Firefox Tests', () => {
234235
'@http://localhost:8080/file.js:33:9',
235236
};
236237

237-
const ex = exceptionFromError(parser, FIREFOX_43_EVAL);
238+
const ex = exceptionFromError(parser, makeMockError(FIREFOX_43_EVAL));
238239

239240
expect(ex).toEqual({
240241
value: 'message string',
@@ -260,7 +261,7 @@ describe('Tracekit - Firefox Tests', () => {
260261
@http://localhost:5000/test:24:7`,
261262
};
262263

263-
const stacktrace = exceptionFromError(parser, FIREFOX66_NATIVE_CODE_EXCEPTION);
264+
const stacktrace = exceptionFromError(parser, makeMockError(FIREFOX66_NATIVE_CODE_EXCEPTION));
264265

265266
expect(stacktrace).toEqual({
266267
value: 'test',
@@ -290,7 +291,7 @@ describe('Tracekit - Firefox Tests', () => {
290291
@http://localhost:5000/:50:19`,
291292
};
292293

293-
const stacktrace = exceptionFromError(parser, FIREFOX66_EVAL_EXCEPTION);
294+
const stacktrace = exceptionFromError(parser, makeMockError(FIREFOX66_EVAL_EXCEPTION));
294295

295296
expect(stacktrace).toEqual({
296297
value: 'aha',
@@ -324,7 +325,7 @@ describe('Tracekit - Firefox Tests', () => {
324325
name: 'TypeError',
325326
};
326327

327-
const stacktrace = exceptionFromError(parser, FIREFOX_FILE_IN_IDENTIFIER);
328+
const stacktrace = exceptionFromError(parser, makeMockError(FIREFOX_FILE_IN_IDENTIFIER));
328329

329330
expect(stacktrace).toEqual({
330331
stacktrace: {

packages/browser/test/unit/tracekit/ie.test.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { exceptionFromError } from '../../../src/eventbuilder';
22
import { defaultStackParser as parser } from '../../../src/stack-parsers';
3+
import { makeMockError } from '../helper/error-object';
34

45
describe('Tracekit - IE Tests', () => {
56
it('should parse IE 10 error', () => {
@@ -15,7 +16,7 @@ describe('Tracekit - IE Tests', () => {
1516
number: -2146823281,
1617
};
1718

18-
const ex = exceptionFromError(parser, IE_10);
19+
const ex = exceptionFromError(parser, makeMockError(IE_10));
1920

2021
// TODO: func should be normalized
2122
expect(ex).toEqual({
@@ -44,7 +45,7 @@ describe('Tracekit - IE Tests', () => {
4445
number: -2146823281,
4546
};
4647

47-
const ex = exceptionFromError(parser, IE_11);
48+
const ex = exceptionFromError(parser, makeMockError(IE_11));
4849

4950
// TODO: func should be normalized
5051
expect(ex).toEqual({
@@ -73,7 +74,7 @@ describe('Tracekit - IE Tests', () => {
7374
number: -2146823279,
7475
};
7576

76-
const ex = exceptionFromError(parser, IE_11_EVAL);
77+
const ex = exceptionFromError(parser, makeMockError(IE_11_EVAL));
7778

7879
expect(ex).toEqual({
7980
value: "'getExceptionProps' is undefined",

packages/browser/test/unit/tracekit/misc.test.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { exceptionFromError } from '../../../src/eventbuilder';
22
import { defaultStackParser as parser } from '../../../src/stack-parsers';
3+
import { makeMockError } from '../helper/error-object';
34

45
describe('Tracekit - Misc Tests', () => {
56
it('should parse PhantomJS 1.19 error', () => {
@@ -12,7 +13,7 @@ describe('Tracekit - Misc Tests', () => {
1213
' at foo (http://path/to/file.js:4283)\n' +
1314
' at http://path/to/file.js:4287',
1415
};
15-
const ex = exceptionFromError(parser, PHANTOMJS_1_19);
16+
const ex = exceptionFromError(parser, makeMockError(PHANTOMJS_1_19));
1617

1718
expect(ex).toEqual({
1819
value: 'bar',
@@ -47,7 +48,7 @@ describe('Tracekit - Misc Tests', () => {
4748
' at playTimer.current(./app/components/replays/replayContext.tsx:397:62)\n' +
4849
' at sentryWrapped(../node_modules/@sentry/browser/esm/helpers.js:90:17)',
4950
};
50-
const ex = exceptionFromError(parser, SECURITY_ERROR);
51+
const ex = exceptionFromError(parser, makeMockError(SECURITY_ERROR));
5152

5253
expect(ex).toEqual({
5354
type: 'SecurityError',

packages/browser/test/unit/tracekit/opera.test.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { createStackParser } from '@sentry/utils';
22

33
import { exceptionFromError } from '../../../src/eventbuilder';
44
import { defaultStackParser, opera10StackLineParser, opera11StackLineParser } from '../../../src/stack-parsers';
5+
import { makeMockError } from '../helper/error-object';
56

67
const operaParser = createStackParser(opera10StackLineParser, opera11StackLineParser);
78
const chromiumParser = defaultStackParser;
@@ -30,7 +31,7 @@ describe('Tracekit - Opera Tests', () => {
3031
'',
3132
};
3233

33-
const ex = exceptionFromError(operaParser, OPERA_10);
34+
const ex = exceptionFromError(operaParser, makeMockError(OPERA_10));
3435

3536
expect(ex).toEqual({
3637
value: 'Statement on line 42: Type mismatch (usually non-object value supplied where object required)',
@@ -76,7 +77,7 @@ describe('Tracekit - Opera Tests', () => {
7677
' foo();',
7778
};
7879

79-
const ex = exceptionFromError(operaParser, OPERA_11);
80+
const ex = exceptionFromError(operaParser, makeMockError(OPERA_11));
8081

8182
expect(ex).toEqual({
8283
value: "'this.undef' is not a function",
@@ -113,7 +114,7 @@ describe('Tracekit - Opera Tests', () => {
113114
' dumpException3();',
114115
};
115116

116-
const ex = exceptionFromError(operaParser, OPERA_12);
117+
const ex = exceptionFromError(operaParser, makeMockError(OPERA_12));
117118

118119
expect(ex).toEqual({
119120
value: "Cannot convert 'x' to object",
@@ -157,7 +158,7 @@ describe('Tracekit - Opera Tests', () => {
157158
' at bar (http://path/to/file.js:108:168)',
158159
};
159160

160-
const ex = exceptionFromError(chromiumParser, OPERA_25);
161+
const ex = exceptionFromError(chromiumParser, makeMockError(OPERA_25));
161162

162163
expect(ex).toEqual({
163164
value: "Cannot read property 'undef' of null",

0 commit comments

Comments
 (0)