-
Notifications
You must be signed in to change notification settings - Fork 36
/
Copy pathstacktrace-gps-spec.js
469 lines (389 loc) · 25.9 KB
/
stacktrace-gps-spec.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
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
// jscs:disable maximumLineLength
describe('StackTraceGPS', function() {
beforeEach(function() {
if (typeof Promise === 'undefined') {
ES6Promise.polyfill();
}
jasmine.Ajax.install();
});
afterEach(function() {
jasmine.Ajax.uninstall();
});
describe('#Constructor', function() {
it('allows for overriding the "ajax" function via the "ajax" option', function(done) {
function ajax() {
return Promise.resolve('');
}
var stackTraceGPS = new StackTraceGPS({ajax: ajax});
stackTraceGPS._get('http://localhost:9999/test.min.js').then(done, done.fail);
});
});
describe('#_get', function() {
it('avoids multiple in-flight network requests', function(done) {
jasmine.Ajax.stubRequest('http://localhost:9999/test.min.js').andReturn({responseText: 'OK'});
var stackTraceGPS = new StackTraceGPS();
stackTraceGPS._get('http://localhost:9999/test.min.js').then(callback, done.fail);
stackTraceGPS._get('http://localhost:9999/test.min.js').then(callback, done.fail);
var callCount = 0;
function callback() {
callCount++;
if (callCount === 2) {
expect(jasmine.Ajax.requests.count()).toBe(1);
done();
}
}
});
});
describe('#_getSourceMapConsumer', function() {
it('avoids duplicate SourceMapConsumers', function(done) {
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"}';
var sourceMapUrl = 'http://localhost:9999/test.js.map';
jasmine.Ajax.stubRequest(sourceMapUrl).andReturn({responseText: sourceMap});
var stackTraceGPS = new StackTraceGPS();
stackTraceGPS._getSourceMapConsumer(sourceMapUrl).then(callback, done.fail);
stackTraceGPS._getSourceMapConsumer(sourceMapUrl).then(callback, done.fail);
var callCount = 0;
function callback() {
callCount++;
if (callCount === 1) {
expect(stackTraceGPS.sourceMapConsumerCache[sourceMapUrl]).toBeTruthy();
} else if (callCount === 2) {
expect(Object.keys(stackTraceGPS.sourceMapConsumerCache).length).toBe(1);
done();
}
}
});
});
describe('#findFunctionName', function() {
it('rejects given non-object StackFrame', function(done) {
StackTraceGPS().findFunctionName('').then(done.fail, done); // jshint ignore:line
});
it('rejects given invalid URL String', function(done) {
new StackTraceGPS().findFunctionName(new StackFrame()).then(done.fail, done);
});
it('rejects given invalid line number', function(done) {
var stackframe = new StackFrame({fileName: 'http://localhost:9999/file.js'});
new StackTraceGPS().findFunctionName(stackframe).then(done.fail, done);
});
it('rejects given invalid column number', function(done) {
var stackframe = new StackFrame({args: [], fileName: 'http://localhost:9999/file.js', lineNumber: 10, columnNumber: -1});
new StackTraceGPS().findFunctionName(stackframe).then(done.fail, done);
});
it('rejects if source file could not be found', function(done) {
jasmine.Ajax.stubRequest('http://localhost:9999/file.js').andReturn({status: 404});
var stackframe = new StackFrame({args: [], fileName: 'http://localhost:9999/file.js', lineNumber: 23, columnNumber: 0});
new StackTraceGPS().findFunctionName(stackframe).then(done.fail, errback);
function errback(error) {
expect(error.message).toEqual('HTTP status: 404 retrieving http://localhost:9999/file.js');
done();
}
});
// Expected spy errback to have been called with [ { line : 123, column : 63, sourceURL : '/Users/ewendelin/src/stacktracejs/stacktrace-gps/spec/stacktrace-gps-spec.js' } ] but actual calls were [ { line : 9, column : 9351, sourceURL : '/Users/ewendelin/src/stacktracejs/stacktrace-gps/stacktrace-gps.js' } ]
it('rejects in offline mode if sources not in source cache', function(done) {
var stackframe = new StackFrame({args: [], fileName: 'http://localhost:9999/file.js', lineNumber: 23, columnNumber: 0});
new StackTraceGPS({offline: true}).findFunctionName(stackframe).then(done.fail, done);
});
it('resolves sources from given sourceCache', function(done) {
var stackframe = new StackFrame({args: [], fileName: 'http://localhost:9999/file.js', lineNumber: 1, columnNumber: 4});
var sourceCache = {'http://localhost:9999/file.js': 'var foo = function() {};\nfunction bar() {}\nvar baz = eval("XXX")'};
new StackTraceGPS({sourceCache: sourceCache})
.findFunctionName(stackframe)
.then(callback, done.fail);
function callback(stackframe) {
expect(stackframe).toEqual(new StackFrame({functionName: 'foo', args: [], fileName: 'http://localhost:9999/file.js', lineNumber: 1, columnNumber: 4}));
done();
}
});
it('resolves source for class method', function(done) {
var stackframe = new StackFrame({args: [], fileName: 'http://localhost:9999/file.js', lineNumber: 2, columnNumber: 0});
var sourceCache = {'http://localhost:9999/file.js': 'class Foo {\nbar () {\n}\n }\n'};
new StackTraceGPS({sourceCache: sourceCache})
.findFunctionName(stackframe)
.then(callback, done.fail);
function callback(stackframe) {
expect(stackframe.functionName).toEqual('bar');
done();
}
});
it('resolves source for fat arrow functions', function(done) {
var stackframe = new StackFrame({args: [], fileName: 'http://localhost:9999/file.js', lineNumber: 1, columnNumber: 4});
var sourceCache = {'http://localhost:9999/file.js': 'var meow = () => { }'};
new StackTraceGPS({sourceCache: sourceCache})
.findFunctionName(stackframe)
.then(callback, done.fail);
function callback(stackframe) {
expect(stackframe.functionName).toEqual('meow');
done();
}
});
it('finds function name within function expression', function(done) {
var source = 'var foo = function() {};\nfunction bar() {}\nvar baz = eval("XXX")';
jasmine.Ajax.stubRequest('http://localhost:9999/file.js').andReturn({responseText: source});
var stackframe = new StackFrame({args: [], fileName: 'http://localhost:9999/file.js', lineNumber: 1, columnNumber: 4});
new StackTraceGPS().findFunctionName(stackframe).then(callback, done.fail);
function callback(stackframe) {
expect(stackframe.functionName).toEqual('foo');
done();
}
});
it('finds function name within function declaration', function(done) {
var source = 'var foo = function() {};\nfunction bar() {}\nvar baz = eval("XXX")';
jasmine.Ajax.stubRequest('http://localhost:9999/file.js').andReturn({responseText: source});
var stackframe = new StackFrame({args: [], fileName: 'http://localhost:9999/file.js', lineNumber: 2, columnNumber: 0});
new StackTraceGPS().findFunctionName(stackframe).then(callback, done.fail);
function callback(stackframe) {
expect(stackframe.functionName).toEqual('bar');
done();
}
});
it('ignores special case invalid function declaration', function(done) {
var source = 'true ? warning(ReactCurrentOwner.current == null, \'_renderNewRootComponent(): Render methods should be a pure function \' + \'of props and state; triggering nested component updates from \' + \'render is not allowed. If necessary, trigger nested updates in \' + \'componentDidUpdate. Check the render method of %s.\', ReactCurrentOwner.current && ReactCurrentOwner.current.getName() || \'ReactCompositeComponent\') : void 0;';
jasmine.Ajax.stubRequest('http://localhost:9999/file.js').andReturn({responseText: source});
var originalStackFrame = new StackFrame({functionName: '@test@', args: [], fileName: 'http://localhost:9999/file.js', lineNumber: 1, columnNumber: 0});
new StackTraceGPS().findFunctionName(originalStackFrame).then(callback, done.fail);
function callback(stackframe) {
expect(stackframe).toEqual(originalStackFrame);
done();
}
});
it('finds function name within function evaluation', function(done) {
var source = 'var foo = function() {};\nfunction bar() {}\nvar baz = eval("XXX")';
jasmine.Ajax.stubRequest('http://localhost:9999/file.js').andReturn({responseText: source});
var stackframe = new StackFrame({args: [], fileName: 'http://localhost:9999/file.js', lineNumber: 3, columnNumber: 3});
new StackTraceGPS().findFunctionName(stackframe).then(callback, done.fail);
function callback(stackframe) {
expect(stackframe.functionName).toEqual('baz');
done();
}
});
it('finds function name within static functions', function(done) {
var stackframe = new StackFrame({args: [], fileName: 'http://localhost:9999/file.js', lineNumber: 2, columnNumber: 8});
var sourceCache = {'http://localhost:9999/file.js': 'class Foo {\nstatic woof() {\n}\n}'};
new StackTraceGPS({sourceCache: sourceCache}).findFunctionName(stackframe).then(callback, done.fail);
function callback(stackframe) {
expect(stackframe.functionName).toEqual('woof');
done();
}
});
it('ignores special case interpreting control structures as the function parameter list', function(done) {
var source = 'if (a) { foo(); } else if (b) { bar(); }';
jasmine.Ajax.stubRequest('http://localhost:9999/file.js').andReturn({responseText: source});
var originalStackFrame = new StackFrame({functionName: '@test@', args: [], fileName: 'http://localhost:9999/file.js', lineNumber: 1, columnNumber: 0});
new StackTraceGPS().findFunctionName(originalStackFrame).then(callback, done.fail);
function callback(stackframe) {
expect(stackframe).toEqual(originalStackFrame);
done();
}
});
it('ignores special case interpreting control structures as the function name', function(done) {
var source = 'functionCall()\nif (condition) {';
jasmine.Ajax.stubRequest('http://localhost:9999/file.js').andReturn({responseText: source});
var originalStackFrame = new StackFrame({functionName: '@test@', args: [], fileName: 'http://localhost:9999/file.js', lineNumber: 2, columnNumber: 0});
new StackTraceGPS().findFunctionName(originalStackFrame).then(callback, done.fail);
function callback(stackframe) {
expect(stackframe).toEqual(originalStackFrame);
done();
}
});
it('ignores commented out function definitions', function(done) {
var source = 'var foo = function() {};\n//function bar() {}\nvar baz = eval("XXX")';
jasmine.Ajax.stubRequest('http://localhost:9999/file.js').andReturn({responseText: source});
var stackframe = new StackFrame({args: [], fileName: 'http://localhost:9999/file.js', lineNumber: 2, columnNumber: 0});
new StackTraceGPS().findFunctionName(stackframe).then(callback, done.fail);
function callback(stackframe) {
expect(stackframe).toEqual(new StackFrame({functionName: 'foo', args: [], fileName: 'http://localhost:9999/file.js', lineNumber: 2, columnNumber: 0}));
done();
}
});
it('resolves to undefined if function name could not be found', function(done) {
jasmine.Ajax.stubRequest('http://localhost:9999/file.js').andReturn({status: 200});
var stackframe = new StackFrame({args: [], fileName: 'http://localhost:9999/file.js', lineNumber: 1, columnNumber: 0});
new StackTraceGPS().findFunctionName(stackframe).then(callback, done.fail);
function callback(stackframe) {
expect(stackframe).toEqual(new StackFrame({args: [], fileName: 'http://localhost:9999/file.js', lineNumber: 1, columnNumber: 0}));
done();
}
});
it('does not replace non-anonymous function name with anonymous', function(done) {
jasmine.Ajax.stubRequest('http://localhost:9999/file.js').andReturn({status: 200});
var originalStackFrame = new StackFrame({functionName: 'foo', args: [], fileName: 'http://localhost:9999/file.js', lineNumber: 1, columnNumber: 0});
new StackTraceGPS().findFunctionName(originalStackFrame).then(callback, done.fail);
function callback(stackframe) {
expect(stackframe).toEqual(originalStackFrame);
done();
}
});
it('caches subsequent requests to the same location', function(done) {
var unit = new StackTraceGPS();
var source = 'var foo = function() {};\nfunction bar() {}\nvar baz = eval("XXX")';
jasmine.Ajax.stubRequest('http://localhost:9999/file.js').andReturn({responseText: source});
var stackframe = new StackFrame({args: [], fileName: 'http://localhost:9999/file.js', lineNumber: 3, columnNumber: 3});
unit.findFunctionName(stackframe).then(callback, done.fail);
var stackframe2 = new StackFrame({args: [], fileName: 'http://localhost:9999/file.js', lineNumber: 2, columnNumber: 0});
unit.findFunctionName(stackframe2).then(callback, done.fail);
var callCount = 0;
function callback() {
if (++callCount == 2) {
expect(jasmine.Ajax.requests.count()).toBe(1);
done();
}
}
});
});
describe('#getMappedLocation', function() {
it('rejects given invalid StackFrame', function(done) {
new StackTraceGPS().getMappedLocation('BOGUS').then(done.fail, done);
});
it('rejects if sourceMapURL not found', function(done) {
var source = 'var foo=function(){};function bar(){}var baz=eval("XXX");';
jasmine.Ajax.stubRequest('http://localhost:9999/file.js').andReturn({responseText: source});
var stackframe = new StackFrame({args: [], fileName: 'http://localhost:9999/file.js', lineNumber: 23, columnNumber: 0});
new StackTraceGPS().getMappedLocation(stackframe).then(done.fail, done);
});
it('rejects if source map file 404s', function(done) {
var source = 'var foo=function(){};function bar(){}var baz=eval("XXX");\n//# sourceMappingURL=test.js.map';
jasmine.Ajax.stubRequest('http://localhost:9999/test.js').andReturn({responseText: source});
jasmine.Ajax.stubRequest('http://localhost:9999/test.js.map').andReturn({status: 404});
var stackframe = new StackFrame({args: [], fileName: 'http://localhost:9999/test.js', lineNumber: 23, columnNumber: 0});
new StackTraceGPS().getMappedLocation(stackframe).then(done.fail, done);
});
describe('with inline sourcemaps', function() {
beforeEach(function() {
var sourceMin = 'var foo=function(){};function bar(){}var baz=eval("XXX");//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInRlc3QuanMiXSwibmFtZXMiOlsiZm9vIiwiYmFyIiwiYmF6IiwiZXZhbCJdLCJtYXBwaW5ncyI6IkFBQUEsR0FBSUEsS0FBTSxZQUdWLFNBQVNDLFFBRVQsR0FBSUMsS0FBTUMsS0FBTSJ9';
jasmine.Ajax.stubRequest('test.min.js').andReturn({responseText: sourceMin});
this.stackframe = new StackFrame({args: [], fileName: 'test.min.js', lineNumber: 1, columnNumber: 47});
});
it('supports inline source maps', function(done) {
new StackTraceGPS().getMappedLocation(this.stackframe).then(callback, done.fail);
function callback(stackframe) {
expect(stackframe).toEqual(new StackFrame({functionName: 'eval', args: [], fileName: 'test.js', lineNumber: 6, columnNumber: 10}));
done();
}
});
it('uses opts.atob if it was supplied in options', function(done) {
var atobSpy = jasmine.createSpy('atobSpy').and.callFake(function(str) {
return window.atob(str);
});
new StackTraceGPS({atob: atobSpy}).getMappedLocation(this.stackframe).then(callback);
function callback() {
expect(atobSpy).toHaveBeenCalled();
done();
}
});
it('rejects if atob() does not exist', function(done) {
var oldAtob = window.atob;
window.atob = null;
new StackTraceGPS().getMappedLocation(this.stackframe).then(done.fail, errback)['catch'](errback);
function errback(error) {
expect(error.message).toEqual('You must supply a polyfill for window.atob in this environment');
window.atob = oldAtob;
done();
}
});
});
it('tolerates inline source maps with parameters set', function(done) {
var sourceMin = 'var foo=function(){};function bar(){}var baz=eval("XXX");//# sourceMappingURL=data:application/json;charset=utf8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInRlc3QuanMiXSwibmFtZXMiOlsiZm9vIiwiYmFyIiwiYmF6IiwiZXZhbCJdLCJtYXBwaW5ncyI6IkFBQUEsR0FBSUEsS0FBTSxZQUdWLFNBQVNDLFFBRVQsR0FBSUMsS0FBTUMsS0FBTSJ9';
jasmine.Ajax.stubRequest('test.min.js').andReturn({responseText: sourceMin});
this.stackframe = new StackFrame({args: [], fileName: 'test.min.js', lineNumber: 1, columnNumber: 47});
new StackTraceGPS().getMappedLocation(this.stackframe).then(callback, done.fail);
function callback(stackframe) {
expect(stackframe).toEqual(new StackFrame({functionName: 'eval', args: [], fileName: 'test.js', lineNumber: 6, columnNumber: 10}));
done();
}
});
it('ignores all but the last sourceMappingURL in the file', function (done) {
var source = 'var foo=function(){};\n//# sourceMappingURL=ignoreme.js.map\nfunction bar(){}var baz=eval("XXX");\n//@ sourceMappingURL=test.js.map';
jasmine.Ajax.stubRequest('http://localhost:9999/test.min.js').andReturn({responseText: source});
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"}';
jasmine.Ajax.stubRequest('http://localhost:9999/test.js.map').andReturn({responseText: sourceMap});
var stackframe = new StackFrame({args: [], fileName: 'http://localhost:9999/test.min.js', lineNumber: 1, columnNumber: 5});
new StackTraceGPS().getMappedLocation(stackframe).then(callback, done.fail);
function callback(stackframe) {
expect(stackframe).toEqual(new StackFrame({functionName: 'foo', args: [], fileName: 'http://localhost:9999/test.js', lineNumber: 1, columnNumber: 4}));
done();
}
});
describe('given source and source map that resolves', function() {
beforeEach(function() {
var source = 'var foo=function(){};function bar(){}var baz=eval("XXX");\n//@ sourceMappingURL=test.js.map\n//# sourceURL=test.js';
jasmine.Ajax.stubRequest('http://localhost:9999/test.min.js').andReturn({responseText: source});
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"}';
jasmine.Ajax.stubRequest('http://localhost:9999/test.js.map').andReturn({responseText: sourceMap});
});
it('retrieves source mapped location for function expressions', function(done) {
var stackframe = new StackFrame({args: [], fileName: 'http://localhost:9999/test.min.js', lineNumber: 1, columnNumber: 5});
new StackTraceGPS().getMappedLocation(stackframe).then(callback, done.fail);
function callback(stackframe) {
expect(stackframe).toEqual(new StackFrame({functionName: 'foo', args: [], fileName: 'http://localhost:9999/test.js', lineNumber: 1, columnNumber: 4}));
done();
}
});
it('retrieves source mapped location for function declarations', function(done) {
var stackframe = new StackFrame({args: [], fileName: 'http://localhost:9999/test.min.js', lineNumber: 1, columnNumber: 32});
new StackTraceGPS().getMappedLocation(stackframe).then(callback, done.fail);
function callback(stackframe) {
expect(stackframe).toEqual(new StackFrame({functionName: 'bar', args: [], fileName: 'http://localhost:9999/test.js', lineNumber: 2, columnNumber: 9}));
done();
}
});
it('retrieves source mapped location for eval', function(done) {
var stackframe = new StackFrame({args: [], fileName: 'http://localhost:9999/test.min.js', lineNumber: 1, columnNumber: 47});
new StackTraceGPS().getMappedLocation(stackframe).then(callback, done.fail);
function callback(stackframe) {
expect(stackframe).toEqual(new StackFrame({functionName: 'eval', args: [], fileName: 'http://localhost:9999/test.js', lineNumber: 3, columnNumber: 10}));
done();
}
});
it('does not replace non-empty functionName with empty value', function(done) {
var stackframe = new StackFrame({functionName: 'foo', args: [], fileName: 'http://localhost:9999/test.min.js', lineNumber: 2000, columnNumber: 4200});
new StackTraceGPS().getMappedLocation(stackframe).then(callback, done.fail);
function callback(stackframe) {
expect(stackframe).toEqual(stackframe);
done();
}
});
});
describe('given cache entry for source map', function() {
it('resolves SourceMapConsumer from cache', function(done) {
var stackframe = new StackFrame({args: [], fileName: 'http://localhost:9999/file.min.js', lineNumber: 1, columnNumber: 4});
var sourceCache = {'http://localhost:9999/file.min.js': 'var foo=function(){};function bar(){}var baz=eval("XXX");\n//# sourceMappingURL=file.js.map'};
var sourceMap = '{"version":3,"sources":["./file.js"],"sourceRoot":"http://localhost:9999/","names":["foo","bar","baz","eval"],"mappings":"AAAA,GAAIA,KAAM,YACV,SAASC,QACT,GAAIC,KAAMC,KAAK","file":"file.min.js"}';
var sourceMapConsumerCache = {'http://localhost:9999/file.js.map': new SourceMap.SourceMapConsumer(sourceMap)};
new StackTraceGPS({sourceCache: sourceCache, sourceMapConsumerCache: sourceMapConsumerCache})
.getMappedLocation(stackframe)
.then(callback, done.fail);
function callback(stackframe) {
expect(stackframe).toEqual(new StackFrame({functionName: 'foo', args: [], fileName: 'http://localhost:9999/file.js', lineNumber: 1, columnNumber: 4}));
done();
}
});
});
});
describe('#pinpoint', function() {
beforeEach(function() {
var sourceMin = 'var foo=function(){};function bar(){}var baz=eval("XXX");\n//@ sourceMappingURL=test.js.map';
jasmine.Ajax.stubRequest('test.min.js').andReturn({responseText: sourceMin});
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"}';
jasmine.Ajax.stubRequest('test.js.map').andReturn({responseText: sourceMap});
});
it('combines findFunctionName and getMappedLocation', function(done) {
var source = 'var foo = function() {};\nfunction bar() {}\nvar baz = eval("XXX")';
jasmine.Ajax.stubRequest('test.js').andReturn({responseText: source});
var stackframe = new StackFrame({args: [], fileName: 'test.min.js', lineNumber: 1, columnNumber: 47});
new StackTraceGPS().pinpoint(stackframe).then(callback, done.fail);
function callback(stackframe) {
expect(stackframe).toEqual(new StackFrame({functionName: 'baz', args: [], fileName: 'test.js', lineNumber: 3, columnNumber: 10}));
done();
}
});
it('resolves with mapped location even if find function name fails', function(done) {
jasmine.Ajax.stubRequest('test.js').andError();
var stackframe = new StackFrame({args: [], fileName: 'test.min.js', lineNumber: 1, columnNumber: 47});
new StackTraceGPS().pinpoint(stackframe).then(callback, done.fail);
function callback(stackframe) {
expect(stackframe).toEqual(new StackFrame({functionName: 'eval', args: [], fileName: 'test.js', lineNumber: 3, columnNumber: 10}));
done();
}
});
});
});