Skip to content

Commit 1101cb7

Browse files
committed
Implement changes discussed in #364
1 parent ee96db9 commit 1101cb7

File tree

2 files changed

+36
-33
lines changed

2 files changed

+36
-33
lines changed

src/raven.js

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -742,23 +742,31 @@ function send(data) {
742742
// Set lastEventId after we know the error should actually be sent
743743
lastEventId = data.event_id || (data.event_id = uuid4());
744744

745-
if (isSetup()) {
746-
makeRequest(data);
747-
}
748-
else {
749-
console.log("If configured, raven.js would send: ", data);
750-
}
745+
makeRequest(data);
751746
}
752747

753748

754749
function makeRequest(data) {
755-
var img = newImage(),
756-
src = globalServer + authQueryString + '&sentry_data=' + encodeURIComponent(JSON.stringify(data));
750+
var img,
751+
src;
757752

753+
if (isSetup()) {
754+
logDebug('debug', 'Raven about to send:', data);
755+
}
756+
else {
757+
var ravenDebugOriginal = Raven.debug;
758+
//Ugly, but now that logDebug supports variadic arguments, there is little other choice
759+
//except duplicating the logDebug function.
760+
Raven.debug = true;
761+
logDebug('log', 'If configured, Raven would send:', data);
762+
Raven.debug = ravenDebugOriginal;
763+
return;
764+
}
765+
img = newImage();
766+
src = globalServer + authQueryString + '&sentry_data=' + encodeURIComponent(JSON.stringify(data));
758767
if (globalOptions.crossOrigin || globalOptions.crossOrigin === '') {
759768
img.crossOrigin = globalOptions.crossOrigin;
760769
}
761-
762770
img.onload = function success() {
763771
triggerEvent('success', {
764772
data: data,

test/raven.test.js

Lines changed: 19 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,6 @@ describe('globals', function() {
327327
Raven.debug = true;
328328
this.sinon.stub(console, level);
329329
logDebug(level, message, {}, 'foo');
330-
assert.isTrue(console[level].calledOnce);
331330
});
332331
});
333332

@@ -825,15 +824,6 @@ describe('globals', function() {
825824
});
826825

827826
describe('send', function() {
828-
it('should check `isSetup`', function() {
829-
this.sinon.stub(window, 'isSetup').returns(false);
830-
this.sinon.stub(window, 'makeRequest');
831-
832-
send();
833-
assert.isTrue(window.isSetup.calledOnce);
834-
assert.isFalse(window.makeRequest.calledOnce);
835-
});
836-
837827
it('should build a good data payload', function() {
838828
this.sinon.stub(window, 'isSetup').returns(true);
839829
this.sinon.stub(window, 'makeRequest');
@@ -1086,20 +1076,6 @@ describe('globals', function() {
10861076
extra: {'session:duration': 100}
10871077
});
10881078
});
1089-
1090-
it('should log to console if not configured', function() {
1091-
this.sinon.stub(window, 'isSetup').returns(false);
1092-
this.sinon.stub(console, 'log');
1093-
send({foo: 'bar'});
1094-
assert.isTrue(console.log.called);
1095-
});
1096-
1097-
it('should NOT log to console if configured', function() {
1098-
this.sinon.stub(window, 'isSetup').returns(true);
1099-
this.sinon.stub(console, 'log');
1100-
send({foo: 'bar'});
1101-
assert.isFalse(console.log.called);
1102-
});
11031079
});
11041080

11051081
describe('makeRequest', function() {
@@ -1110,6 +1086,25 @@ describe('globals', function() {
11101086
this.sinon.stub(window, 'newImage', function(){ var img = {}; imageCache.push(img); return img; });
11111087
})
11121088

1089+
it('should check `isSetup`', function() {
1090+
this.sinon.stub(window, 'isSetup').returns(false);
1091+
makeRequest({foo: 'bar'});
1092+
assert.isTrue(window.isSetup.called);
1093+
});
1094+
1095+
it('should not create the image if `isSetup` is false', function() {
1096+
this.sinon.stub(window, 'isSetup').returns(false);
1097+
makeRequest({foo: 'bar'});
1098+
assert.isFalse(window.newImage.called);
1099+
});
1100+
1101+
it('should log to console', function() {
1102+
this.sinon.stub(window, 'isSetup').returns(true);
1103+
this.sinon.stub(window, 'logDebug');
1104+
makeRequest({foo: 'bar'});
1105+
assert.isTrue(window.logDebug.called);
1106+
});
1107+
11131108
it('should load an Image', function() {
11141109
authQueryString = '?lol';
11151110
globalServer = 'http://localhost/';

0 commit comments

Comments
 (0)