Skip to content

Fix bad level arg in console plugin, other fixes #474

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

Merged
merged 1 commit into from
Jan 16, 2016
Merged
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
12 changes: 7 additions & 5 deletions plugins/console.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,20 @@ function consolePlugin(Raven, console) {

// warning level is the only level that doesn't map up
// correctly with what Sentry expects.
if (level === 'warn') level = 'warning';
if (l === 'warn') l = 'warning';
return function () {
var args = [].slice.call(arguments);
Raven.captureMessage('' + args[0], {level: level, logger: 'console', extra: { 'arguments': args }});
Raven.captureMessage('' + args.join(' '), {level: l, logger: 'console', extra: { 'arguments': args }});

// this fails for some browsers. :(
if (originalConsoleLevel) {
// IE9 doesn't allow calling apply on console functions directly
// See: https://stackoverflow.com/questions/5472938/does-ie9-support-console-log-and-is-it-a-real-function#answer-5473193
Function.prototype.bind
.call(originalConsoleLevel, originalConsole)
.apply(originalConsole, args);
Function.prototype.apply.call(
originalConsoleLevel,
originalConsole,
args
);
}
};
};
Expand Down
48 changes: 48 additions & 0 deletions test/plugins/console.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
var _Raven = require('../../src/raven');
var consolePlugin = require('../../plugins/console');

var Raven;
describe('console plugin', function () {
beforeEach(function () {
Raven = new _Raven();
Raven.config('http://[email protected]:80/2');
});

it('should call Raven.captureMessage', function () {
var console = {
debug: function () {},
info: function () {},
warn: function () {},
error: function () {}
};

consolePlugin(Raven, console);

this.sinon.stub(Raven, 'captureMessage');
console.error('Raven should capture', 'console.error');

assert.equal(Raven.captureMessage.callCount, 1);
assert.equal(Raven.captureMessage.getCall(0).args[0], 'Raven should capture console.error');
assert.deepEqual(Raven.captureMessage.getCall(0).args[1], {
level: 'error',
logger: 'console',
extra: {
arguments: ['Raven should capture', 'console.error']
}
});

Raven.captureMessage.reset();

console.warn('Raven should capture console.warn');

assert.equal(Raven.captureMessage.callCount, 1);
assert.equal(Raven.captureMessage.getCall(0).args[0], 'Raven should capture console.warn');
assert.deepEqual(Raven.captureMessage.getCall(0).args[1], {
level: 'warning', // warn => warning
logger: 'console',
extra: {
arguments: ['Raven should capture console.warn']
}
});
});
});