Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Log to console what would be sent to the server when raven isn't configured #364

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 16 additions & 13 deletions src/raven.js
Original file line number Diff line number Diff line change
Expand Up @@ -232,10 +232,6 @@ var Raven = {
* @return {Raven}
*/
captureException: function(ex, options) {
if (!isSetup()) {
return Raven;
}

// If not an Error is passed through, recall as a message instead
if (!isError(ex)) return Raven.captureMessage(ex, options);

Expand Down Expand Up @@ -267,10 +263,6 @@ var Raven = {
* @return {Raven}
*/
captureMessage: function(msg, options) {
if (!isSetup()) {
return Raven;
}

// config() automagically converts ignoreErrors from a list to a RegExp so we need to test for an
// early call; we'll error on the side of logging anything called before configuration since it's
// probably something you should see:
Expand Down Expand Up @@ -699,8 +691,6 @@ function getHttpData() {
}

function send(data) {
if (!isSetup()) return;

var baseData = {
project: globalProject,
logger: globalOptions.logger,
Expand Down Expand Up @@ -757,13 +747,26 @@ function send(data) {


function makeRequest(data) {
var img = newImage(),
src = globalServer + authQueryString + '&sentry_data=' + encodeURIComponent(JSON.stringify(data));
var img,
src;

if (isSetup()) {
logDebug('debug', 'Raven about to send:', data);
}
else {
var ravenDebugOriginal = Raven.debug;
//Ugly, but now that logDebug supports variadic arguments, there is little other choice
//except duplicating the logDebug function.
Raven.debug = true;
logDebug('log', 'If configured, Raven would send:', data);
Raven.debug = ravenDebugOriginal;
return;
}
img = newImage();
src = globalServer + authQueryString + '&sentry_data=' + encodeURIComponent(JSON.stringify(data));
if (globalOptions.crossOrigin || globalOptions.crossOrigin === '') {
img.crossOrigin = globalOptions.crossOrigin;
}

img.onload = function success() {
triggerEvent('success', {
data: data,
Expand Down
39 changes: 25 additions & 14 deletions test/raven.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,6 @@ describe('globals', function() {
Raven.debug = true;
this.sinon.stub(console, level);
logDebug(level, message, {}, 'foo');
assert.isTrue(console[level].calledOnce);
});
});

Expand Down Expand Up @@ -825,15 +824,6 @@ describe('globals', function() {
});

describe('send', function() {
it('should check `isSetup`', function() {
this.sinon.stub(window, 'isSetup').returns(false);
this.sinon.stub(window, 'makeRequest');

send();
assert.isTrue(window.isSetup.calledOnce);
assert.isFalse(window.makeRequest.calledOnce);
});

it('should build a good data payload', function() {
this.sinon.stub(window, 'isSetup').returns(true);
this.sinon.stub(window, 'makeRequest');
Expand Down Expand Up @@ -1096,6 +1086,25 @@ describe('globals', function() {
this.sinon.stub(window, 'newImage', function(){ var img = {}; imageCache.push(img); return img; });
})

it('should check `isSetup`', function() {
this.sinon.stub(window, 'isSetup').returns(false);
makeRequest({foo: 'bar'});
assert.isTrue(window.isSetup.called);
});

it('should not create the image if `isSetup` is false', function() {
this.sinon.stub(window, 'isSetup').returns(false);
makeRequest({foo: 'bar'});
assert.isFalse(window.newImage.called);
});

it('should log to console', function() {
this.sinon.stub(window, 'isSetup').returns(true);
this.sinon.stub(window, 'logDebug');
makeRequest({foo: 'bar'});
assert.isTrue(window.logDebug.called);
});

it('should load an Image', function() {
authQueryString = '?lol';
globalServer = 'http://localhost/';
Expand Down Expand Up @@ -1772,8 +1781,9 @@ describe('Raven (public API)', function() {
it('should not throw an error if not configured', function() {
this.sinon.stub(Raven, 'isSetup').returns(false);
this.sinon.stub(window, 'send')
Raven.captureMessage('foo');
assert.isFalse(window.send.called);
assert.doesNotThrow(function() {
Raven.captureMessage('foo');
});
});

});
Expand Down Expand Up @@ -1830,8 +1840,9 @@ describe('Raven (public API)', function() {
it('should not throw an error if not configured', function() {
this.sinon.stub(Raven, 'isSetup').returns(false);
this.sinon.stub(window, 'handleStackInfo')
Raven.captureException(new Error('err'));
assert.isFalse(window.handleStackInfo.called);
assert.doesNotThrow(function() {
Raven.captureException(new Error('err'));
});
});
});

Expand Down