-
Notifications
You must be signed in to change notification settings - Fork 280
Description
in stacktrace-spec.js, the "uses source maps to enhance stack frames" spec doesn't seem to actually test using source maps.
The first thing that I would expect would be for the error to be thrown in a minified file (something like path/to/file.js:1:450). Right now the test expects the error to remain on the same line after the sourcemap enriching has happened (line 45, char 13). The whole point of enriching is to map the uglified line back to its source, and this test doesn't seem to be doing that.
The second thing is that I don't think the test is using the mocked web requests at all. I commented out the server code and the test still passes, which indicates to me that this test is not actually testing this issue correctly.
Here's the test that is still passing even with the network requests removed.
it('uses source maps to enhance stack frames', function () {
runs(function () {
//comment out the network requests. the test still passes for some reason...
// var sourceMin = 'var foo=function(){};function bar(){}var baz=eval("XXX");\n//@ sourceMappingURL=test.js.map';
// 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"}';
// server.respondWith('GET', 'http://path/to/file.js', [200, {'Content-Type': 'application/x-javascript'}, sourceMin]);
// server.respondWith('GET', 'test.js.map', [200, {'Content-Type': 'application/json'}, sourceMap]);
var stack = 'TypeError: Unable to get property \'undef\' of undefined or null reference\n at foo (http://path/to/file.js:45:13)';
StackTrace.fromError({stack: stack}).then(callback, errback)['catch'](errback);
server.respond();
});
waits(100);
runs(function () {
server.respond();
});
waits(100);
runs(function () {
expect(callback).toHaveBeenCalled();
var stackFrames = callback.mostRecentCall.args[0];
expect(stackFrames.length).toEqual(1);
debugger;
expect(stackFrames[0]).toMatchStackFrame(['foo', undefined, 'http://path/to/file.js', 45, 13]);
expect(errback).not.toHaveBeenCalled();
});
});
I created a test that I think should probably pass. I don't know enough about this codebase and sourcemaps to know exactly how to fix this. I just guessed what the column numbers should be, but once the code is working it should be easy enough to spot that I miscounted by 1 or 2 characters and adjust the number accordingly
it('uses source maps to enhance stack frames', function () {
runs(function () {
var sourceMin = 'function increment(){someVariable+=2,null.x()}var someVariable=2;increment();\n//# sourceMappingURL=file.min.js.map';
var sourceMap = '{"version":3,"sources":["file.js"],"names":["increment","someVariable","x"],"mappings":"AAEA,QAASA,aACRC,cAA8B,EAE9B,KAAKC,IALN,GAAID,cAAe,CACnBD","file":"file.min.js","sourcesContent":["var someVariable = 2;\r\nincrement();\r\nfunction increment(){\r\n\tsomeVariable = someVariable + 2;\r\n\t//cause an error to occur\r\n\tnull.x();\r\n}"],"sourceRoot":"/source/"}';
server.respondWith('GET', 'http://path/to/file.js', [200, {'Content-Type': 'application/x-javascript'}, sourceMin]);
server.respondWith('GET', 'test.js.map', [200, {'Content-Type': 'application/json'}, sourceMap]);
var stack = 'TypeError: Cannot read property \'x\' of null\n at increment (http://path/to/file.js:1:41)';
StackTrace.fromError({stack: stack}).then(callback, errback)['catch'](errback);
server.respond();
});
waits(100);
runs(function () {
server.respond();
});
waits(100);
runs(function () {
expect(callback).toHaveBeenCalled();
var stackFrames = callback.mostRecentCall.args[0];
expect(stackFrames.length).toEqual(1);
debugger;
expect(stackFrames[0]).toMatchStackFrame(['foo', undefined, 'http://path/to/file.js', 6, 6]);
expect(errback).not.toHaveBeenCalled();
});
});