@@ -20,25 +20,18 @@ function testWrapper() {
20
20
return testBasic ( ) ;
21
21
}
22
22
23
- describe ( 'stacktrace.ts' , ( ) => {
24
- test ( 'testObjectInMethodName' , ( ) => {
25
- const err : { [ key : string ] : any } = { } ;
26
- err . stack =
27
- 'Error: Foo\n' +
28
- ' at [object Object].global.every [as _onTimeout] (/Users/hoitz/develop/test.coffee:36:3)\n' +
29
- ' at Timer.listOnTimeout [as ontimeout] (timers.js:110:15)\n' ;
30
-
31
- const trace = stacktrace . parse ( err as Error ) ;
32
-
33
- expect ( trace [ 0 ] . fileName ) . toEqual ( '/Users/hoitz/develop/test.coffee' ) ;
34
- expect ( trace [ 1 ] . fileName ) . toEqual ( 'timers.js' ) ;
35
- } ) ;
23
+ function evalWrapper ( ) {
24
+ return eval ( 'testWrapper()' ) ;
25
+ }
36
26
27
+ describe ( 'stacktrace.ts' , ( ) => {
37
28
test ( 'testBasic' , ( ) => {
38
29
const trace = stacktrace . parse ( testBasic ( ) ) ;
39
30
40
31
expect ( trace [ 0 ] . fileName ) . toEqual ( __filename ) ;
41
32
expect ( trace [ 0 ] . functionName ) . toEqual ( 'testBasic' ) ;
33
+ expect ( trace [ 0 ] . lineNumber ) . toEqual ( 16 ) ;
34
+ expect ( trace [ 0 ] . columnNumber ) . toEqual ( 10 ) ;
42
35
} ) ;
43
36
44
37
test ( 'testWrapper' , ( ) => {
@@ -48,6 +41,45 @@ describe('stacktrace.ts', () => {
48
41
expect ( trace [ 1 ] . functionName ) . toEqual ( 'testWrapper' ) ;
49
42
} ) ;
50
43
44
+ test ( 'evalWrapper' , ( ) => {
45
+ const trace = stacktrace . parse ( evalWrapper ( ) ) ;
46
+
47
+ expect ( trace [ 0 ] . functionName ) . toEqual ( 'testBasic' ) ;
48
+ expect ( trace [ 1 ] . functionName ) . toEqual ( 'testWrapper' ) ;
49
+ expect ( trace [ 2 ] . functionName ) . toEqual ( 'eval' ) ;
50
+ } ) ;
51
+
52
+ test ( 'testObjectInMethodName' , ( ) => {
53
+ const err : { [ key : string ] : any } = { } ;
54
+ err . stack =
55
+ 'Error: Foo\n' +
56
+ ' at [object Object].global.every [as _onTimeout] (/Users/hoitz/develop/test.coffee:36:3)\n' +
57
+ ' at Timer.listOnTimeout [as ontimeout] (timers.js:110:15)\n' ;
58
+
59
+ const trace = stacktrace . parse ( err as Error ) ;
60
+
61
+ expect ( trace ) . toEqual ( [
62
+ {
63
+ columnNumber : 3 ,
64
+ fileName : '/Users/hoitz/develop/test.coffee' ,
65
+ functionName : '[object Object].global.every [as _onTimeout]' ,
66
+ lineNumber : 36 ,
67
+ methodName : 'every [as _onTimeout]' ,
68
+ native : false ,
69
+ typeName : '[object Object].global' ,
70
+ } ,
71
+ {
72
+ columnNumber : 15 ,
73
+ fileName : 'timers.js' ,
74
+ functionName : 'Timer.listOnTimeout [as ontimeout]' ,
75
+ lineNumber : 110 ,
76
+ methodName : 'listOnTimeout [as ontimeout]' ,
77
+ native : false ,
78
+ typeName : 'Timer' ,
79
+ } ,
80
+ ] ) ;
81
+ } ) ;
82
+
51
83
test ( 'testNoStack' , ( ) => {
52
84
const err = { stack : undefined } ;
53
85
const trace = stacktrace . parse ( err as Error ) ;
@@ -66,7 +98,26 @@ describe('stacktrace.ts', () => {
66
98
67
99
const trace = stacktrace . parse ( err as Error ) ;
68
100
69
- expect ( trace . length ) . toEqual ( 2 ) ;
101
+ expect ( trace ) . toEqual ( [
102
+ {
103
+ columnNumber : 10 ,
104
+ fileName : '/Users/felix/code/node-fast-or-slow/lib/test.js' ,
105
+ functionName : 'Test.run' ,
106
+ lineNumber : 45 ,
107
+ methodName : 'run' ,
108
+ native : false ,
109
+ typeName : 'Test' ,
110
+ } ,
111
+ {
112
+ columnNumber : 8 ,
113
+ fileName : '/Users/felix/code/node-fast-or-slow/lib/test_case.js' ,
114
+ functionName : 'TestCase.run' ,
115
+ lineNumber : 61 ,
116
+ methodName : 'run' ,
117
+ native : false ,
118
+ typeName : 'TestCase' ,
119
+ } ,
120
+ ] ) ;
70
121
} ) ;
71
122
72
123
test ( 'testTraceWitoutColumnNumbers' , ( ) => {
@@ -78,9 +129,26 @@ describe('stacktrace.ts', () => {
78
129
79
130
const trace = stacktrace . parse ( err as Error ) ;
80
131
81
- expect ( trace [ 0 ] . fileName ) . toEqual ( '/Users/felix/code/node-fast-or-slow/test/fast/example/test-example.js' ) ;
82
- expect ( trace [ 0 ] . lineNumber ) . toEqual ( 6 ) ;
83
- expect ( trace [ 0 ] . columnNumber ) . toEqual ( null ) ;
132
+ expect ( trace ) . toEqual ( [
133
+ {
134
+ columnNumber : null ,
135
+ fileName : '/Users/felix/code/node-fast-or-slow/test/fast/example/test-example.js' ,
136
+ functionName : 'Test.fn' ,
137
+ lineNumber : 6 ,
138
+ methodName : 'fn' ,
139
+ native : false ,
140
+ typeName : 'Test' ,
141
+ } ,
142
+ {
143
+ columnNumber : null ,
144
+ fileName : '/Users/felix/code/node-fast-or-slow/lib/test.js' ,
145
+ functionName : 'Test.run' ,
146
+ lineNumber : 45 ,
147
+ methodName : 'run' ,
148
+ native : false ,
149
+ typeName : 'Test' ,
150
+ } ,
151
+ ] ) ;
84
152
} ) ;
85
153
86
154
test ( 'testStackWithNativeCall' , ( ) => {
@@ -95,31 +163,82 @@ describe('stacktrace.ts', () => {
95
163
' at EventEmitter._tickCallback (node.js:126:26)' ;
96
164
97
165
const trace = stacktrace . parse ( err as Error ) ;
98
- const nativeCallSite = trace [ 4 ] ;
99
-
100
- expect ( nativeCallSite . fileName ) . toEqual ( null ) ;
101
- expect ( nativeCallSite . functionName ) . toEqual ( 'Array.0' ) ;
102
- expect ( nativeCallSite . typeName ) . toEqual ( 'Array' ) ;
103
- expect ( nativeCallSite . methodName ) . toEqual ( '0' ) ;
104
- expect ( nativeCallSite . lineNumber ) . toEqual ( null ) ;
105
- expect ( nativeCallSite . columnNumber ) . toEqual ( null ) ;
106
- expect ( nativeCallSite . native ) . toEqual ( true ) ;
166
+
167
+ expect ( trace ) . toEqual ( [
168
+ {
169
+ columnNumber : 10 ,
170
+ fileName : '/Users/felix/code/node-fast-or-slow/test/fast/example/test-example.js' ,
171
+ functionName : 'Test.fn' ,
172
+ lineNumber : 6 ,
173
+ methodName : 'fn' ,
174
+ native : false ,
175
+ typeName : 'Test' ,
176
+ } ,
177
+ {
178
+ columnNumber : 10 ,
179
+ fileName : '/Users/felix/code/node-fast-or-slow/lib/test.js' ,
180
+ functionName : 'Test.run' ,
181
+ lineNumber : 45 ,
182
+ methodName : 'run' ,
183
+ native : false ,
184
+ typeName : 'Test' ,
185
+ } ,
186
+ {
187
+ columnNumber : 8 ,
188
+ fileName : '/Users/felix/code/node-fast-or-slow/lib/test_case.js' ,
189
+ functionName : 'TestCase.runNext' ,
190
+ lineNumber : 73 ,
191
+ methodName : 'runNext' ,
192
+ native : false ,
193
+ typeName : 'TestCase' ,
194
+ } ,
195
+ {
196
+ columnNumber : 8 ,
197
+ fileName : '/Users/felix/code/node-fast-or-slow/lib/test_case.js' ,
198
+ functionName : 'TestCase.run' ,
199
+ lineNumber : 61 ,
200
+ methodName : 'run' ,
201
+ native : false ,
202
+ typeName : 'TestCase' ,
203
+ } ,
204
+ {
205
+ columnNumber : null ,
206
+ fileName : null ,
207
+ functionName : 'Array.0' ,
208
+ lineNumber : null ,
209
+ methodName : '0' ,
210
+ native : true ,
211
+ typeName : 'Array' ,
212
+ } ,
213
+ {
214
+ columnNumber : 26 ,
215
+ fileName : 'node.js' ,
216
+ functionName : 'EventEmitter._tickCallback' ,
217
+ lineNumber : 126 ,
218
+ methodName : '_tickCallback' ,
219
+ native : false ,
220
+ typeName : 'EventEmitter' ,
221
+ } ,
222
+ ] ) ;
107
223
} ) ;
108
224
109
225
test ( 'testStackWithFileOnly' , ( ) => {
110
226
const err : { [ key : string ] : any } = { } ;
111
227
err . stack = 'AssertionError: true == false\n' + ' at /Users/felix/code/node-fast-or-slow/lib/test_case.js:80:10' ;
112
228
113
229
const trace = stacktrace . parse ( err as Error ) ;
114
- const callSite = trace [ 0 ] ;
115
-
116
- expect ( callSite . fileName ) . toEqual ( '/Users/felix/code/node-fast-or-slow/lib/test_case.js' ) ;
117
- expect ( callSite . functionName ) . toEqual ( null ) ;
118
- expect ( callSite . typeName ) . toEqual ( null ) ;
119
- expect ( callSite . methodName ) . toEqual ( null ) ;
120
- expect ( callSite . lineNumber ) . toEqual ( 80 ) ;
121
- expect ( callSite . columnNumber ) . toEqual ( 10 ) ;
122
- expect ( callSite . native ) . toEqual ( false ) ;
230
+
231
+ expect ( trace ) . toEqual ( [
232
+ {
233
+ columnNumber : 10 ,
234
+ fileName : '/Users/felix/code/node-fast-or-slow/lib/test_case.js' ,
235
+ functionName : null ,
236
+ lineNumber : 80 ,
237
+ methodName : null ,
238
+ native : false ,
239
+ typeName : null ,
240
+ } ,
241
+ ] ) ;
123
242
} ) ;
124
243
125
244
test ( 'testStackWithMultilineMessage' , ( ) => {
@@ -129,9 +248,18 @@ describe('stacktrace.ts', () => {
129
248
' at /Users/felix/code/node-fast-or-slow/lib/test_case.js:80:10' ;
130
249
131
250
const trace = stacktrace . parse ( err as Error ) ;
132
- const callSite = trace [ 0 ] ;
133
251
134
- expect ( callSite . fileName ) . toEqual ( '/Users/felix/code/node-fast-or-slow/lib/test_case.js' ) ;
252
+ expect ( trace ) . toEqual ( [
253
+ {
254
+ columnNumber : 10 ,
255
+ fileName : '/Users/felix/code/node-fast-or-slow/lib/test_case.js' ,
256
+ functionName : null ,
257
+ lineNumber : 80 ,
258
+ methodName : null ,
259
+ native : false ,
260
+ typeName : null ,
261
+ } ,
262
+ ] ) ;
135
263
} ) ;
136
264
137
265
test ( 'testStackWithAnonymousFunctionCall' , ( ) => {
@@ -141,15 +269,18 @@ describe('stacktrace.ts', () => {
141
269
' at Assertion.prop.(anonymous function) (/Users/den/Projects/should.js/lib/should.js:60:14)\n' ;
142
270
143
271
const trace = stacktrace . parse ( err as Error ) ;
144
- const callSite0 = trace [ 0 ] ;
145
-
146
- expect ( callSite0 . fileName ) . toEqual ( '/Users/den/Projects/should.js/lib/should.js' ) ;
147
- expect ( callSite0 . functionName ) . toEqual ( 'Assertion.prop.(anonymous function)' ) ;
148
- expect ( callSite0 . typeName ) . toEqual ( 'Assertion.prop' ) ;
149
- expect ( callSite0 . methodName ) . toEqual ( '(anonymous function)' ) ;
150
- expect ( callSite0 . lineNumber ) . toEqual ( 60 ) ;
151
- expect ( callSite0 . columnNumber ) . toEqual ( 14 ) ;
152
- expect ( callSite0 . native ) . toEqual ( false ) ;
272
+
273
+ expect ( trace ) . toEqual ( [
274
+ {
275
+ columnNumber : 14 ,
276
+ fileName : '/Users/den/Projects/should.js/lib/should.js' ,
277
+ functionName : 'Assertion.prop.(anonymous function)' ,
278
+ lineNumber : 60 ,
279
+ methodName : '(anonymous function)' ,
280
+ native : false ,
281
+ typeName : 'Assertion.prop' ,
282
+ } ,
283
+ ] ) ;
153
284
} ) ;
154
285
155
286
test ( 'testTraceBracesInPath' , ( ) => {
@@ -161,7 +292,25 @@ describe('stacktrace.ts', () => {
161
292
162
293
const trace = stacktrace . parse ( err as Error ) ;
163
294
164
- expect ( trace . length ) . toEqual ( 2 ) ;
165
- expect ( trace [ 0 ] . fileName ) . toEqual ( '/Users/felix (something)/code/node-fast-or-slow/lib/test.js' ) ;
295
+ expect ( trace ) . toEqual ( [
296
+ {
297
+ columnNumber : 10 ,
298
+ fileName : '/Users/felix (something)/code/node-fast-or-slow/lib/test.js' ,
299
+ functionName : 'Test.run' ,
300
+ lineNumber : 45 ,
301
+ methodName : 'run' ,
302
+ native : false ,
303
+ typeName : 'Test' ,
304
+ } ,
305
+ {
306
+ columnNumber : 8 ,
307
+ fileName : '/Users/felix (something)/code/node-fast-or-slow/lib/test_case.js' ,
308
+ functionName : 'TestCase.run' ,
309
+ lineNumber : 61 ,
310
+ methodName : 'run' ,
311
+ native : false ,
312
+ typeName : 'TestCase' ,
313
+ } ,
314
+ ] ) ;
166
315
} ) ;
167
316
} ) ;
0 commit comments