-
Notifications
You must be signed in to change notification settings - Fork 251
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
178 additions
and
2 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
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,34 @@ | ||
Feature: @bugsnag/plugin-express | ||
|
||
Background: | ||
Given I store the api key in the environment variable "BUGSNAG_API_KEY" | ||
And I store the notify endpoint in the environment variable "BUGSNAG_NOTIFY_ENDPOINT" | ||
And I store the sessions endpoint in the environment variable "BUGSNAG_SESSIONS_ENDPOINT" | ||
And I start the service "express" | ||
And I wait for the host "express" to open port "80" | ||
|
||
Scenario: adding body to request metadata | ||
When I POST the data "data=in_request_body_1" to the URL "http://express/bodytest" | ||
And I wait to receive an error | ||
Then the error is valid for the error reporting API version "4" for the "Bugsnag Node" notifier | ||
And the event "unhandled" is true | ||
And the event "severity" equals "error" | ||
And the exception "errorClass" equals "Error" | ||
And the exception "message" equals "request body" | ||
And the exception "type" equals "nodejs" | ||
And the "file" of stack frame 0 equals "scenarios/app.js" | ||
And the event "request.body.data" equals "in_request_body_1" | ||
And the event "request.httpMethod" equals "POST" | ||
And I discard the oldest error | ||
|
||
Then I POST the data "data=in_request_body_2" to the URL "http://express/bodytest" | ||
And I wait to receive an error | ||
Then the error is valid for the error reporting API version "4" for the "Bugsnag Node" notifier | ||
And the event "unhandled" is true | ||
And the event "severity" equals "error" | ||
And the exception "errorClass" equals "Error" | ||
And the exception "message" equals "request body" | ||
And the exception "type" equals "nodejs" | ||
And the "file" of stack frame 0 equals "scenarios/app.js" | ||
And the event "request.body.data" equals "in_request_body_2" | ||
And the event "request.httpMethod" equals "POST" |
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
113 changes: 113 additions & 0 deletions
113
test/node/features/fixtures/express/scenarios/app-auto-sessions.js
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,113 @@ | ||
var Bugsnag = require('@bugsnag/node') | ||
var bugsnagExpress = require('@bugsnag/plugin-express') | ||
var express = require('express') | ||
var bodyParser = require('body-parser') | ||
|
||
Bugsnag.start({ | ||
apiKey: process.env.BUGSNAG_API_KEY, | ||
endpoints: { | ||
notify: process.env.BUGSNAG_NOTIFY_ENDPOINT, | ||
sessions: process.env.BUGSNAG_SESSIONS_ENDPOINT | ||
}, | ||
featureFlags: [ | ||
{ name: 'from config 1', variant: '1234' }, | ||
{ name: 'from config 2' }, | ||
{ name: 'from config 3', variant: 'SHOULD BE REMOVED' } | ||
], | ||
autoTrackSessions: true, | ||
plugins: [bugsnagExpress] | ||
}) | ||
|
||
var middleware = Bugsnag.getPlugin('express') | ||
|
||
var app = express() | ||
|
||
app.use(middleware.requestHandler) | ||
|
||
// If the server hasn't started sending something within 2 seconds | ||
// it probably won't. So end the request and hurry the failing test | ||
// along. | ||
app.use(function (req, res, next) { | ||
setTimeout(function () { | ||
if (!res.headersSent) return res.sendStatus(500) | ||
}, 2000) | ||
next() | ||
}) | ||
|
||
app.get('/', function (req, res) { | ||
res.end('ok') | ||
}) | ||
|
||
app.get('/sync', function (req, res) { | ||
throw new Error('sync') | ||
}) | ||
|
||
app.get('/async', function (req, res) { | ||
setTimeout(function () { | ||
throw new Error('async') | ||
}, 100) | ||
}) | ||
|
||
app.get('/next', function (req, res, next) { | ||
next(new Error('next')) | ||
}) | ||
|
||
app.get('/rejection-sync', function (req, res, next) { | ||
Promise.reject(new Error('reject sync')).catch(next) | ||
}) | ||
|
||
app.get('/rejection-async', function (req, res, next) { | ||
setTimeout(function () { | ||
Promise.reject(new Error('reject async')).catch(next) | ||
}, 100) | ||
}) | ||
|
||
app.get('/string-as-error', function (req, res, next) { | ||
next('errrr') | ||
}) | ||
|
||
app.get('/throw-non-error', function (req, res, next) { | ||
throw 1 // eslint-disable-line | ||
}) | ||
|
||
app.get('/handled', function (req, res, next) { | ||
req.bugsnag.notify(new Error('handled')) | ||
res.end('OK') | ||
}) | ||
|
||
app.post('/bodytest', bodyParser.urlencoded(), function (req, res, next) { | ||
throw new Error('request body') | ||
}) | ||
|
||
app.post('/features/unhandled', bodyParser.urlencoded(), function (req, res, next) { | ||
// the request body is an object of feature flag name -> variant | ||
const featureFlags = Object.keys(req.body).map(name => ({ name, variant: req.body[name] })) | ||
|
||
req.bugsnag.addFeatureFlags(featureFlags) | ||
req.bugsnag.clearFeatureFlag('from config 3') | ||
|
||
if (req.body.hasOwnProperty('clearAllFeatureFlags')) { | ||
req.bugsnag.clearFeatureFlags() | ||
} | ||
|
||
throw new Error('oh no') | ||
}) | ||
|
||
app.post('/features/handled', bodyParser.urlencoded(), function (req, res, next) { | ||
// the request body is an object of feature flag name -> variant | ||
const featureFlags = Object.keys(req.body).map(name => ({ name, variant: req.body[name] })) | ||
|
||
req.bugsnag.addFeatureFlags(featureFlags) | ||
req.bugsnag.clearFeatureFlag('from config 3') | ||
|
||
if (req.body.hasOwnProperty('clearAllFeatureFlags')) { | ||
req.bugsnag.clearFeatureFlags() | ||
} | ||
|
||
req.bugsnag.notify(new Error('oh no')) | ||
res.end('OK') | ||
}) | ||
|
||
app.use(middleware.errorHandler) | ||
|
||
app.listen(80) |