@fastify/express 1.1.0 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,49 +1,19 @@
1
1
  name: CI
2
- 'on':
2
+
3
+ on:
3
4
  push:
4
5
  paths-ignore:
5
- - docs/**
6
+ - 'docs/**'
6
7
  - '*.md'
7
8
  pull_request:
8
9
  paths-ignore:
9
- - docs/**
10
+ - 'docs/**'
10
11
  - '*.md'
12
+
11
13
  jobs:
12
14
  test:
13
- runs-on: ${{ matrix.os }}
14
- strategy:
15
- matrix:
16
- node-version:
17
- - 10
18
- - 12
19
- - 14
20
- - 16
21
- os:
22
- - macos-latest
23
- - ubuntu-latest
24
- - windows-latest
25
- steps:
26
- - uses: actions/checkout@v3
27
- - name: Use Node.js
28
- uses: actions/setup-node@v3
29
- with:
30
- node-version: ${{ matrix.node-version }}
31
- - name: Install Dependencies
32
- run: |
33
- npm install --ignore-scripts
34
- - name: Run Tests
35
- run: |
36
- npm test
37
- automerge:
38
- needs: test
39
- runs-on: ubuntu-latest
40
- permissions:
41
- pull-requests: write
42
- contents: write
43
- steps:
44
- - uses: fastify/github-action-merge-dependabot@v3
45
- if: >-
46
- ${{ github.actor == 'dependabot[bot]' && github.event_name ==
47
- 'pull_request' }}
48
- with:
49
- github-token: ${{ secrets.GITHUB_TOKEN }}
15
+ uses: fastify/workflows/.github/workflows/plugins-ci.yml@v3
16
+
17
+
18
+
19
+
package/README.md CHANGED
@@ -2,7 +2,6 @@
2
2
 
3
3
  ![CI](https://github.com/fastify/fastify-express/workflows/CI/badge.svg)
4
4
  [![NPM version](https://img.shields.io/npm/v/@fastify/express.svg?style=flat)](https://www.npmjs.com/package/@fastify/express)
5
- [![Known Vulnerabilities](https://snyk.io/test/github/fastify/fastify-express/badge.svg)](https://snyk.io/test/github/fastify/fastify-express)
6
5
  [![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat)](https://standardjs.com/)
7
6
 
8
7
  This plugin adds full [Express](http://expressjs.com) compatibility to Fastify, it exposes the same `use` function of Express, and it allows you to use any Express middleware or application.<br/>
package/index.js CHANGED
@@ -91,6 +91,6 @@ function expressPlugin (fastify, options, next) {
91
91
  }
92
92
 
93
93
  module.exports = fp(expressPlugin, {
94
- fastify: '>=3.0.0',
95
- name: 'fastify-express'
94
+ fastify: '4.x',
95
+ name: '@fastify/express'
96
96
  })
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fastify/express",
3
- "version": "1.1.0",
3
+ "version": "2.0.0",
4
4
  "description": "Express compatibility layer for Fastify",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -29,10 +29,10 @@
29
29
  "@types/node": "*",
30
30
  "body-parser": "^1.20.0",
31
31
  "cors": "^2.8.5",
32
- "fastify": "^3.0.0",
33
- "fastify-formbody": "^5.3.0",
32
+ "fastify": "^4.0.0-rc.3",
33
+ "@fastify/formbody": "^7.0.1",
34
34
  "helmet": "^5.0.0",
35
- "passport": "^0.5.1",
35
+ "passport": "^0.6.0",
36
36
  "passport-http-bearer": "^1.0.1",
37
37
  "serve-static": "^1.14.1",
38
38
  "simple-get": "^4.0.0",
@@ -44,9 +44,6 @@
44
44
  "express": "^4.17.1",
45
45
  "fastify-plugin": "^3.0.0"
46
46
  },
47
- "engines": {
48
- "node": ">=10.0.0"
49
- },
50
47
  "tsd": {
51
48
  "directory": "test/types"
52
49
  },
package/test/404s.test.js CHANGED
@@ -44,9 +44,9 @@ test('run hooks and middleware on default 404', t => {
44
44
  reply.send({ hello: 'world' })
45
45
  })
46
46
 
47
- t.tearDown(fastify.close.bind(fastify))
47
+ t.teardown(fastify.close.bind(fastify))
48
48
 
49
- fastify.listen(0, err => {
49
+ fastify.listen({ port: 0 }, err => {
50
50
  t.error(err)
51
51
 
52
52
  sget({
@@ -56,7 +56,7 @@ test('run hooks and middleware on default 404', t => {
56
56
  headers: { 'Content-Type': 'application/json' }
57
57
  }, (err, response, body) => {
58
58
  t.error(err)
59
- t.strictEqual(response.statusCode, 404)
59
+ t.equal(response.statusCode, 404)
60
60
  })
61
61
  })
62
62
  })
@@ -101,7 +101,7 @@ test('run non-encapsulated plugin hooks and middleware on default 404', t => {
101
101
  reply.send({ hello: 'world' })
102
102
  })
103
103
 
104
- fastify.listen(0, (err, address) => {
104
+ fastify.listen({ port: 0 }, (err, address) => {
105
105
  t.error(err)
106
106
  sget({
107
107
  method: 'POST',
@@ -110,7 +110,7 @@ test('run non-encapsulated plugin hooks and middleware on default 404', t => {
110
110
  headers: { 'Content-Type': 'application/json' }
111
111
  }, (err, response, body) => {
112
112
  t.error(err)
113
- t.strictEqual(response.statusCode, 404)
113
+ t.equal(response.statusCode, 404)
114
114
  })
115
115
  })
116
116
  })
@@ -163,15 +163,15 @@ test('run non-encapsulated plugin hooks and middleware on custom 404', t => {
163
163
 
164
164
  fastify.register(plugin) // Registering plugin after handler also works
165
165
 
166
- fastify.listen(0, (err, address) => {
166
+ fastify.listen({ port: 0 }, (err, address) => {
167
167
  t.error(err)
168
168
  sget({
169
169
  method: 'GET',
170
170
  url: address + '/not-found'
171
171
  }, (err, response, body) => {
172
172
  t.error(err)
173
- t.strictEqual(body.toString(), 'this was not found')
174
- t.strictEqual(response.statusCode, 404)
173
+ t.equal(body.toString(), 'this was not found')
174
+ t.equal(response.statusCode, 404)
175
175
  })
176
176
  })
177
177
  })
@@ -243,9 +243,9 @@ test('run hooks and middleware with encapsulated 404', t => {
243
243
  next()
244
244
  }, { prefix: '/test' })
245
245
 
246
- t.tearDown(fastify.close.bind(fastify))
246
+ t.teardown(fastify.close.bind(fastify))
247
247
 
248
- fastify.listen(0, err => {
248
+ fastify.listen({ port: 0 }, err => {
249
249
  t.error(err)
250
250
 
251
251
  sget({
@@ -255,7 +255,7 @@ test('run hooks and middleware with encapsulated 404', t => {
255
255
  headers: { 'Content-Type': 'application/json' }
256
256
  }, (err, response, body) => {
257
257
  t.error(err)
258
- t.strictEqual(response.statusCode, 404)
258
+ t.equal(response.statusCode, 404)
259
259
  })
260
260
  })
261
261
  })
@@ -277,9 +277,9 @@ test('run middlewares on default 404', t => {
277
277
  reply.send({ hello: 'world' })
278
278
  })
279
279
 
280
- t.tearDown(fastify.close.bind(fastify))
280
+ t.teardown(fastify.close.bind(fastify))
281
281
 
282
- fastify.listen(0, err => {
282
+ fastify.listen({ port: 0 }, err => {
283
283
  t.error(err)
284
284
 
285
285
  sget({
@@ -289,7 +289,7 @@ test('run middlewares on default 404', t => {
289
289
  headers: { 'Content-Type': 'application/json' }
290
290
  }, (err, response, body) => {
291
291
  t.error(err)
292
- t.strictEqual(response.statusCode, 404)
292
+ t.equal(response.statusCode, 404)
293
293
  })
294
294
  })
295
295
  })
@@ -320,9 +320,9 @@ test('run middlewares with encapsulated 404', t => {
320
320
  next()
321
321
  }, { prefix: '/test' })
322
322
 
323
- t.tearDown(fastify.close.bind(fastify))
323
+ t.teardown(fastify.close.bind(fastify))
324
324
 
325
- fastify.listen(0, err => {
325
+ fastify.listen({ port: 0 }, err => {
326
326
  t.error(err)
327
327
 
328
328
  sget({
@@ -332,7 +332,7 @@ test('run middlewares with encapsulated 404', t => {
332
332
  headers: { 'Content-Type': 'application/json' }
333
333
  }, (err, response, body) => {
334
334
  t.error(err)
335
- t.strictEqual(response.statusCode, 404)
335
+ t.equal(response.statusCode, 404)
336
336
  })
337
337
  })
338
338
  })
@@ -26,16 +26,16 @@ test('Register express application', t => {
26
26
  fastify.register(expressPlugin)
27
27
  .after(() => { fastify.use(express) })
28
28
 
29
- fastify.listen(0, (err, address) => {
29
+ fastify.listen({ port: 0 }, (err, address) => {
30
30
  t.error(err)
31
31
  sget({
32
32
  method: 'GET',
33
33
  url: address + '/hello'
34
34
  }, (err, res, data) => {
35
35
  t.error(err)
36
- t.strictEqual(res.statusCode, 201)
36
+ t.equal(res.statusCode, 201)
37
37
  t.match(res.headers, { 'x-custom': 'true' })
38
- t.deepEqual(JSON.parse(data), { hello: 'world' })
38
+ t.same(JSON.parse(data), { hello: 'world' })
39
39
  })
40
40
  })
41
41
  })
@@ -65,25 +65,25 @@ test('Register express application that uses Router', t => {
65
65
  fastify.register(expressPlugin)
66
66
  .after(() => { fastify.use(router) })
67
67
 
68
- fastify.listen(0, (err, address) => {
68
+ fastify.listen({ port: 0 }, (err, address) => {
69
69
  t.error(err)
70
70
  sget({
71
71
  method: 'GET',
72
72
  url: address + '/hello'
73
73
  }, (err, res, data) => {
74
74
  t.error(err)
75
- t.strictEqual(res.statusCode, 201)
75
+ t.equal(res.statusCode, 201)
76
76
  t.match(res.headers, { 'x-custom': 'true' })
77
- t.deepEqual(JSON.parse(data), { hello: 'world' })
77
+ t.same(JSON.parse(data), { hello: 'world' })
78
78
  })
79
79
  sget({
80
80
  method: 'GET',
81
81
  url: address + '/foo'
82
82
  }, (err, res, data) => {
83
83
  t.error(err)
84
- t.strictEqual(res.statusCode, 400)
84
+ t.equal(res.statusCode, 400)
85
85
  t.match(res.headers, { 'x-custom': 'true' })
86
- t.deepEqual(JSON.parse(data), { foo: 'bar' })
86
+ t.same(JSON.parse(data), { foo: 'bar' })
87
87
  })
88
88
  })
89
89
  })
@@ -104,14 +104,14 @@ test('Should remove x-powered-by header', t => {
104
104
  .register(expressPlugin)
105
105
  .after(() => { fastify.use(router) })
106
106
 
107
- fastify.listen(0, (err, address) => {
107
+ fastify.listen({ port: 0 }, (err, address) => {
108
108
  t.error(err)
109
109
  sget({
110
110
  method: 'GET',
111
111
  url: address
112
112
  }, (err, res) => {
113
113
  t.error(err)
114
- t.strictEqual(res.headers['x-powered-by'], undefined)
114
+ t.equal(res.headers['x-powered-by'], undefined)
115
115
  })
116
116
  })
117
117
  })
@@ -132,14 +132,14 @@ test('Should expose the express app on the fastify instance', t => {
132
132
  .register(expressPlugin)
133
133
  .after(() => { fastify.use(router) })
134
134
 
135
- fastify.listen(0, (err, address) => {
135
+ fastify.listen({ port: 0 }, (err, address) => {
136
136
  t.error(err)
137
137
  sget({
138
138
  method: 'GET',
139
139
  url: address
140
140
  }, (err, res) => {
141
141
  t.error(err)
142
- t.strictEqual(fastify.express.disabled('x-powered-by'), true)
142
+ t.equal(fastify.express.disabled('x-powered-by'), true)
143
143
  })
144
144
  })
145
145
  })
@@ -166,14 +166,14 @@ test('Should flush headers if express handles request', t => {
166
166
  .register(expressPlugin)
167
167
  .after(() => { fastify.use(router) })
168
168
 
169
- fastify.listen(0, (err, address) => {
169
+ fastify.listen({ port: 0 }, (err, address) => {
170
170
  t.error(err)
171
171
  sget({
172
172
  method: 'GET',
173
173
  url: address
174
174
  }, (err, res) => {
175
175
  t.error(err)
176
- t.strictEqual(res.headers.foo, 'bar')
176
+ t.equal(res.headers.foo, 'bar')
177
177
  })
178
178
  })
179
179
  })
@@ -22,7 +22,7 @@ test('Should support connect style middlewares', t => {
22
22
  return { hello: 'world' }
23
23
  })
24
24
 
25
- fastify.listen(0, (err, address) => {
25
+ fastify.listen({ port: 0 }, (err, address) => {
26
26
  t.error(err)
27
27
  sget({
28
28
  method: 'GET',
@@ -32,7 +32,7 @@ test('Should support connect style middlewares', t => {
32
32
  t.match(res.headers, {
33
33
  'access-control-allow-origin': '*'
34
34
  })
35
- t.deepEqual(JSON.parse(data), { hello: 'world' })
35
+ t.same(JSON.parse(data), { hello: 'world' })
36
36
  })
37
37
  })
38
38
  })
@@ -49,7 +49,7 @@ test('Should support connect style middlewares (async await)', async t => {
49
49
  return { hello: 'world' }
50
50
  })
51
51
 
52
- const address = await fastify.listen(0)
52
+ const address = await fastify.listen({ port: 0 })
53
53
  return new Promise((resolve, reject) => {
54
54
  sget({
55
55
  method: 'GET',
@@ -59,7 +59,7 @@ test('Should support connect style middlewares (async await)', async t => {
59
59
  t.match(res.headers, {
60
60
  'access-control-allow-origin': '*'
61
61
  })
62
- t.deepEqual(JSON.parse(data), { hello: 'world' })
62
+ t.same(JSON.parse(data), { hello: 'world' })
63
63
  resolve()
64
64
  })
65
65
  })
@@ -78,7 +78,7 @@ test('Should support connect style middlewares (async await after)', async t =>
78
78
  return { hello: 'world' }
79
79
  })
80
80
 
81
- const address = await fastify.listen(0)
81
+ const address = await fastify.listen({ port: 0 })
82
82
  return new Promise((resolve, reject) => {
83
83
  sget({
84
84
  method: 'GET',
@@ -88,7 +88,7 @@ test('Should support connect style middlewares (async await after)', async t =>
88
88
  t.match(res.headers, {
89
89
  'access-control-allow-origin': '*'
90
90
  })
91
- t.deepEqual(JSON.parse(data), { hello: 'world' })
91
+ t.same(JSON.parse(data), { hello: 'world' })
92
92
  resolve()
93
93
  })
94
94
  })
@@ -111,7 +111,7 @@ test('Should support per path middlewares', t => {
111
111
  return { hello: 'world' }
112
112
  })
113
113
 
114
- fastify.listen(0, (err, address) => {
114
+ fastify.listen({ port: 0 }, (err, address) => {
115
115
  t.error(err)
116
116
  sget({
117
117
  method: 'GET',
@@ -139,7 +139,7 @@ test('Should support complex middlewares', t => {
139
139
  const fastify = Fastify()
140
140
 
141
141
  passport.use(new Strategy((token, cb) => {
142
- t.strictEqual(token, '123456789')
142
+ t.equal(token, '123456789')
143
143
  cb(null, { token })
144
144
  }))
145
145
 
@@ -148,10 +148,10 @@ test('Should support complex middlewares', t => {
148
148
  .after(() => { fastify.use(passport.authenticate('bearer', { session: false })) })
149
149
  fastify
150
150
  .get('/', (req, reply) => {
151
- t.deepEqual(req.raw.user, { token: '123456789' })
151
+ t.same(req.raw.user, { token: '123456789' })
152
152
  reply.send('ok')
153
153
  })
154
- .listen(0, (err, address) => {
154
+ .listen({ port: 0 }, (err, address) => {
155
155
  t.error(err)
156
156
  sget({
157
157
  method: 'GET',
@@ -186,7 +186,7 @@ test('Encapsulation support / 1', t => {
186
186
  reply.send('ok')
187
187
  })
188
188
 
189
- fastify.listen(0, (err, address) => {
189
+ fastify.listen({ port: 0 }, (err, address) => {
190
190
  t.error(err)
191
191
  sget({
192
192
  method: 'GET',
@@ -222,7 +222,7 @@ test('Encapsulation support / 2', t => {
222
222
  reply.send('ok')
223
223
  })
224
224
 
225
- fastify.listen(0, (err, address) => {
225
+ fastify.listen({ port: 0 }, (err, address) => {
226
226
  t.error(err)
227
227
  sget({
228
228
  method: 'GET',
@@ -260,7 +260,7 @@ test('Encapsulation support / 3', t => {
260
260
  reply.send('ok')
261
261
  })
262
262
 
263
- fastify.listen(0, (err, address) => {
263
+ fastify.listen({ port: 0 }, (err, address) => {
264
264
  t.error(err)
265
265
  sget({
266
266
  method: 'GET',
@@ -309,7 +309,7 @@ test('Encapsulation support / 4', t => {
309
309
  reply.send('ok')
310
310
  })
311
311
 
312
- fastify.listen(0, (err, address) => {
312
+ fastify.listen({ port: 0 }, (err, address) => {
313
313
  t.error(err)
314
314
  sget({
315
315
  method: 'GET',
@@ -378,7 +378,7 @@ test('Encapsulation support / 5', t => {
378
378
  reply.send('ok')
379
379
  })
380
380
 
381
- fastify.listen(0, (err, address) => {
381
+ fastify.listen({ port: 0 }, (err, address) => {
382
382
  t.error(err)
383
383
  sget({
384
384
  method: 'GET',
@@ -449,7 +449,7 @@ test('Middleware chain', t => {
449
449
  return { hello: 'world' }
450
450
  })
451
451
 
452
- fastify.listen(0, (err, address) => {
452
+ fastify.listen({ port: 0 }, (err, address) => {
453
453
  t.error(err)
454
454
  sget({
455
455
  method: 'GET',
@@ -461,17 +461,17 @@ test('Middleware chain', t => {
461
461
  })
462
462
 
463
463
  function middleware1 (req, res, next) {
464
- t.strictEqual(order.shift(), 1)
464
+ t.equal(order.shift(), 1)
465
465
  next()
466
466
  }
467
467
 
468
468
  function middleware2 (req, res, next) {
469
- t.strictEqual(order.shift(), 2)
469
+ t.equal(order.shift(), 2)
470
470
  next()
471
471
  }
472
472
 
473
473
  function middleware3 (req, res, next) {
474
- t.strictEqual(order.shift(), 3)
474
+ t.equal(order.shift(), 3)
475
475
  next()
476
476
  }
477
477
  })
@@ -495,32 +495,32 @@ test('Middleware chain (with errors) / 1', t => {
495
495
  return { hello: 'world' }
496
496
  })
497
497
 
498
- fastify.listen(0, (err, address) => {
498
+ fastify.listen({ port: 0 }, (err, address) => {
499
499
  t.error(err)
500
500
  sget({
501
501
  method: 'GET',
502
502
  url: address
503
503
  }, (err, res, data) => {
504
504
  t.error(err)
505
- t.strictEqual(res.statusCode, 500)
505
+ t.equal(res.statusCode, 500)
506
506
  fastify.close()
507
507
  })
508
508
  })
509
509
 
510
510
  function middleware1 (req, res, next) {
511
- t.strictEqual(order.shift(), 1)
511
+ t.equal(order.shift(), 1)
512
512
  next(new Error('middleware1'))
513
513
  }
514
514
 
515
515
  function middleware2 (err, req, res, next) {
516
- t.is(err.message, 'middleware1')
517
- t.strictEqual(order.shift(), 2)
516
+ t.equal(err.message, 'middleware1')
517
+ t.equal(order.shift(), 2)
518
518
  next(new Error('middleware2'))
519
519
  }
520
520
 
521
521
  function middleware3 (err, req, res, next) {
522
- t.is(err.message, 'middleware2')
523
- t.strictEqual(order.shift(), 3)
522
+ t.equal(err.message, 'middleware2')
523
+ t.equal(order.shift(), 3)
524
524
  next(new Error('kaboom'))
525
525
  }
526
526
  })
@@ -532,7 +532,7 @@ test('Middleware chain (with errors) / 2', t => {
532
532
  const fastify = Fastify()
533
533
 
534
534
  fastify.setErrorHandler((err, req, reply) => {
535
- t.is(err.message, 'middleware2')
535
+ t.equal(err.message, 'middleware2')
536
536
  reply.send(err)
537
537
  })
538
538
 
@@ -549,26 +549,26 @@ test('Middleware chain (with errors) / 2', t => {
549
549
  return { hello: 'world' }
550
550
  })
551
551
 
552
- fastify.listen(0, (err, address) => {
552
+ fastify.listen({ port: 0 }, (err, address) => {
553
553
  t.error(err)
554
554
  sget({
555
555
  method: 'GET',
556
556
  url: address
557
557
  }, (err, res, data) => {
558
558
  t.error(err)
559
- t.strictEqual(res.statusCode, 500)
559
+ t.equal(res.statusCode, 500)
560
560
  fastify.close()
561
561
  })
562
562
  })
563
563
 
564
564
  function middleware1 (req, res, next) {
565
- t.strictEqual(order.shift(), 1)
565
+ t.equal(order.shift(), 1)
566
566
  next(new Error('middleware1'))
567
567
  }
568
568
 
569
569
  function middleware2 (err, req, res, next) {
570
- t.is(err.message, 'middleware1')
571
- t.strictEqual(order.shift(), 2)
570
+ t.equal(err.message, 'middleware1')
571
+ t.equal(order.shift(), 2)
572
572
  next(new Error('middleware2'))
573
573
  }
574
574
 
@@ -615,7 +615,7 @@ test('Send a response from a middleware', t => {
615
615
  t.fail('We should not be here')
616
616
  })
617
617
 
618
- fastify.listen(0, (err, address) => {
618
+ fastify.listen({ port: 0 }, (err, address) => {
619
619
  t.error(err)
620
620
  sget({
621
621
  method: 'GET',
@@ -623,7 +623,7 @@ test('Send a response from a middleware', t => {
623
623
  json: true
624
624
  }, (err, res, data) => {
625
625
  t.error(err)
626
- t.deepEqual(data, { hello: 'world' })
626
+ t.same(data, { hello: 'world' })
627
627
  fastify.close()
628
628
  })
629
629
  })
@@ -657,15 +657,15 @@ test('Should support plugin level prefix', t => {
657
657
  next()
658
658
  }, { prefix: '/hello' })
659
659
 
660
- fastify.listen(0, (err, address) => {
660
+ fastify.listen({ port: 0 }, (err, address) => {
661
661
  t.error(err)
662
662
  sget({
663
663
  method: 'GET',
664
664
  url: address + '/hello/world'
665
665
  }, (err, res, data) => {
666
666
  t.error(err)
667
- t.strictEqual(res.headers['x-foo'], 'bar')
668
- t.deepEqual(JSON.parse(data), { hello: 'world' })
667
+ t.equal(res.headers['x-foo'], 'bar')
668
+ t.same(JSON.parse(data), { hello: 'world' })
669
669
  })
670
670
  })
671
671
  })
@@ -14,18 +14,18 @@ test('Should enhance the Node.js core request/response objects', t => {
14
14
  fastify.register(expressPlugin)
15
15
 
16
16
  fastify.get('/', async (req, reply) => {
17
- t.strictEqual(req.raw.originalUrl, req.raw.url)
18
- t.strictEqual(req.raw.id, req.id)
19
- t.strictEqual(req.raw.hostname, req.hostname)
20
- t.strictEqual(req.raw.protocol, req.protocol)
21
- t.strictEqual(req.raw.ip, req.ip)
22
- t.deepEqual(req.raw.ips, req.ips)
17
+ t.equal(req.raw.originalUrl, req.raw.url)
18
+ t.equal(req.raw.id, req.id)
19
+ t.equal(req.raw.hostname, req.hostname)
20
+ t.equal(req.raw.protocol, req.protocol)
21
+ t.equal(req.raw.ip, req.ip)
22
+ t.same(req.raw.ips, req.ips)
23
23
  t.ok(req.raw.log)
24
24
  t.ok(reply.raw.log)
25
25
  return { hello: 'world' }
26
26
  })
27
27
 
28
- fastify.listen(0, (err, address) => {
28
+ fastify.listen({ port: 0 }, (err, address) => {
29
29
  t.error(err)
30
30
  sget({
31
31
  method: 'GET',
@@ -40,19 +40,19 @@ test('trust proxy protocol', (t) => {
40
40
  t.plan(5)
41
41
  const fastify = Fastify({ trustProxy: true })
42
42
 
43
- t.tearDown(fastify.close.bind(fastify))
43
+ t.teardown(fastify.close.bind(fastify))
44
44
 
45
45
  fastify.register(expressPlugin).after(() => {
46
46
  fastify.use('/', function (req, res) {
47
- t.strictEqual(req.ip, '1.1.1.1', 'gets ip from x-forwarded-for')
48
- t.strictEqual(req.hostname, 'example.com', 'gets hostname from x-forwarded-host')
49
- t.strictEqual(req.protocol, 'lorem', 'gets protocol from x-forwarded-proto')
47
+ t.equal(req.ip, '1.1.1.1', 'gets ip from x-forwarded-for')
48
+ t.equal(req.hostname, 'example.com', 'gets hostname from x-forwarded-host')
49
+ t.equal(req.protocol, 'lorem', 'gets protocol from x-forwarded-proto')
50
50
 
51
51
  res.sendStatus(200)
52
52
  })
53
53
  })
54
54
 
55
- fastify.listen(0, (err, address) => {
55
+ fastify.listen({ port: 0 }, (err, address) => {
56
56
  t.error(err)
57
57
  sget({
58
58
  method: 'GET',
@@ -2,7 +2,7 @@
2
2
 
3
3
  const { test } = require('tap')
4
4
  const Fastify = require('fastify')
5
- const fastifyFormBody = require('fastify-formbody')
5
+ const fastifyFormBody = require('@fastify/formbody')
6
6
  const Express = require('express')
7
7
  const bodyParser = require('body-parser')
8
8
  const sget = require('simple-get').concat
@@ -22,7 +22,7 @@ test('POST request without form body works', t => {
22
22
  fastify.use(express)
23
23
  fastify.use((req, res, next) => {
24
24
  // body-parser default value
25
- t.deepEqual(req.body, {})
25
+ t.same(req.body, {})
26
26
  next()
27
27
  })
28
28
  })
@@ -31,7 +31,7 @@ test('POST request without form body works', t => {
31
31
  return { hello: 'world' }
32
32
  })
33
33
 
34
- fastify.listen(0, (err, address) => {
34
+ fastify.listen({ port: 0 }, (err, address) => {
35
35
  t.error(err)
36
36
  sget({
37
37
  method: 'post',
@@ -39,8 +39,8 @@ test('POST request without form body works', t => {
39
39
  timeout: 100
40
40
  }, (err, res, data) => {
41
41
  t.error(err)
42
- t.strictEqual(res.statusCode, 200)
43
- t.deepEqual(JSON.parse(data), { hello: 'world' })
42
+ t.equal(res.statusCode, 200)
43
+ t.same(JSON.parse(data), { hello: 'world' })
44
44
  })
45
45
  })
46
46
  })
@@ -57,7 +57,7 @@ test('POST request with form body and without body-parser works', t => {
57
57
  fastify.use(express)
58
58
  fastify.use((req, res, next) => {
59
59
  // req.body default value
60
- t.strictEqual(req.body, undefined)
60
+ t.equal(req.body, undefined)
61
61
  next()
62
62
  })
63
63
  })
@@ -66,7 +66,7 @@ test('POST request with form body and without body-parser works', t => {
66
66
  return { hello: 'world' }
67
67
  })
68
68
 
69
- fastify.listen(0, (err, address) => {
69
+ fastify.listen({ port: 0 }, (err, address) => {
70
70
  t.error(err)
71
71
  sget({
72
72
  method: 'post',
@@ -75,8 +75,8 @@ test('POST request with form body and without body-parser works', t => {
75
75
  timeout: 100
76
76
  }, (err, res, data) => {
77
77
  t.error(err)
78
- t.strictEqual(res.statusCode, 200)
79
- t.deepEqual(JSON.parse(data), { hello: 'world' })
78
+ t.equal(res.statusCode, 200)
79
+ t.same(JSON.parse(data), { hello: 'world' })
80
80
  })
81
81
  })
82
82
  })
@@ -94,7 +94,7 @@ test('POST request with form body and body-parser hangs up', t => {
94
94
  fastify.use(express)
95
95
  fastify.use((req, res, next) => {
96
96
  // body-parser result
97
- t.deepEqual(req.body, { input: 'test' })
97
+ t.same(req.body, { input: 'test' })
98
98
  next()
99
99
  })
100
100
  })
@@ -103,7 +103,7 @@ test('POST request with form body and body-parser hangs up', t => {
103
103
  return { hello: 'world' }
104
104
  })
105
105
 
106
- fastify.listen(0, (err, address) => {
106
+ fastify.listen({ port: 0 }, (err, address) => {
107
107
  t.error(err)
108
108
  sget({
109
109
  method: 'post',
@@ -111,7 +111,7 @@ test('POST request with form body and body-parser hangs up', t => {
111
111
  form: { input: 'test' },
112
112
  timeout: 100
113
113
  }, (err, res, data) => {
114
- t.strictEqual(err.message, 'Request timed out')
114
+ t.equal(err.message, 'Request timed out')
115
115
  })
116
116
  })
117
117
  })
@@ -128,7 +128,7 @@ test('POST request with form body and body-parser hangs up, compatibility case',
128
128
  fastify.use(express)
129
129
  fastify.use((req, res, next) => {
130
130
  // fastify-formbody with backward compatibility result
131
- t.deepEqual(req.body, { input: 'test' })
131
+ t.same(req.body, { input: 'test' })
132
132
  next()
133
133
  })
134
134
  })
@@ -137,7 +137,7 @@ test('POST request with form body and body-parser hangs up, compatibility case',
137
137
  return { hello: 'world' }
138
138
  })
139
139
 
140
- fastify.listen(0, (err, address) => {
140
+ fastify.listen({ port: 0 }, (err, address) => {
141
141
  t.error(err)
142
142
  sget({
143
143
  method: 'post',
@@ -146,8 +146,8 @@ test('POST request with form body and body-parser hangs up, compatibility case',
146
146
  timeout: 100
147
147
  }, (err, res, data) => {
148
148
  t.error(err)
149
- t.strictEqual(res.statusCode, 200)
150
- t.deepEqual(JSON.parse(data), { hello: 'world' })
149
+ t.equal(res.statusCode, 200)
150
+ t.same(JSON.parse(data), { hello: 'world' })
151
151
  })
152
152
  })
153
153
  })
@@ -18,8 +18,8 @@ test('onSend hook should receive valid request and reply objects if middleware f
18
18
  fastify.decorateReply('testDecorator', 'testDecoratorVal')
19
19
 
20
20
  fastify.addHook('onSend', function (request, reply, payload, next) {
21
- t.strictEqual(request.testDecorator, 'testDecoratorVal')
22
- t.strictEqual(reply.testDecorator, 'testDecoratorVal')
21
+ t.equal(request.testDecorator, 'testDecoratorVal')
22
+ t.equal(reply.testDecorator, 'testDecoratorVal')
23
23
  next()
24
24
  })
25
25
 
@@ -32,6 +32,6 @@ test('onSend hook should receive valid request and reply objects if middleware f
32
32
  url: '/'
33
33
  }, (err, res) => {
34
34
  t.error(err)
35
- t.strictEqual(res.statusCode, 500)
35
+ t.equal(res.statusCode, 500)
36
36
  })
37
37
  })
@@ -30,19 +30,19 @@ test('use a middleware', t => {
30
30
  reply.send({ hello: 'world' })
31
31
  })
32
32
 
33
- instance.listen(0, err => {
33
+ instance.listen({ port: 0 }, err => {
34
34
  t.error(err)
35
35
 
36
- t.tearDown(instance.server.close.bind(instance.server))
36
+ t.teardown(instance.server.close.bind(instance.server))
37
37
 
38
38
  sget({
39
39
  method: 'GET',
40
40
  url: 'http://localhost:' + instance.server.address().port
41
41
  }, (err, response, body) => {
42
42
  t.error(err)
43
- t.strictEqual(response.statusCode, 200)
44
- t.strictEqual(response.headers['content-length'], '' + body.length)
45
- t.deepEqual(JSON.parse(body), { hello: 'world' })
43
+ t.equal(response.statusCode, 200)
44
+ t.equal(response.headers['content-length'], '' + body.length)
45
+ t.same(JSON.parse(body), { hello: 'world' })
46
46
  })
47
47
  })
48
48
  })
@@ -60,10 +60,10 @@ test('use cors', t => {
60
60
  reply.send({ hello: 'world' })
61
61
  })
62
62
 
63
- instance.listen(0, err => {
63
+ instance.listen({ port: 0 }, err => {
64
64
  t.error(err)
65
65
 
66
- t.tearDown(instance.server.close.bind(instance.server))
66
+ t.teardown(instance.server.close.bind(instance.server))
67
67
 
68
68
  sget({
69
69
  method: 'GET',
@@ -88,10 +88,10 @@ test('use helmet', t => {
88
88
  reply.send({ hello: 'world' })
89
89
  })
90
90
 
91
- instance.listen(0, err => {
91
+ instance.listen({ port: 0 }, err => {
92
92
  t.error(err)
93
93
 
94
- t.tearDown(instance.server.close.bind(instance.server))
94
+ t.teardown(instance.server.close.bind(instance.server))
95
95
 
96
96
  sget({
97
97
  method: 'GET',
@@ -117,10 +117,10 @@ test('use helmet and cors', t => {
117
117
  reply.send({ hello: 'world' })
118
118
  })
119
119
 
120
- instance.listen(0, err => {
120
+ instance.listen({ port: 0 }, err => {
121
121
  t.error(err)
122
122
 
123
- t.tearDown(instance.server.close.bind(instance.server))
123
+ t.teardown(instance.server.close.bind(instance.server))
124
124
 
125
125
  sget({
126
126
  method: 'GET',
@@ -176,9 +176,9 @@ test('middlewares with prefix', t => {
176
176
  instance.get('/prefix/', handler)
177
177
  instance.get('/prefix/inner', handler)
178
178
 
179
- instance.listen(0, err => {
179
+ instance.listen({ port: 0 }, err => {
180
180
  t.error(err)
181
- t.tearDown(instance.server.close.bind(instance.server))
181
+ t.teardown(instance.server.close.bind(instance.server))
182
182
 
183
183
  t.test('/', t => {
184
184
  t.plan(2)
@@ -188,7 +188,7 @@ test('middlewares with prefix', t => {
188
188
  json: true
189
189
  }, (err, response, body) => {
190
190
  t.error(err)
191
- t.deepEqual(body, {
191
+ t.same(body, {
192
192
  global: true,
193
193
  global2: true,
194
194
  root: true
@@ -204,7 +204,7 @@ test('middlewares with prefix', t => {
204
204
  json: true
205
205
  }, (err, response, body) => {
206
206
  t.error(err)
207
- t.deepEqual(body, {
207
+ t.same(body, {
208
208
  prefixed: true,
209
209
  global: true,
210
210
  global2: true,
@@ -222,7 +222,7 @@ test('middlewares with prefix', t => {
222
222
  json: true
223
223
  }, (err, response, body) => {
224
224
  t.error(err)
225
- t.deepEqual(body, {
225
+ t.same(body, {
226
226
  prefixed: true,
227
227
  slashed: true,
228
228
  global: true,
@@ -240,7 +240,7 @@ test('middlewares with prefix', t => {
240
240
  json: true
241
241
  }, (err, response, body) => {
242
242
  t.error(err)
243
- t.deepEqual(body, {
243
+ t.same(body, {
244
244
  prefixed: true,
245
245
  slashed: true,
246
246
  global: true,
@@ -290,15 +290,15 @@ test('res.end should block middleware execution', t => {
290
290
  t.fail('we should no be here')
291
291
  })
292
292
 
293
- instance.listen(0, (err, address) => {
293
+ instance.listen({ port: 0 }, (err, address) => {
294
294
  t.error(err)
295
295
  sget({
296
296
  method: 'GET',
297
297
  url: address
298
298
  }, (err, res, data) => {
299
299
  t.error(err)
300
- t.is(res.statusCode, 200)
301
- t.is(data.toString(), 'hello')
300
+ t.equal(res.statusCode, 200)
301
+ t.equal(data.toString(), 'hello')
302
302
  })
303
303
  })
304
304
  })
@@ -331,15 +331,15 @@ test('Use a middleware inside a plugin after an encapsulated plugin', t => {
331
331
  next()
332
332
  }))
333
333
 
334
- f.listen(0, (err, address) => {
334
+ f.listen({ port: 0 }, (err, address) => {
335
335
  t.error(err)
336
336
  sget({
337
337
  method: 'GET',
338
338
  url: address
339
339
  }, (err, res, data) => {
340
340
  t.error(err)
341
- t.is(res.statusCode, 200)
342
- t.deepEqual(JSON.parse(data), { hello: 'world' })
341
+ t.equal(res.statusCode, 200)
342
+ t.same(JSON.parse(data), { hello: 'world' })
343
343
  })
344
344
  })
345
345
  })
@@ -352,14 +352,14 @@ test('middlewares should run in the order in which they are defined', t => {
352
352
 
353
353
  f.register(fp(function (instance, opts, next) {
354
354
  instance.use(function (req, res, next) {
355
- t.strictEqual(req.previous, undefined)
355
+ t.equal(req.previous, undefined)
356
356
  req.previous = 1
357
357
  next()
358
358
  })
359
359
 
360
360
  instance.register(fp(function (i, opts, next) {
361
361
  i.use(function (req, res, next) {
362
- t.strictEqual(req.previous, 2)
362
+ t.equal(req.previous, 2)
363
363
  req.previous = 3
364
364
  next()
365
365
  })
@@ -367,7 +367,7 @@ test('middlewares should run in the order in which they are defined', t => {
367
367
  }))
368
368
 
369
369
  instance.use(function (req, res, next) {
370
- t.strictEqual(req.previous, 1)
370
+ t.equal(req.previous, 1)
371
371
  req.previous = 2
372
372
  next()
373
373
  })
@@ -377,19 +377,19 @@ test('middlewares should run in the order in which they are defined', t => {
377
377
 
378
378
  f.register(function (instance, opts, next) {
379
379
  instance.use(function (req, res, next) {
380
- t.strictEqual(req.previous, 3)
380
+ t.equal(req.previous, 3)
381
381
  req.previous = 4
382
382
  next()
383
383
  })
384
384
 
385
385
  instance.get('/', function (request, reply) {
386
- t.strictEqual(request.raw.previous, 5)
386
+ t.equal(request.raw.previous, 5)
387
387
  reply.send({ hello: 'world' })
388
388
  })
389
389
 
390
390
  instance.register(fp(function (i, opts, next) {
391
391
  i.use(function (req, res, next) {
392
- t.strictEqual(req.previous, 4)
392
+ t.equal(req.previous, 4)
393
393
  req.previous = 5
394
394
  next()
395
395
  })
@@ -399,15 +399,15 @@ test('middlewares should run in the order in which they are defined', t => {
399
399
  next()
400
400
  })
401
401
 
402
- f.listen(0, (err, address) => {
402
+ f.listen({ port: 0 }, (err, address) => {
403
403
  t.error(err)
404
404
  sget({
405
405
  method: 'GET',
406
406
  url: address
407
407
  }, (err, res, data) => {
408
408
  t.error(err)
409
- t.is(res.statusCode, 200)
410
- t.deepEqual(JSON.parse(data), { hello: 'world' })
409
+ t.equal(res.statusCode, 200)
410
+ t.same(JSON.parse(data), { hello: 'world' })
411
411
  })
412
412
  })
413
413
  })