-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
Copy pathtracekit-parser.test.js
261 lines (232 loc) · 20.3 KB
/
tracekit-parser.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
/*global Mocha, assert*/
'use strict';
var TraceKit = require('../../vendor/TraceKit/tracekit');
var CapturedExceptions = require('./fixtures/captured-errors');
describe('TraceKit', function () {
describe('Parser', function() {
it('should parse Safari 6 error', function () {
var stackFrames = TraceKit.computeStackTrace(CapturedExceptions.SAFARI_6);
assert.ok(stackFrames);
assert.deepEqual(stackFrames.stack.length, 4);
assert.deepEqual(stackFrames.stack[0], { url: 'http://path/to/file.js', func: '?', args: [], line: 48, column: null });
assert.deepEqual(stackFrames.stack[1], { url: 'http://path/to/file.js', func: 'dumpException3', args: [], line: 52, column: null });
assert.deepEqual(stackFrames.stack[2], { url: 'http://path/to/file.js', func: 'onclick', args: [], line: 82, column: null });
assert.deepEqual(stackFrames.stack[3], { url: '[native code]', func: '?', args: [], line: null, column: null });
});
it('should parse Safari 7 error', function () {
var stackFrames = TraceKit.computeStackTrace(CapturedExceptions.SAFARI_7);
assert.ok(stackFrames);
assert.deepEqual(stackFrames.stack.length, 3);
assert.deepEqual(stackFrames.stack[0], { url: 'http://path/to/file.js', func: '?', args: [], line: 48, column: 22 });
assert.deepEqual(stackFrames.stack[1], { url: 'http://path/to/file.js', func: 'foo', args: [], line: 52, column: 15 });
assert.deepEqual(stackFrames.stack[2], { url: 'http://path/to/file.js', func: 'bar', args: [], line: 108, column: 107 });
});
it('should parse Safari 8 error', function () {
var stackFrames = TraceKit.computeStackTrace(CapturedExceptions.SAFARI_8);
assert.ok(stackFrames);
assert.deepEqual(stackFrames.stack.length, 3);
assert.deepEqual(stackFrames.stack[0], { url: 'http://path/to/file.js', func: '?', args: [], line: 47, column: 22 });
assert.deepEqual(stackFrames.stack[1], { url: 'http://path/to/file.js', func: 'foo', args: [], line: 52, column: 15 });
assert.deepEqual(stackFrames.stack[2], { url: 'http://path/to/file.js', func: 'bar', args: [], line: 108, column: 23 });
});
it('should parse Safari 8 eval error', function () {
// TODO: Take into account the line and column properties on the error object and use them for the first stack trace.
var stackFrames = TraceKit.computeStackTrace(CapturedExceptions.SAFARI_8_EVAL);
assert.ok(stackFrames);
assert.deepEqual(stackFrames.stack.length, 3);
assert.deepEqual(stackFrames.stack[0], { url: '[native code]', func: 'eval', args: [], line: null, column: null });
assert.deepEqual(stackFrames.stack[1], { url: 'http://path/to/file.js', func: 'foo', args: [], line: 58, column: 21 });
assert.deepEqual(stackFrames.stack[2], { url: 'http://path/to/file.js', func: 'bar', args: [], line: 109, column: 91 });
});
it('should parse Firefox 3 error', function () {
var stackFrames = TraceKit.computeStackTrace(CapturedExceptions.FIREFOX_3);
assert.ok(stackFrames);
assert.deepEqual(stackFrames.stack.length, 7);
assert.deepEqual(stackFrames.stack[0], { url: 'http://127.0.0.1:8000/js/stacktrace.js', func: '?', args: [], line: 44, column: null });
assert.deepEqual(stackFrames.stack[1], { url: 'http://127.0.0.1:8000/js/stacktrace.js', func: '?', args: ['null'], line: 31, column: null });
assert.deepEqual(stackFrames.stack[2], { url: 'http://127.0.0.1:8000/js/stacktrace.js', func: 'printStackTrace', args: [], line: 18, column: null });
assert.deepEqual(stackFrames.stack[3], { url: 'http://127.0.0.1:8000/js/file.js', func: 'bar', args: ['1'], line: 13, column: null });
assert.deepEqual(stackFrames.stack[4], { url: 'http://127.0.0.1:8000/js/file.js', func: 'bar', args: ['2'], line: 16, column: null });
assert.deepEqual(stackFrames.stack[5], { url: 'http://127.0.0.1:8000/js/file.js', func: 'foo', args: [], line: 20, column: null });
assert.deepEqual(stackFrames.stack[6], { url: 'http://127.0.0.1:8000/js/file.js', func: '?', args: [], line: 24, column: null });
});
it('should parse Firefox 7 error', function () {
var stackFrames = TraceKit.computeStackTrace(CapturedExceptions.FIREFOX_7);
assert.ok(stackFrames);
assert.deepEqual(stackFrames.stack.length, 7);
assert.deepEqual(stackFrames.stack[0], { url: 'file:///G:/js/stacktrace.js', func: '?', args: [], line: 44, column: null });
assert.deepEqual(stackFrames.stack[1], { url: 'file:///G:/js/stacktrace.js', func: '?', args: ['null'], line: 31, column: null });
assert.deepEqual(stackFrames.stack[2], { url: 'file:///G:/js/stacktrace.js', func: 'printStackTrace', args: [], line: 18, column: null });
assert.deepEqual(stackFrames.stack[3], { url: 'file:///G:/js/file.js', func: 'bar', args: ['1'], line: 13, column: null });
assert.deepEqual(stackFrames.stack[4], { url: 'file:///G:/js/file.js', func: 'bar', args: ['2'], line: 16, column: null });
assert.deepEqual(stackFrames.stack[5], { url: 'file:///G:/js/file.js', func: 'foo', args: [], line: 20, column: null });
assert.deepEqual(stackFrames.stack[6], { url: 'file:///G:/js/file.js', func: '?', args: [], line: 24, column: null });
});
it('should parse Firefox 14 error', function () {
var stackFrames = TraceKit.computeStackTrace(CapturedExceptions.FIREFOX_14);
assert.ok(stackFrames);
assert.deepEqual(stackFrames.stack.length, 3);
assert.deepEqual(stackFrames.stack[0], { url: 'http://path/to/file.js', func: '?', args: [], line: 48, column: null });
assert.deepEqual(stackFrames.stack[1], { url: 'http://path/to/file.js', func: 'dumpException3', args: [], line: 52, column: null });
assert.deepEqual(stackFrames.stack[2], { url: 'http://path/to/file.js', func: 'onclick', args: [], line: 1, column: null });
});
it('should parse Firefox 31 error', function () {
var stackFrames = TraceKit.computeStackTrace(CapturedExceptions.FIREFOX_31);
assert.ok(stackFrames);
assert.deepEqual(stackFrames.stack.length, 3);
assert.deepEqual(stackFrames.stack[0], { url: 'http://path/to/file.js', func: 'foo', args: [], line: 41, column: 13 });
assert.deepEqual(stackFrames.stack[1], { url: 'http://path/to/file.js', func: 'bar', args: [], line: 1, column: 1 });
assert.deepEqual(stackFrames.stack[2], { url: 'http://path/to/file.js', func: '.plugin/e.fn[c]/<', args: [], line: 1, column: 1 });
});
it('should parse Firefox 44 ns exceptions', function () {
var stackFrames = TraceKit.computeStackTrace(CapturedExceptions.FIREFOX_44_NS_EXCEPTION);
assert.ok(stackFrames);
assert.deepEqual(stackFrames.stack.length, 4);
assert.deepEqual(stackFrames.stack[0], { url: 'http://path/to/file.js', func: '[2]</Bar.prototype._baz/</<', args: [], line: 703, column: 28 });
assert.deepEqual(stackFrames.stack[1], { url: 'file:///path/to/file.js', func: 'App.prototype.foo', args: [], line: 15, column: 2 });
assert.deepEqual(stackFrames.stack[2], { url: 'file:///path/to/file.js', func: 'bar', args: [], line: 20, column: 3 });
assert.deepEqual(stackFrames.stack[3], { url: 'file:///path/to/index.html', func: '?', args: [], line: 23, column: 1 });
});
it('should parse Chrome error with no location', function () {
var stackFrames = TraceKit.computeStackTrace({stack: "error\n at Array.forEach (native)"});
assert.deepEqual(stackFrames.stack.length, 1);
assert.deepEqual(stackFrames.stack[0], { url: null, func: 'Array.forEach', args: ['native'], line: null, column: null });
});
it('should parse Chrome 15 error', function () {
var stackFrames = TraceKit.computeStackTrace(CapturedExceptions.CHROME_15);
assert.ok(stackFrames);
assert.deepEqual(stackFrames.stack.length, 4);
assert.deepEqual(stackFrames.stack[0], { url: 'http://path/to/file.js', func: 'bar', args: [], line: 13, column: 17 });
assert.deepEqual(stackFrames.stack[1], { url: 'http://path/to/file.js', func: 'bar', args: [], line: 16, column: 5 });
assert.deepEqual(stackFrames.stack[2], { url: 'http://path/to/file.js', func: 'foo', args: [], line: 20, column: 5 });
assert.deepEqual(stackFrames.stack[3], { url: 'http://path/to/file.js', func: '?', args: [], line: 24, column: 4 });
});
it('should parse Chrome 36 error with port numbers', function () {
var stackFrames = TraceKit.computeStackTrace(CapturedExceptions.CHROME_36);
assert.ok(stackFrames);
assert.deepEqual(stackFrames.stack.length, 3);
assert.deepEqual(stackFrames.stack[0], { url: 'http://localhost:8080/file.js', func: 'dumpExceptionError', args: [], line: 41, column: 27 });
assert.deepEqual(stackFrames.stack[1], { url: 'http://localhost:8080/file.js', func: 'HTMLButtonElement.onclick', args: [], line: 107, column: 146 });
assert.deepEqual(stackFrames.stack[2], { url: 'http://localhost:8080/file.js', func: 'I.e.fn.(anonymous function) [as index]', args: [], line: 10, column: 3651 });
});
it('should parse Chrome error with webpack URLs', function () {
var stackFrames = TraceKit.computeStackTrace(CapturedExceptions.CHROME_XX_WEBPACK);
assert.ok(stackFrames);
assert.deepEqual(stackFrames.stack.length, 4);
assert.deepEqual(stackFrames.stack[0], { url: 'webpack:///./src/components/test/test.jsx?', func: 'TESTTESTTEST.eval', args: [], line: 295, column: 108 });
assert.deepEqual(stackFrames.stack[1], { url: 'webpack:///./src/components/test/test.jsx?', func: 'TESTTESTTEST.render', args: [], line: 272, column: 32 });
assert.deepEqual(stackFrames.stack[2], { url: 'webpack:///./~/react-transform-catch-errors/lib/index.js?', func: 'TESTTESTTEST.tryRender', args: [], line: 34, column: 31 });
assert.deepEqual(stackFrames.stack[3], { url: 'webpack:///./~/react-proxy/modules/createPrototypeProxy.js?', func: 'TESTTESTTEST.proxiedMethod', args: [], line: 44, column: 30 });
});
it('should parse nested eval() from Chrome', function() {
var stackFrames = TraceKit.computeStackTrace(CapturedExceptions.CHROME_48_EVAL);
assert.ok(stackFrames);
assert.deepEqual(stackFrames.stack.length, 5);
assert.deepEqual(stackFrames.stack[0], { url: 'http://localhost:8080/file.js', func: 'baz', args: [], line: 21, column: 17});
assert.deepEqual(stackFrames.stack[1], { url: 'http://localhost:8080/file.js', func: 'foo', args: [], line: 21, column: 17});
assert.deepEqual(stackFrames.stack[2], { url: 'http://localhost:8080/file.js', func: 'eval', args: [], line: 21, column: 17});
assert.deepEqual(stackFrames.stack[3], { url: 'http://localhost:8080/file.js', func: 'Object.speak', args: [], line: 21, column: 17});
assert.deepEqual(stackFrames.stack[4], { url: 'http://localhost:8080/file.js', func: '?', args: [], line: 31, column: 13});
});
it('should parse Chrome error with blob URLs', function () {
var stackFrames = TraceKit.computeStackTrace(CapturedExceptions.CHROME_48_BLOB);
assert.ok(stackFrames);
assert.deepEqual(stackFrames.stack.length, 7);
assert.deepEqual(stackFrames.stack[1], { url: 'blob:http%3A//localhost%3A8080/abfc40e9-4742-44ed-9dcd-af8f99a29379', func: 's', args: [], line: 31, column: 29146 });
assert.deepEqual(stackFrames.stack[2], { url: 'blob:http%3A//localhost%3A8080/abfc40e9-4742-44ed-9dcd-af8f99a29379', func: 'Object.d [as add]', args: [ ], line: 31, column: 30039 });
assert.deepEqual(stackFrames.stack[3], { url: 'blob:http%3A//localhost%3A8080/d4eefe0f-361a-4682-b217-76587d9f712a', func: '?', args: [], line: 15, column: 10978 });
assert.deepEqual(stackFrames.stack[4], { url: 'blob:http%3A//localhost%3A8080/abfc40e9-4742-44ed-9dcd-af8f99a29379', func: '?', args: [], line: 1, column: 6911 });
assert.deepEqual(stackFrames.stack[5], { url: 'blob:http%3A//localhost%3A8080/abfc40e9-4742-44ed-9dcd-af8f99a29379', func: 'n.fire', args: [], line: 7, column: 3019 });
assert.deepEqual(stackFrames.stack[6], { url: 'blob:http%3A//localhost%3A8080/abfc40e9-4742-44ed-9dcd-af8f99a29379', func: 'n.handle', args: [], line: 7, column: 2863 });
});
it('should parse empty IE 9 error', function() {
var stackFrames = TraceKit.computeStackTrace(CapturedExceptions.IE_9);
assert.ok(stackFrames);
stackFrames.stack && assert.deepEqual(stackFrames.stack.length, 0);
});
it('should parse IE 10 error', function () {
var stackFrames = TraceKit.computeStackTrace(CapturedExceptions.IE_10);
assert.ok(stackFrames);
assert.deepEqual(stackFrames.stack.length, 3);
// TODO: func should be normalized
assert.deepEqual(stackFrames.stack[0], { url: 'http://path/to/file.js', func: 'Anonymous function', args: [], line: 48, column: 13 });
assert.deepEqual(stackFrames.stack[1], { url: 'http://path/to/file.js', func: 'foo', args: [], line: 46, column: 9 });
assert.deepEqual(stackFrames.stack[2], { url: 'http://path/to/file.js', func: 'bar', args: [], line: 82, column: 1 });
});
it('should parse IE 11 error', function () {
var stackFrames = TraceKit.computeStackTrace(CapturedExceptions.IE_11);
assert.ok(stackFrames);
assert.deepEqual(stackFrames.stack.length, 3);
// TODO: func should be normalized
assert.deepEqual(stackFrames.stack[0], { url: 'http://path/to/file.js', func: 'Anonymous function', args: [], line: 47, column: 21 });
assert.deepEqual(stackFrames.stack[1], { url: 'http://path/to/file.js', func: 'foo', args: [], line: 45, column: 13 });
assert.deepEqual(stackFrames.stack[2], { url: 'http://path/to/file.js', func: 'bar', args: [], line: 108, column: 1 });
});
it('should parse IE 11 eval error', function () {
var stackFrames = TraceKit.computeStackTrace(CapturedExceptions.IE_11_EVAL);
assert.ok(stackFrames);
assert.deepEqual(stackFrames.stack.length, 3);
assert.deepEqual(stackFrames.stack[0], { url: 'eval code', func: 'eval code', args: [], line: 1, column: 1 });
assert.deepEqual(stackFrames.stack[1], { url: 'http://path/to/file.js', func: 'foo', args: [], line: 58, column: 17 });
assert.deepEqual(stackFrames.stack[2], { url: 'http://path/to/file.js', func: 'bar', args: [], line: 109, column: 1 });
});
it('should parse Opera 11 error', function () {
var stackFrames = TraceKit.computeStackTrace(CapturedExceptions.OPERA_11);
assert.ok(stackFrames);
assert.deepEqual(stackFrames.stack.length, 5);
assert.deepEqual(stackFrames.stack[0], { url: 'http://path/to/file.js', func: '<anonymous function: run>', args: ['[arguments not available]'], line: 27, column: null });
assert.deepEqual(stackFrames.stack[1], { url: 'http://domain.com:1234/path/to/file.js', func: 'bar', args: ['[arguments not available]'], line: 18, column: null });
assert.deepEqual(stackFrames.stack[2], { url: 'http://domain.com:1234/path/to/file.js', func: 'foo', args: ['[arguments not available]'], line: 11, column: null });
assert.deepEqual(stackFrames.stack[3], { url: 'http://path/to/file.js', func: '<anonymous function>', args: [], line: 15, column: null });
assert.deepEqual(stackFrames.stack[4], { url: 'http://path/to/file.js', func: 'Error created at <anonymous function>', args: [], line: 15, column: null });
});
it('should parse Opera 12 error', function () {
// TODO: Improve anonymous function name.
var stackFrames = TraceKit.computeStackTrace(CapturedExceptions.OPERA_12);
assert.ok(stackFrames);
assert.deepEqual(stackFrames.stack.length, 3);
assert.deepEqual(stackFrames.stack[0], { url: 'http://localhost:8000/ExceptionLab.html', func: '<anonymous function>', args: ['[arguments not available]'], line: 48, column: null });
assert.deepEqual(stackFrames.stack[1], { url: 'http://localhost:8000/ExceptionLab.html', func: 'dumpException3', args: ['[arguments not available]'], line: 46, column: null });
assert.deepEqual(stackFrames.stack[2], { url: 'http://localhost:8000/ExceptionLab.html', func: '<anonymous function>', args: ['[arguments not available]'], line: 1, column: null });
});
it('should parse Opera 25 error', function () {
var stackFrames = TraceKit.computeStackTrace(CapturedExceptions.OPERA_25);
assert.ok(stackFrames);
assert.deepEqual(stackFrames.stack.length, 3);
assert.deepEqual(stackFrames.stack[0], { url: 'http://path/to/file.js', func: '?', args: [], line: 47, column: 22 });
assert.deepEqual(stackFrames.stack[1], { url: 'http://path/to/file.js', func: 'foo', args: [], line: 52, column: 15 });
assert.deepEqual(stackFrames.stack[2], { url: 'http://path/to/file.js', func: 'bar', args: [], line: 108, column: 168 });
});
it('should parse PhantomJS 1.19 error', function () {
var stackFrames = TraceKit.computeStackTrace(CapturedExceptions.PHANTOMJS_1_19);
assert.ok(stackFrames);
assert.deepEqual(stackFrames.stack.length, 3);
assert.deepEqual(stackFrames.stack[0], { url: 'file:///path/to/file.js', func: '?', args: [], line: 878, column: null });
assert.deepEqual(stackFrames.stack[1], { url: 'http://path/to/file.js', func: 'foo', args: [], line: 4283, column: null });
assert.deepEqual(stackFrames.stack[2], { url: 'http://path/to/file.js', func: '?', args: [], line: 4287, column: null });
});
it('should parse Firefox errors with resource: URLs', function () {
var stackFrames = TraceKit.computeStackTrace(CapturedExceptions.FIREFOX_50_RESOURCE_URL);
assert.ok(stackFrames);
assert.deepEqual(stackFrames.stack.length, 3);
assert.deepEqual(stackFrames.stack[0], { url: 'resource://path/data/content/bundle.js', func: 'render', args: [], line: 5529, column: 16 });
});
it('should parse Firefox errors with eval URLs', function () {
var stackFrames = TraceKit.computeStackTrace(CapturedExceptions.FIREFOX_43_EVAL);
assert.ok(stackFrames);
assert.deepEqual(stackFrames.stack.length, 5);
assert.deepEqual(stackFrames.stack[0], { url: 'http://localhost:8080/file.js', func: 'baz', args:[], line: 26, column: null});
assert.deepEqual(stackFrames.stack[1], { url: 'http://localhost:8080/file.js', func: 'foo', args:[], line: 26, column: null});
assert.deepEqual(stackFrames.stack[2], { url: 'http://localhost:8080/file.js', func: '?', args:[], line: 26, column: null});
assert.deepEqual(stackFrames.stack[3], { url: 'http://localhost:8080/file.js', func: 'speak', args:[], line: 26, column: 17});
assert.deepEqual(stackFrames.stack[4], { url: 'http://localhost:8080/file.js', func: '?', args:[], line: 33, column: 9});
});
it('should parse React Native errors on Android', function () {
var stackFrames = TraceKit.computeStackTrace(CapturedExceptions.ANDROID_REACT_NATIVE);
assert.ok(stackFrames);
assert.deepEqual(stackFrames.stack.length, 8);
assert.deepEqual(stackFrames.stack[0], { url: '/home/username/sample-workspace/sampleapp.collect.react/src/components/GpsMonitorScene.js', func: 'render', args: [], line: 78, column: 24 });
assert.deepEqual(stackFrames.stack[7], { url: '/home/username/sample-workspace/sampleapp.collect.react/node_modules/react-native/Libraries/Renderer/src/renderers/native/ReactNativeBaseComponent.js', func: 'this', args: [], line: 74, column: 41 });
});
});
});