Silence server errors in test with default error handler

This commit is contained in:
Brandon Keepers
2017-08-29 21:58:57 -05:00
parent 90606115a4
commit d441aa6f4c
2 changed files with 15 additions and 0 deletions

View File

@@ -1,6 +1,8 @@
const expect = require('expect')
const createProbot = require('..')
process.env.LOG_LEVEL = 'fatal'
describe('Probot', () => {
let probot
let event
@@ -69,6 +71,10 @@ describe('Probot', () => {
it('allows users to configure webhook paths', async () => {
probot = createProbot({webhookPath: '/webhook'})
// Error handler to avoid printing logs
// eslint-disable-next-line handle-callback-err
probot.server.use((err, req, res, next) => { })
probot.load(robot => {
const app = robot.route()
app.get('/webhook', (req, res) => res.end('get-webhook'))
@@ -85,6 +91,10 @@ describe('Probot', () => {
})
it('defaults webhook path to `/`', async () => {
// Error handler to avoid printing logs
// eslint-disable-next-line handle-callback-err
probot.server.use((err, req, res, next) => { })
// GET requests to `/` should 404 at express level, not 400 at webhook level
await request(probot.server).get('/')
.expect(404)

View File

@@ -9,6 +9,11 @@ describe('server', function () {
beforeEach(() => {
webhook = expect.createSpy().andCall((req, res, next) => next())
server = createServer(webhook)
// Error handler to avoid printing logs
server.use(function (err, req, res, next) {
res.status(500).send(err.message)
})
})
describe('GET /ping', () => {