-
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.
Add Koa v1 tests with autoDetectErrors=false
- Loading branch information
1 parent
1ffe2a8
commit 1fc4c0d
Showing
3 changed files
with
125 additions
and
0 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
63 changes: 63 additions & 0 deletions
63
test/node/features/fixtures/koa-1x/scenarios/app-disabled.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,63 @@ | ||
const Bugsnag = require('@bugsnag/node') | ||
const bugsnagKoa = require('@bugsnag/plugin-koa') | ||
const Koa = require('koa') | ||
|
||
Bugsnag.start({ | ||
apiKey: process.env.BUGSNAG_API_KEY, | ||
endpoints: { | ||
notify: process.env.BUGSNAG_NOTIFY_ENDPOINT, | ||
sessions: process.env.BUGSNAG_SESSIONS_ENDPOINT | ||
}, | ||
autoDetectErrors: false, | ||
plugins: [bugsnagKoa] | ||
}) | ||
|
||
|
||
const middleware = Bugsnag.getPlugin('koa') | ||
|
||
const app = new Koa() | ||
|
||
// 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 * (next) { | ||
console.log('[req]', this.url, this.path) | ||
var ctx = this | ||
setTimeout(function () { | ||
if (!ctx.headerSent) ctx.status = 500 | ||
}, 2000) | ||
yield next | ||
}) | ||
|
||
app.use(function * (next) { | ||
if (this.path === '/error-before-handler') { | ||
throw new Error('nope') | ||
} else { | ||
yield next | ||
} | ||
}) | ||
|
||
app.use(middleware.requestHandler.v1) | ||
|
||
app.use(function * (next) { | ||
if (this.path === '/') { | ||
this.body = 'ok' | ||
} else if (this.path === '/err') { | ||
throw new Error('noooop') | ||
} else if (this.path === '/ctx-throw') { | ||
this.throw(500, 'thrown') | ||
} else if (this.path === '/ctx-throw-400') { | ||
this.throw(400, 'thrown') | ||
} else if (this.path === '/throw-non-error') { | ||
throw 'error' // eslint-disable-line | ||
} else if (this.path === '/handled') { | ||
this.bugsnag.notify(new Error('handled')) | ||
yield next | ||
} else { | ||
yield next | ||
} | ||
}) | ||
|
||
app.on('error', middleware.errorHandler) | ||
|
||
app.listen(80) |
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,46 @@ | ||
Feature: @bugsnag/plugin-koa (koa v1.x support) autoDetectErrors=false | ||
|
||
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 "koa-1x-disabled" | ||
And I wait for the host "koa-1x-disabled" to open port "80" | ||
|
||
Scenario: a synchronous thrown error in a route | ||
Given I open the URL "http://koa-1x-disabled/err" | ||
Then I should receive no errors | ||
|
||
Scenario: An error created with with ctx.throw() | ||
Given I open the URL "http://koa-1x-disabled/ctx-throw" | ||
Then I should receive no errors | ||
|
||
Scenario: an error thrown before the requestHandler middleware | ||
Given I open the URL "http://koa-1x-disabled/error-before-handler" | ||
Then I should receive no errors | ||
|
||
Scenario: throwing non-Error error | ||
Given I open the URL "http://koa-1x-disabled/throw-non-error" | ||
Then I should receive no errors | ||
|
||
Scenario: A non-5XX error created with ctx.throw() | ||
Given I open the URL "http://koa-1x-disabled/ctx-throw-400" | ||
Then I should receive no errors | ||
When I wait to receive a session | ||
Then the session is valid for the session reporting API version "1" for the "Bugsnag Node" notifier | ||
And the session payload has a valid sessions array | ||
And the sessionCount "sessionsStarted" equals 1 | ||
|
||
Scenario: A handled error with ctx.bugsnag.notify() | ||
Given I open the URL "http://koa-1x-disabled/handled" | ||
When 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 false | ||
And the event "severity" equals "warning" | ||
And the exception "errorClass" equals "Error" | ||
And the exception "message" equals "handled" | ||
And the exception "type" equals "nodejs" | ||
And the "file" of stack frame 0 equals "scenarios/app-disabled.js" | ||
And the event "request.url" equals "http://koa-1x-disabled/handled" | ||
And the event "request.httpMethod" equals "GET" | ||
And the event "request.clientIp" is not null |