@@ -20,25 +20,18 @@ function testWrapper() {
2020 return testBasic ( ) ;
2121}
2222
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+ }
3626
27+ describe ( 'stacktrace.ts' , ( ) => {
3728 test ( 'testBasic' , ( ) => {
3829 const trace = stacktrace . parse ( testBasic ( ) ) ;
3930
4031 expect ( trace [ 0 ] . fileName ) . toEqual ( __filename ) ;
4132 expect ( trace [ 0 ] . functionName ) . toEqual ( 'testBasic' ) ;
33+ expect ( trace [ 0 ] . lineNumber ) . toEqual ( 16 ) ;
34+ expect ( trace [ 0 ] . columnNumber ) . toEqual ( 10 ) ;
4235 } ) ;
4336
4437 test ( 'testWrapper' , ( ) => {
@@ -48,6 +41,45 @@ describe('stacktrace.ts', () => {
4841 expect ( trace [ 1 ] . functionName ) . toEqual ( 'testWrapper' ) ;
4942 } ) ;
5043
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+
5183 test ( 'testNoStack' , ( ) => {
5284 const err = { stack : undefined } ;
5385 const trace = stacktrace . parse ( err as Error ) ;
@@ -66,7 +98,26 @@ describe('stacktrace.ts', () => {
6698
6799 const trace = stacktrace . parse ( err as Error ) ;
68100
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+ ] ) ;
70121 } ) ;
71122
72123 test ( 'testTraceWitoutColumnNumbers' , ( ) => {
@@ -78,9 +129,26 @@ describe('stacktrace.ts', () => {
78129
79130 const trace = stacktrace . parse ( err as Error ) ;
80131
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+ ] ) ;
84152 } ) ;
85153
86154 test ( 'testStackWithNativeCall' , ( ) => {
@@ -95,31 +163,82 @@ describe('stacktrace.ts', () => {
95163 ' at EventEmitter._tickCallback (node.js:126:26)' ;
96164
97165 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+ ] ) ;
107223 } ) ;
108224
109225 test ( 'testStackWithFileOnly' , ( ) => {
110226 const err : { [ key : string ] : any } = { } ;
111227 err . stack = 'AssertionError: true == false\n' + ' at /Users/felix/code/node-fast-or-slow/lib/test_case.js:80:10' ;
112228
113229 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+ ] ) ;
123242 } ) ;
124243
125244 test ( 'testStackWithMultilineMessage' , ( ) => {
@@ -129,9 +248,18 @@ describe('stacktrace.ts', () => {
129248 ' at /Users/felix/code/node-fast-or-slow/lib/test_case.js:80:10' ;
130249
131250 const trace = stacktrace . parse ( err as Error ) ;
132- const callSite = trace [ 0 ] ;
133251
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+ ] ) ;
135263 } ) ;
136264
137265 test ( 'testStackWithAnonymousFunctionCall' , ( ) => {
@@ -141,15 +269,18 @@ describe('stacktrace.ts', () => {
141269 ' at Assertion.prop.(anonymous function) (/Users/den/Projects/should.js/lib/should.js:60:14)\n' ;
142270
143271 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+ ] ) ;
153284 } ) ;
154285
155286 test ( 'testTraceBracesInPath' , ( ) => {
@@ -161,7 +292,25 @@ describe('stacktrace.ts', () => {
161292
162293 const trace = stacktrace . parse ( err as Error ) ;
163294
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+ ] ) ;
166315 } ) ;
167316} ) ;
0 commit comments