Skip to content

Commit f480ac2

Browse files
authored
Merge pull request #8 from fs-opensource/greenkeeper/initial
Update dependencies to enable Greenkeeper 🌴
2 parents cdef7e4 + 5c07510 commit f480ac2

File tree

8 files changed

+52
-50
lines changed

8 files changed

+52
-50
lines changed

.eslintrc.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@
55
},
66
"extends": "standard",
77
"parserOptions": {
8-
"ecmaVersion": 8
8+
"ecmaVersion": 2018
99
}
1010
}

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525

2626
------
2727

28+
[![Greenkeeper badge](https://badges.greenkeeper.io/fs-opensource/hapi-dev-errors.svg)](https://greenkeeper.io/)
29+
2830
<p align="center"><sup>Development of this hapi plugin is supported by <a href="https://futurestud.io">Future Studio University 🚀</a></sup>
2931
<br><b>
3032
Join the <a href="https://futurestud.io/university">Future Studio University and Skyrocket in Node.js</a></b>

lib/index.js

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -116,31 +116,19 @@ async function register (server, options) {
116116
}
117117

118118
const config = Object.assign({}, defaults, options)
119+
config.links = Array.isArray(config.links) ? config.links : [config.links]
119120

120-
/**
121-
* Cut early if `showErrors` is false. No need to
122-
* hook the extension point in production.
123-
*/
124121
if (!config.showErrors) {
125122
return
126123
}
127124

128-
// require `vision` plugin in case the user provides an error template
129125
if (config.template) {
130126
server.dependency(['vision'])
131127
}
132128

133-
// Make sure the `links` are an array
134-
if (!Array.isArray(config.links)) {
135-
config.links = [config.links]
136-
}
137-
138-
// extend the request lifecycle at `onPreResponse`
139-
// to change the default error handling behavior (if enabled)
140129
server.ext('onPreResponse', async (request, h) => {
141130
const error = request.response
142131

143-
// only show `bad implementation` developer errors (status code 500)
144132
if (error.isBoom && error.output.statusCode === 500) {
145133
const accept = request.raw.req.headers.accept
146134
const agent = request.raw.req.headers['user-agent']
@@ -165,9 +153,6 @@ async function register (server, options) {
165153
console.log(ForTerminal(json))
166154
}
167155

168-
// take priority:
169-
// - check "agent" header for REST request (cURL, Postman & Co.)
170-
// - check "accept" header for JSON request
171156
if (wantsJson({ accept, agent })) {
172157
const details = Object.assign({}, errorResponse, {
173158
stacktrace: errorResponse.stacktrace.split('\n').map(line => line.trim())
@@ -187,7 +172,6 @@ async function register (server, options) {
187172
.code(statusCode)
188173
}
189174

190-
// render Youch HTML template
191175
const html = await youch.toHTML()
192176

193177
return h
@@ -196,7 +180,6 @@ async function register (server, options) {
196180
.code(statusCode)
197181
}
198182

199-
// no developer error, go ahead with the response
200183
return h.continue
201184
})
202185
}

package.json

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,19 @@
1111
"youch-terminal": "~1.0.0"
1212
},
1313
"devDependencies": {
14-
"boom": "~7.2.0",
14+
"boom": "~7.3.0",
1515
"code": "~5.2.0",
16-
"eslint": "~4.19.1",
17-
"eslint-config-standard": "~11.0.0",
18-
"eslint-plugin-import": "~2.13.0",
19-
"eslint-plugin-node": "~6.0.1",
20-
"eslint-plugin-promise": "~3.8.0",
21-
"eslint-plugin-standard": "~3.1.0",
22-
"hapi": "~17.6.0",
23-
"husky": "~1.1.1",
24-
"joi": "~13.7.0",
25-
"lab": "~15.5.0",
26-
"sinon": "~6.3.5",
16+
"eslint": "~5.9.0",
17+
"eslint-config-standard": "~12.0.0",
18+
"eslint-plugin-import": "~2.14.0",
19+
"eslint-plugin-node": "~8.0.0",
20+
"eslint-plugin-promise": "~4.0.1",
21+
"eslint-plugin-standard": "~4.0.0",
22+
"hapi": "~17.8.1",
23+
"husky": "~1.2.0",
24+
"joi": "~14.3.0",
25+
"lab": "~18.0.0",
26+
"sinon": "~7.1.1",
2727
"vision": "~5.4.0"
2828
},
2929
"engines": {

test/plugin-falls-back-to-json.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const Hapi = require('hapi')
66

77
let server
88

9-
const { experiment, test, before } = (exports.lab = Lab.script())
9+
const { experiment, it, before } = (exports.lab = Lab.script())
1010

1111
experiment('hapi-dev-error falls back to json', () => {
1212
before(async () => {
@@ -32,7 +32,7 @@ experiment('hapi-dev-error falls back to json', () => {
3232
server.route(routeOptions)
3333
})
3434

35-
test('test if the plugin responds json with json accept header', async () => {
35+
it('responds json with json accept header', async () => {
3636
const response = await server.inject({
3737
url: '/error',
3838
method: 'GET',
@@ -46,7 +46,7 @@ experiment('hapi-dev-error falls back to json', () => {
4646
Code.expect(payload).to.startWith('{')
4747
})
4848

49-
test('test if the plugin responds json with curl user-agent', async () => {
49+
it('responds json with curl user-agent', async () => {
5050
const response = await server.inject({
5151
url: '/error',
5252
method: 'GET',

test/plugin-is-enabled-when-not-in-production.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const Path = require('path')
88

99
let server
1010

11-
const { experiment, test, before, beforeEach } = (exports.lab = Lab.script())
11+
const { experiment, it, before, beforeEach } = (exports.lab = Lab.script())
1212
const expect = Code.expect
1313

1414
experiment('hapi-dev-error register plugin', () => {
@@ -26,7 +26,7 @@ experiment('hapi-dev-error register plugin', () => {
2626
})
2727
})
2828

29-
test('test if the plugin is enabled in development for web requests', async () => {
29+
it('is enabled in development for web requests', async () => {
3030
const routeOptions = {
3131
path: '/showErrorsForWeb',
3232
method: 'GET',
@@ -49,7 +49,7 @@ experiment('hapi-dev-error register plugin', () => {
4949
expect(payload).to.startWith('<!DOCTYPE html>')
5050
})
5151

52-
test('test if the plugin is enabled in development for JSON/REST requests', async () => {
52+
it('is enabled in development for JSON/REST requests', async () => {
5353
const routeOptions = {
5454
path: '/showErrorsForREST',
5555
method: 'GET',
@@ -77,7 +77,7 @@ experiment('hapi-dev-error register plugin', () => {
7777
expect(payload.method).to.equal(routeOptions.method)
7878
})
7979

80-
test('test when the error is from a rejected Promise', async () => {
80+
it('test when the error is from a rejected Promise', async () => {
8181
const routeOptions = {
8282
path: '/showPromiseError',
8383
method: 'GET',
@@ -105,7 +105,7 @@ experiment('hapi-dev-error register plugin', () => {
105105
expect(payload.method).to.equal(routeOptions.method)
106106
})
107107

108-
test('test if the request payload is added to the error response', async () => {
108+
it('test if the request payload is added to the error response', async () => {
109109
const routeOptions = {
110110
path: '/with-request-payload',
111111
method: 'POST',
@@ -167,7 +167,7 @@ experiment('hapi-dev-error renders a custom template', () => {
167167
})
168168
})
169169

170-
test('render a template', async () => {
170+
it('render a template', async () => {
171171
const routeOptions = {
172172
path: '/custom-view',
173173
method: 'GET',

test/plugin-skips-non-500-responses.js

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@
33
const Lab = require('lab')
44
const Code = require('code')
55
const Hapi = require('hapi')
6+
const Boom = require('boom')
67

78
let server
89

9-
const { experiment, test, before } = (exports.lab = Lab.script())
10+
const { experiment, it, before } = (exports.lab = Lab.script())
1011
const expect = Code.expect
1112

1213
experiment('hapi-dev-error works only with 500 errors', () => {
@@ -22,13 +23,11 @@ experiment('hapi-dev-error works only with 500 errors', () => {
2223
})
2324
})
2425

25-
test('test if the plugin skips handling for non-error response', async () => {
26+
it('skips handling for non-error response', async () => {
2627
const routeOptions = {
2728
path: '/ok',
2829
method: 'GET',
29-
handler: () => {
30-
return 'ok'
31-
}
30+
handler: () => 'ok'
3231
}
3332

3433
server.route(routeOptions)
@@ -44,4 +43,22 @@ experiment('hapi-dev-error works only with 500 errors', () => {
4443
expect(response.statusCode).to.equal(200)
4544
expect(payload).to.equal('ok')
4645
})
46+
47+
it('skips handling for 404 errors', async () => {
48+
const routeOptions = {
49+
path: '/404',
50+
method: 'GET',
51+
handler: () => Boom.notFound()
52+
}
53+
54+
server.route(routeOptions)
55+
56+
const request = {
57+
url: routeOptions.path,
58+
method: routeOptions.method
59+
}
60+
61+
const response = await server.inject(request)
62+
expect(response.statusCode).to.equal(404)
63+
})
4764
})

test/plugin-uses-links.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const Code = require('code')
55
const Hapi = require('hapi')
66
const Sinon = require('sinon')
77

8-
const { experiment, test, beforeEach, afterEach } = (exports.lab = Lab.script())
8+
const { experiment, it, beforeEach, afterEach } = (exports.lab = Lab.script())
99

1010
experiment('hapi-dev-error handles custom user links', () => {
1111
async function createServer (options) {
@@ -39,7 +39,7 @@ experiment('hapi-dev-error handles custom user links', () => {
3939
console.error.restore()
4040
})
4141

42-
test('that the plugin works fine with empty links', async () => {
42+
it('works fine with empty links', async () => {
4343
const server = await createServer({ links: [] })
4444

4545
const response = await server.inject({
@@ -53,7 +53,7 @@ experiment('hapi-dev-error handles custom user links', () => {
5353
Code.expect(response.payload).to.startWith('<')
5454
})
5555

56-
test('that the plugin throws if the links are strings', async () => {
56+
it('throws if the links are strings', async () => {
5757
const server = await createServer({ links: [ 'error' ] })
5858

5959
const response = await server.inject({
@@ -68,7 +68,7 @@ experiment('hapi-dev-error handles custom user links', () => {
6868
Code.expect(response.payload).to.include('Internal Server Error')
6969
})
7070

71-
test('that the plugin throws if the links is not an array of functions', async () => {
71+
it('throws if the links is not an array of functions', async () => {
7272
const server = await createServer({ links: 'error' })
7373

7474
const response = await server.inject({
@@ -83,7 +83,7 @@ experiment('hapi-dev-error handles custom user links', () => {
8383
Code.expect(response.payload).to.include('Internal Server Error')
8484
})
8585

86-
test('that the plugin works fine with a link function', async () => {
86+
it('works fine with a link function', async () => {
8787
const server = await createServer({ links: () => `link` })
8888

8989
const response = await server.inject({

0 commit comments

Comments
 (0)