mirror of
https://github.com/zhigang1992/probot.git
synced 2026-06-15 10:27:43 +08:00
Silence server errors in test with default error handler
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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', () => {
|
||||
|
||||
Reference in New Issue
Block a user