Skip to content

Commit 26e04d7

Browse files
committed
Implement changes discussed in #364
1 parent 21526f8 commit 26e04d7

File tree

2 files changed

+51
-31
lines changed

2 files changed

+51
-31
lines changed

src/raven.js

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -741,19 +741,27 @@ function send(data) {
741741
// Set lastEventId after we know the error should actually be sent
742742
lastEventId = data.event_id || (data.event_id = uuid4());
743743

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

752747

753748
function makeRequest(data) {
754-
var img = newImage(),
755-
src = globalServer + authQueryString + '&sentry_data=' + encodeURIComponent(JSON.stringify(data));
749+
var img,
750+
src;
756751

752+
if (isSetup()) {
753+
//In two calls so data is formatted
754+
logDebug('debug', 'Raven about to send:');
755+
logDebug('debug', data);
756+
}
757+
else {
758+
//In two calls so data is formatted
759+
logDebug('log', 'If configured, Raven would send:', true);
760+
logDebug('log', data, true);
761+
return;
762+
}
763+
img = newImage();
764+
src = globalServer + authQueryString + '&sentry_data=' + encodeURIComponent(JSON.stringify(data));
757765
img.crossOrigin = 'anonymous';
758766
img.onload = function success() {
759767
triggerEvent('success', {
@@ -841,8 +849,8 @@ function uuid4() {
841849
}
842850
}
843851

844-
function logDebug(level, message) {
845-
if (window.console && console[level] && Raven.debug) {
852+
function logDebug(level, message, force) {
853+
if (window.console && console[level] && (Raven.debug || force)) {
846854
console[level](message);
847855
}
848856
}

test/raven.test.js

Lines changed: 33 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,13 @@ describe('globals', function() {
321321
logDebug(level, message);
322322
assert.isTrue(console[level].calledOnce);
323323
});
324+
325+
it('should write to console when force is true, even if Raven.debug is false', function() {
326+
Raven.debug = false;
327+
this.sinon.stub(console, level);
328+
logDebug(level, message, true);
329+
assert.isTrue(console[level].calledOnce);
330+
});
324331
});
325332

326333
describe('setAuthQueryString', function() {
@@ -817,15 +824,6 @@ describe('globals', function() {
817824
});
818825

819826
describe('send', function() {
820-
it('should check `isSetup`', function() {
821-
this.sinon.stub(window, 'isSetup').returns(false);
822-
this.sinon.stub(window, 'makeRequest');
823-
824-
send();
825-
assert.isTrue(window.isSetup.calledOnce);
826-
assert.isFalse(window.makeRequest.calledOnce);
827-
});
828-
829827
it('should build a good data payload', function() {
830828
this.sinon.stub(window, 'isSetup').returns(true);
831829
this.sinon.stub(window, 'makeRequest');
@@ -1078,23 +1076,37 @@ describe('globals', function() {
10781076
extra: {'session:duration': 100}
10791077
});
10801078
});
1081-
1082-
it('should log to console if not configured', function() {
1079+
});
1080+
1081+
describe('makeRequest', function() {
1082+
it('should check `isSetup`', function() {
10831083
this.sinon.stub(window, 'isSetup').returns(false);
1084-
this.sinon.stub(console, 'log');
1085-
send({foo: 'bar'});
1086-
assert.isTrue(console.log.called);
1084+
makeRequest({foo: 'bar'});
1085+
assert.isTrue(window.isSetup.called);
1086+
});
1087+
1088+
it('should not create the image if `isSetup` is false', function() {
1089+
this.sinon.stub(window, 'isSetup').returns(false);
1090+
this.sinon.stub(window, 'newImage');
1091+
makeRequest({foo: 'bar'});
1092+
assert.isFalse(window.newImage.called);
10871093
});
1088-
1089-
it('should NOT log to console if configured', function() {
1094+
1095+
it('should log to console', function() {
10901096
this.sinon.stub(window, 'isSetup').returns(true);
1091-
this.sinon.stub(console, 'log');
1092-
send({foo: 'bar'});
1093-
assert.isFalse(console.log.called);
1097+
this.sinon.stub(window, 'logDebug');
1098+
makeRequest({foo: 'bar'});
1099+
assert.isTrue(window.logDebug.called);
1100+
});
1101+
1102+
it('should log to console, forcing output if isSetup is false', function() {
1103+
this.sinon.stub(window, 'isSetup').returns(false);
1104+
this.sinon.stub(window, 'logDebug');
1105+
makeRequest({foo: 'bar'});
1106+
assert.isTrue(window.logDebug.called);
1107+
assert.isTrue(window.logDebug.args[0][2], 'logDebug should have been called with force=true');
10941108
});
1095-
});
10961109

1097-
describe('makeRequest', function() {
10981110
it('should load an Image', function() {
10991111
authQueryString = '?lol';
11001112
globalServer = 'http://localhost/';

0 commit comments

Comments
 (0)