Files
shields/lib/log.spec.js
T
Paul MelnikowandGitHub 7a664ca3e8 Run prettier (#1866)
Merging this separately so the commit with the tooling change is readable. This is a follow-on to #1167 which turned prettier on.
2018-08-08 17:57:14 -04:00

66 lines
2.0 KiB
JavaScript

'use strict'
const chai = require('chai')
const expect = chai.expect
const sinon = require('sinon')
const sinonChai = require('sinon-chai')
const Raven = require('raven')
chai.use(sinonChai)
function requireUncached(module) {
delete require.cache[require.resolve(module)]
return require(module)
}
describe('log', () => {
describe('error', () => {
before(() => {
this.clock = sinon.useFakeTimers()
sinon
.stub(Raven, 'captureException')
.callsFake(function fakeFn(e, callback) {
callback(new Error(`Cannot send message "${e}" to Sentry.`))
})
// we have to create a spy before requiring 'error' function
sinon.spy(console, 'error')
this.error = requireUncached('./log').error
})
after(() => {
this.clock.restore()
console.error.restore()
Raven.captureException.restore()
})
it('should throttle errors from Raven client', () => {
this.error('test error 1')
this.error('test error 2')
this.error('test error 3')
this.clock.tick(11000)
this.error('test error 4')
this.error('test error 5')
expect(console.error).to.be.calledWithExactly(
'Failed to send captured exception to Sentry',
'Cannot send message "test error 1" to Sentry.'
)
expect(console.error).to.not.be.calledWithExactly(
'Failed to send captured exception to Sentry',
'Cannot send message "test error 2" to Sentry.'
)
expect(console.error).to.not.be.calledWithExactly(
'Failed to send captured exception to Sentry',
'Cannot send message "test error 3" to Sentry.'
)
expect(console.error).to.be.calledWithExactly(
'Failed to send captured exception to Sentry',
'Cannot send message "test error 4" to Sentry.'
)
expect(console.error).to.not.be.calledWithExactly(
'Failed to send captured exception to Sentry',
'Cannot send message "test error 5" to Sentry.'
)
})
})
})