@@ -26,13 +26,13 @@ describe('StackTrace', function () {
26
26
27
27
describe ( '#get' , function ( ) {
28
28
it ( 'gets stacktrace from current location' , function ( ) {
29
- runs ( function ( ) {
30
- new StackTrace ( ) . get ( ) . then ( callback , errback ) ;
29
+ runs ( function testStackTraceGet ( ) {
30
+ new StackTrace ( ) . get ( ) . then ( callback , errback ) [ 'catch' ] ( debugErrback ) ;
31
31
} ) ;
32
32
waits ( 100 ) ;
33
33
runs ( function ( ) {
34
34
expect ( callback ) . toHaveBeenCalled ( ) ;
35
- expect ( callback . mostRecentCall . args [ 0 ] [ 0 ] . fileName ) . toMatch ( / s t a c k t r a c e \- s p e c \. j s \b / ) ;
35
+ expect ( callback . mostRecentCall . args [ 0 ] [ 0 ] . functionName ) . toEqual ( 'testStackTraceGet' ) ;
36
36
expect ( errback ) . not . toHaveBeenCalled ( ) ;
37
37
} ) ;
38
38
} ) ;
@@ -41,7 +41,8 @@ describe('StackTrace', function () {
41
41
describe ( '#fromError' , function ( ) {
42
42
it ( 'rejects with Error given non-Error object' , function ( ) {
43
43
runs ( function ( ) {
44
- new StackTrace ( ) . fromError ( 'BOGUS' ) . then ( callback , errback ) ;
44
+ new StackTrace ( ) . fromError ( 'BOGUS' )
45
+ . then ( callback , errback ) [ 'catch' ] ( errback ) ;
45
46
} ) ;
46
47
waits ( 100 ) ;
47
48
runs ( function ( ) {
@@ -51,11 +52,13 @@ describe('StackTrace', function () {
51
52
} ) ;
52
53
53
54
it ( 'parses stacktrace from given Error object' , function ( ) {
55
+ //FIXME: shims for IE9
54
56
runs ( function ( ) {
55
57
try {
56
58
throw new Error ( 'Yikes!' ) ;
57
59
} catch ( e ) {
58
- new StackTrace ( ) . fromError ( e ) . then ( callback , errback ) ;
60
+ new StackTrace ( ) . fromError ( e )
61
+ . then ( callback , errback ) [ 'catch' ] ( errback ) ;
59
62
}
60
63
} ) ;
61
64
waits ( 100 ) ;
@@ -66,7 +69,9 @@ describe('StackTrace', function () {
66
69
} ) ;
67
70
68
71
it ( 'totally extracts function names' , function ( ) {
69
- var TEST_FUNCTION = function ( ) {
72
+ //FIXME: shims for IE9
73
+ //FIXME: need function name for opera 12
74
+ var TEST_FUNCTION = function TEST_FUNCTION ( ) {
70
75
try {
71
76
throw new Error ( 'Yikes!' ) ;
72
77
} catch ( e ) {
@@ -75,7 +80,7 @@ describe('StackTrace', function () {
75
80
}
76
81
77
82
new StackTrace ( ) . fromError ( e , { filter : onlySpecSourcesPlease } )
78
- . then ( callback , errback ) ;
83
+ . then ( callback , errback ) [ 'catch' ] ( errback ) ;
79
84
}
80
85
} ;
81
86
runs ( TEST_FUNCTION ) ;
@@ -95,7 +100,7 @@ describe('StackTrace', function () {
95
100
} ) ;
96
101
} ) ;
97
102
98
- describe ( '#getMappedLocation' , function ( ) {
103
+ describe ( '#getMappedLocation' , function ( ) {
99
104
var server ;
100
105
beforeEach ( function ( ) {
101
106
server = sinon . fakeServer . create ( ) ;
@@ -104,34 +109,34 @@ describe('StackTrace', function () {
104
109
server . restore ( ) ;
105
110
} ) ;
106
111
107
- it ( 'defaults to given stackframe if source map location not found' , function ( ) {
108
- runs ( function ( ) {
112
+ it ( 'defaults to given stackframe if source map location not found' , function ( ) {
113
+ runs ( function ( ) {
109
114
var stackframe = new StackFrame ( undefined , [ ] , 'http://localhost:9999/test.min.js' , 1 , 32 ) ;
110
- new StackTrace ( ) . getMappedLocation ( stackframe ) . then ( callback , errback ) ;
115
+ new StackTrace ( ) . getMappedLocation ( stackframe ) . then ( callback , errback ) [ 'catch' ] ( debugErrback ) ;
111
116
server . requests [ 0 ] . respond ( 404 , { } , '' ) ;
112
117
} ) ;
113
118
waits ( 100 ) ;
114
- runs ( function ( ) {
119
+ runs ( function ( ) {
115
120
expect ( callback ) . toHaveBeenCalled ( ) ;
116
121
expect ( callback . mostRecentCall . args [ 0 ] ) . toMatchStackFrame ( [ undefined , [ ] , 'http://localhost:9999/test.min.js' , 1 , 32 ] ) ;
117
122
expect ( errback ) . not . toHaveBeenCalled ( ) ;
118
123
} ) ;
119
124
} ) ;
120
125
121
126
it ( 'uses source maps to enhance stack frames' , function ( ) {
122
- runs ( function ( ) {
127
+ runs ( function ( ) {
123
128
var stackframe = new StackFrame ( undefined , [ ] , 'http://localhost:9999/test.min.js' , 1 , 32 ) ;
124
- new StackTrace ( ) . getMappedLocation ( stackframe ) . then ( callback , errback ) ;
129
+ new StackTrace ( ) . getMappedLocation ( stackframe ) . then ( callback , errback ) [ 'catch' ] ( debugErrback ) ;
125
130
var source = 'var foo=function(){};function bar(){}var baz=eval("XXX");\n//@ sourceMappingURL=test.js.map' ;
126
- server . requests [ 0 ] . respond ( 200 , { 'Content-Type' : 'application/x-javascript' } , source ) ;
131
+ server . requests [ 0 ] . respond ( 200 , { 'Content-Type' : 'application/x-javascript' } , source ) ;
127
132
} ) ;
128
133
waits ( 100 ) ;
129
- runs ( function ( ) {
134
+ runs ( function ( ) {
130
135
var sourceMap = '{"version":3,"sources":["./test.js"],"names":["foo","bar","baz","eval"],"mappings":"AAAA,GAAIA,KAAM,YACV,SAASC,QACT,GAAIC,KAAMC,KAAK","file":"test.min.js"}' ;
131
- server . requests [ 1 ] . respond ( 200 , { 'Content-Type' : 'application/json' } , sourceMap ) ;
136
+ server . requests [ 1 ] . respond ( 200 , { 'Content-Type' : 'application/json' } , sourceMap ) ;
132
137
} ) ;
133
138
waits ( 100 ) ;
134
- runs ( function ( ) {
139
+ runs ( function ( ) {
135
140
expect ( callback ) . toHaveBeenCalled ( ) ;
136
141
expect ( callback . mostRecentCall . args [ 0 ] ) . toMatchStackFrame ( [ 'bar' , [ ] , './test.js' , 2 , 9 ] ) ;
137
142
expect ( errback ) . not . toHaveBeenCalled ( ) ;
@@ -140,12 +145,21 @@ describe('StackTrace', function () {
140
145
} ) ;
141
146
142
147
describe ( '#generateArtificially' , function ( ) {
143
- var unit = new StackTrace ( ) ;
144
- it ( 'gets stacktrace from current location' , function testGenerateArtificially ( ) {
145
- var stackFrames = unit . generateArtificially ( ) . filter ( function ( stackFrame ) {
146
- return stackFrame . getFunctionName ( ) && stackFrame . getFunctionName ( ) . indexOf ( 'testGenerateArtificially' ) > - 1 ;
148
+ it ( 'gets stacktrace from current location' , function ( ) {
149
+ runs ( function testGenerateArtificially ( ) {
150
+ var stackFrameFilter = function ( stackFrame ) {
151
+ return stackFrame . getFunctionName ( ) &&
152
+ stackFrame . getFunctionName ( ) . indexOf ( 'testGenerateArtificially' ) > - 1 ;
153
+ } ;
154
+ new StackTrace ( ) . generateArtificially ( { filter : stackFrameFilter } )
155
+ . then ( callback , errback ) [ 'catch' ] ( debugErrback ) ;
156
+ } ) ;
157
+ waits ( 100 ) ;
158
+ runs ( function ( ) {
159
+ expect ( callback ) . toHaveBeenCalled ( ) ;
160
+ expect ( callback . mostRecentCall . args [ 0 ] [ 0 ] ) . toMatchStackFrame ( [ 'testGenerateArtificially' , [ ] ] ) ;
161
+ expect ( errback ) . not . toHaveBeenCalled ( ) ;
147
162
} ) ;
148
- expect ( stackFrames . length ) . toEqual ( 1 ) ;
149
163
} ) ;
150
164
} ) ;
151
165
} ) ;
0 commit comments