Skip to content

Commit de0db41

Browse files
committed
test: Fix Tracekit tests w. blob handling and some minor corrections
1 parent 18cba74 commit de0db41

File tree

2 files changed

+21
-14
lines changed

2 files changed

+21
-14
lines changed

test/vendor/tracekit-parser.test.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,18 @@
33

44
var TraceKit = require('../../vendor/TraceKit/tracekit');
55
var CapturedExceptions = require('./fixtures/captured-errors');
6+
var sinon = require('sinon');
7+
var xhr;
68

79
describe('TraceKit', function() {
10+
beforeEach(function() {
11+
xhr = sinon.useFakeXMLHttpRequest();
12+
});
13+
14+
afterEach(function() {
15+
xhr.restore();
16+
});
17+
818
describe('Parser', function() {
919
it('should parse Safari 6 error', function() {
1020
var stackFrames = TraceKit.computeStackTrace(CapturedExceptions.SAFARI_6);

vendor/TraceKit/tracekit.js

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -455,29 +455,26 @@ TraceKit.computeStackTrace = (function computeStackTraceWrapper() {
455455
if (xhr.status === 200) {
456456
var source = xhr.responseText;
457457

458-
// We trim the source down to the last 300 characters here as
459-
// sourceMappingURL is usually at the end of the file.
460-
source = source.substr(source.length - 300);
458+
// We trim the source down to the last 300 characters as sourceMappingURL is always at the end of the file.
459+
// Why 300? To be in line with: https://github.com/getsentry/sentry/blob/4af29e8f2350e20c28a6933354e4f42437b4ba42/src/sentry/lang/javascript/processor.py#L164-L175
460+
source = source.slice(-300);
461461

462462
// Now we dig out the source map URL
463-
var sourceMaps = source.match(/\/\/# {0,1}sourceMappingURL=(.*) {0,1}/);
463+
var sourceMaps = source.match(/\/\/# sourceMappingURL=(.*)$/);
464464

465-
// If we don't find a source map comment or we find more than one,
466-
// continue on to the next element. We check for a length of 2 as the
467-
// first result is always the entire match, subsequent indices are
468-
// the group matches.
469-
if (sourceMaps.length === 2) {
465+
// If we don't find a source map comment or we find more than one, continue on to the next element.
466+
if (!sourceMaps) {
470467
var sourceMapAddress = sourceMaps[1];
471468

472-
// Now we check to see if it's a relative URL. If it is, convert it
473-
// to an absolute one.
474-
if (sourceMapAddress.substr(0, 1) === '~') {
475-
sourceMapAddress = window.location.origin + sourceMapAddress.substr(1);
469+
// Now we check to see if it's a relative URL.
470+
// If it is, convert it to an absolute one.
471+
if (sourceMapAddress.charAt(0) === '~') {
472+
sourceMapAddress = window.location.origin + sourceMapAddress.slice(1);
476473
}
477474

478475
// Now we strip the '.map' off of the end of the URL and update the
479476
// element so that Sentry can match the map to the blob.
480-
element.url = sourceMapAddress.substr(0, sourceMapAddress.length - 4);
477+
element.url = sourceMapAddress.slice(0, -4);
481478
}
482479
}
483480
}

0 commit comments

Comments
 (0)