1
+ /* global Errors: false */
1
2
describe ( 'StackTrace' , function ( ) {
2
3
var callback ;
3
4
var debugCallback ;
@@ -16,18 +17,10 @@ describe('StackTrace', function () {
16
17
} ;
17
18
} ) ;
18
19
19
- describe ( '#constructor' , function ( ) {
20
- it ( 'should allow empty arguments' , function ( ) {
21
- expect ( function ( ) {
22
- new StackTrace ( ) ; // jshint ignore:line
23
- } ) . not . toThrow ( ) ;
24
- } ) ;
25
- } ) ;
26
-
27
20
describe ( '#get' , function ( ) {
28
21
it ( 'gets stacktrace from current location' , function ( ) {
29
22
runs ( function testStackTraceGet ( ) {
30
- new StackTrace ( ) . get ( ) . then ( callback , errback ) [ 'catch' ] ( debugErrback ) ;
23
+ StackTrace . get ( ) . then ( callback , errback ) [ 'catch' ] ( debugErrback ) ;
31
24
} ) ;
32
25
waits ( 100 ) ;
33
26
runs ( function ( ) {
@@ -39,9 +32,17 @@ describe('StackTrace', function () {
39
32
} ) ;
40
33
41
34
describe ( '#fromError' , function ( ) {
42
- it ( 'rejects with Error given non-Error object' , function ( ) {
35
+ var server ;
36
+ beforeEach ( function ( ) {
37
+ server = sinon . fakeServer . create ( ) ;
38
+ } ) ;
39
+ afterEach ( function ( ) {
40
+ server . restore ( ) ;
41
+ } ) ;
42
+
43
+ it ( 'rejects with Error given unparsable Error object' , function ( ) {
43
44
runs ( function ( ) {
44
- new StackTrace ( ) . fromError ( 'BOGUS' )
45
+ StackTrace . fromError ( { message : 'ERROR_MESSAGE' } )
45
46
. then ( callback , errback ) [ 'catch' ] ( errback ) ;
46
47
} ) ;
47
48
waits ( 100 ) ;
@@ -52,83 +53,49 @@ describe('StackTrace', function () {
52
53
} ) ;
53
54
54
55
it ( 'parses stacktrace from given Error object' , function ( ) {
55
- //FIXME: shims for IE9
56
56
runs ( function ( ) {
57
- try {
58
- throw new Error ( 'Yikes!' ) ;
59
- } catch ( e ) {
60
- new StackTrace ( ) . fromError ( e )
61
- . then ( callback , errback ) [ 'catch' ] ( errback ) ;
62
- }
63
- } ) ;
64
- waits ( 100 ) ;
65
- runs ( function ( ) {
66
- expect ( callback ) . toHaveBeenCalled ( ) ;
67
- expect ( errback ) . not . toHaveBeenCalled ( ) ;
57
+ server . respondWith ( 'GET' , 'http://path/to/file.js' , [ 404 , { 'Content-Type' : 'text/plain' } , '' ] ) ;
58
+ StackTrace . fromError ( Errors . IE_11 )
59
+ . then ( callback , debugErrback ) [ 'catch' ] ( debugErrback ) ;
60
+ server . respond ( ) ;
68
61
} ) ;
69
- } ) ;
70
-
71
- it ( 'totally extracts function names' , function ( ) {
72
- //FIXME: shims for IE9
73
- //FIXME: need function name for opera 12
74
- var TEST_FUNCTION = function TEST_FUNCTION ( ) {
75
- try {
76
- throw new Error ( 'Yikes!' ) ;
77
- } catch ( e ) {
78
- function onlySpecSourcesPlease ( stackFrame ) {
79
- return ( stackFrame . fileName || '' ) . indexOf ( 'stacktrace-spec.js' ) !== - 1 ;
80
- }
81
-
82
- new StackTrace ( ) . fromError ( e , { filter : onlySpecSourcesPlease } )
83
- . then ( callback , errback ) [ 'catch' ] ( errback ) ;
84
- }
85
- } ;
86
- runs ( TEST_FUNCTION ) ;
87
62
waits ( 100 ) ;
88
63
runs ( function ( ) {
89
64
expect ( callback ) . toHaveBeenCalled ( ) ;
90
65
var stackFrames = callback . mostRecentCall . args [ 0 ] ;
91
- expect ( stackFrames . length ) . toEqual ( 1 ) ;
92
- expect ( stackFrames [ 0 ] . fileName ) . toMatch ( / s t a c k t r a c e \- s p e c \. j s \b / ) ;
93
- expect ( stackFrames [ 0 ] . functionName ) . toEqual ( 'TEST_FUNCTION' ) ;
66
+ expect ( stackFrames . length ) . toEqual ( 3 ) ;
67
+ expect ( stackFrames [ 0 ] . fileName ) . toEqual ( 'http://path/to/file.js' ) ;
94
68
expect ( errback ) . not . toHaveBeenCalled ( ) ;
95
69
} ) ;
96
70
} ) ;
97
71
98
- xit ( 'uses source maps to enhance stack frames' , function ( ) {
99
-
100
- } ) ;
101
- } ) ;
102
-
103
- describe ( '#getMappedLocation' , function ( ) {
104
- var server ;
105
- beforeEach ( function ( ) {
106
- server = sinon . fakeServer . create ( ) ;
107
- } ) ;
108
- afterEach ( function ( ) {
109
- server . restore ( ) ;
110
- } ) ;
111
-
112
- it ( 'defaults to given stackframe if source map location not found' , function ( ) {
72
+ it ( 'filters returned stack' , function ( ) {
113
73
runs ( function ( ) {
114
- var stackframe = new StackFrame ( undefined , [ ] , 'http://localhost:9999/test.min.js' , 1 , 32 ) ;
115
- new StackTrace ( ) . getMappedLocation ( stackframe ) . then ( callback , errback ) [ 'catch' ] ( debugErrback ) ;
74
+ function onlyFoos ( stackFrame ) {
75
+ return stackFrame . functionName === 'foo' ;
76
+ }
77
+
78
+ StackTrace . fromError ( Errors . IE_11 , { filter : onlyFoos } )
79
+ . then ( callback , errback ) [ 'catch' ] ( debugErrback ) ;
116
80
server . requests [ 0 ] . respond ( 404 , { } , '' ) ;
117
81
} ) ;
118
82
waits ( 100 ) ;
119
83
runs ( function ( ) {
120
84
expect ( callback ) . toHaveBeenCalled ( ) ;
121
- expect ( callback . mostRecentCall . args [ 0 ] ) . toMatchStackFrame ( [ undefined , [ ] , 'http://localhost:9999/test.min.js' , 1 , 32 ] ) ;
85
+ var stackFrames = callback . mostRecentCall . args [ 0 ] ;
86
+ expect ( stackFrames . length ) . toEqual ( 1 ) ;
87
+ expect ( stackFrames [ 0 ] . fileName ) . toEqual ( 'http://path/to/file.js' ) ;
88
+ expect ( stackFrames [ 0 ] . functionName ) . toEqual ( 'foo' ) ;
122
89
expect ( errback ) . not . toHaveBeenCalled ( ) ;
123
90
} ) ;
124
91
} ) ;
125
92
126
93
it ( 'uses source maps to enhance stack frames' , function ( ) {
127
94
runs ( function ( ) {
128
- var stackframe = new StackFrame ( undefined , [ ] , ' http://localhost:9999/test.min.js' , 1 , 32 ) ;
129
- new StackTrace ( ) . getMappedLocation ( stackframe ) . then ( callback , errback ) [ 'catch' ] ( debugErrback ) ;
130
- var source = 'var foo=function(){};function bar(){}var baz=eval("XXX");\n//@ sourceMappingURL=test.js.map' ;
131
- server . requests [ 0 ] . respond ( 200 , { 'Content-Type' : 'application/x-javascript' } , source ) ;
95
+ var stack = 'TypeError: Unable to get property \'undef\' of undefined or null reference\n at foo ( http://path/to/file.js:45:13)' ;
96
+ StackTrace . fromError ( { stack : stack } ) . then ( callback , errback ) [ 'catch' ] ( debugErrback ) ;
97
+ var sourceMin = 'var foo=function(){};function bar(){}var baz=eval("XXX");\n//@ sourceMappingURL=test.js.map' ;
98
+ server . requests [ 0 ] . respond ( 200 , { 'Content-Type' : 'application/x-javascript' } , sourceMin ) ;
132
99
} ) ;
133
100
waits ( 100 ) ;
134
101
runs ( function ( ) {
@@ -138,7 +105,9 @@ describe('StackTrace', function () {
138
105
waits ( 100 ) ;
139
106
runs ( function ( ) {
140
107
expect ( callback ) . toHaveBeenCalled ( ) ;
141
- expect ( callback . mostRecentCall . args [ 0 ] ) . toMatchStackFrame ( [ 'bar' , [ ] , './test.js' , 2 , 9 ] ) ;
108
+ var stackFrames = callback . mostRecentCall . args [ 0 ] ;
109
+ expect ( stackFrames . length ) . toEqual ( 1 ) ;
110
+ expect ( stackFrames [ 0 ] ) . toMatchStackFrame ( [ 'foo' , undefined , 'http://path/to/file.js' , 45 , 13 ] ) ;
142
111
expect ( errback ) . not . toHaveBeenCalled ( ) ;
143
112
} ) ;
144
113
} ) ;
@@ -151,7 +120,7 @@ describe('StackTrace', function () {
151
120
return stackFrame . getFunctionName ( ) &&
152
121
stackFrame . getFunctionName ( ) . indexOf ( 'testGenerateArtificially' ) > - 1 ;
153
122
} ;
154
- new StackTrace ( ) . generateArtificially ( { filter : stackFrameFilter } )
123
+ StackTrace . generateArtificially ( { filter : stackFrameFilter } )
155
124
. then ( callback , errback ) [ 'catch' ] ( debugErrback ) ;
156
125
} ) ;
157
126
waits ( 100 ) ;
0 commit comments