forked from golyakov/winston-rollbar
-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix stacktrace format for rollbar (#5)
* docs: switch to yarn * fix: pass error object of stacktrace for rollbar dashboard correct format * fix: guard for null rollbar config * test: for empty rollbar key and log messages params * docs: add test command to docs * bump minor version * feat: always send error object as payload to rollbar * fix: logging with appropriate rollbar methods; rewrote unit tests * v3.2.5 * default to log level info if log method does not exist * v3.2.6
- Loading branch information
Showing
6 changed files
with
2,248 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
const RollbarTransport = require('../lib/rollbar_transport'); | ||
const rollbar = require('rollbar'); | ||
|
||
jest.mock('rollbar'); | ||
|
||
describe('RollbarTransport', () => { | ||
let transport; | ||
let rollbarMock; | ||
|
||
function createLogData(level, message, payload = {}) { | ||
const logData = { level, message, ...payload }; | ||
logData[Symbol.for('level')] = level; | ||
return logData; | ||
} | ||
|
||
beforeEach(() => { | ||
rollbarMock = { | ||
log: jest.fn(), | ||
warning: jest.fn(), | ||
error: jest.fn(), | ||
info: jest.fn(), | ||
debug: jest.fn(), | ||
}; | ||
|
||
rollbar.mockReturnValue(rollbarMock); | ||
|
||
transport = new RollbarTransport({ | ||
rollbarConfig: { accessToken: 'test' }, | ||
}); | ||
}); | ||
|
||
describe('#log', () => { | ||
it('throws an error if no accessToken is provided', () => { | ||
expect(() => new RollbarTransport({})).toThrow( | ||
"winston-transport-rollbar requires a 'rollbarConfig.accessToken' property" | ||
); | ||
}); | ||
|
||
it('logs with log level error', async () => { | ||
const logData = createLogData('error', 'test'); | ||
transport.log(logData, function() {}); | ||
|
||
expect(rollbarMock.error).toHaveBeenCalledWith(logData.message, {}, expect.any(Function)); | ||
}); | ||
|
||
it('logs with log level warn', async () => { | ||
const logData = createLogData('warn', 'test'); | ||
transport.log(logData, function() {}); | ||
|
||
expect(rollbarMock.warning).toHaveBeenCalledWith(logData.message, {}, expect.any(Function)); | ||
}); | ||
|
||
it('logs with log level info', async () => { | ||
const logData = createLogData('info', 'test'); | ||
transport.log(logData, function() {}); | ||
|
||
expect(rollbarMock.info).toHaveBeenCalledWith(logData.message, {}, expect.any(Function)); | ||
}) | ||
|
||
it('logs with log level debug', async () => { | ||
const logData = createLogData('debug', 'test'); | ||
transport.log(logData, function() {}); | ||
|
||
expect(rollbarMock.debug).toHaveBeenCalledWith(logData.message, {}, expect.any(Function)); | ||
}) | ||
|
||
it('logs additional payload as meta', () => { | ||
const logData = createLogData('error', 'test', { foo: 'bar' }); | ||
transport.log(logData, function() {}); | ||
|
||
expect(rollbarMock.error).toHaveBeenCalledWith(logData.message, { foo: 'bar' }, expect.any(Function)); | ||
}) | ||
|
||
it('logs with log level info by default', async () => { | ||
const logData = createLogData('unknown', 'test'); | ||
transport.log(logData, function() {}); | ||
|
||
expect(rollbarMock.info).toHaveBeenCalledWith(logData.message, {}, expect.any(Function)); | ||
}) | ||
}); | ||
}); |
Oops, something went wrong.