fastify 4.0.0-alpha.1 → 4.0.0-alpha.2

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.
Files changed (101) hide show
  1. package/.taprc +3 -0
  2. package/README.md +2 -3
  3. package/docs/Guides/Database.md +320 -0
  4. package/docs/Guides/Getting-Started.md +7 -7
  5. package/docs/Guides/Plugins-Guide.md +1 -1
  6. package/docs/Guides/Serverless.md +3 -3
  7. package/docs/Guides/Testing.md +2 -2
  8. package/docs/Reference/Decorators.md +2 -2
  9. package/docs/Reference/Encapsulation.md +2 -2
  10. package/docs/Reference/HTTP2.md +3 -3
  11. package/docs/Reference/Plugins.md +3 -3
  12. package/docs/Reference/Routes.md +5 -5
  13. package/docs/Reference/Server.md +27 -62
  14. package/docs/Reference/TypeScript.md +9 -9
  15. package/docs/Reference/Validation-and-Serialization.md +4 -4
  16. package/docs/Type-Providers.md +2 -2
  17. package/examples/asyncawait.js +1 -1
  18. package/examples/benchmark/hooks-benchmark-async-await.js +1 -1
  19. package/examples/benchmark/hooks-benchmark.js +1 -1
  20. package/examples/benchmark/simple.js +1 -1
  21. package/examples/hooks.js +1 -1
  22. package/examples/http2.js +1 -1
  23. package/examples/https.js +1 -1
  24. package/examples/parser.js +1 -1
  25. package/examples/route-prefix.js +1 -1
  26. package/examples/shared-schema.js +1 -1
  27. package/examples/simple-stream.js +1 -1
  28. package/examples/simple.js +1 -1
  29. package/examples/simple.mjs +1 -1
  30. package/examples/typescript-server.ts +1 -1
  31. package/examples/use-plugin.js +1 -1
  32. package/fastify.js +4 -2
  33. package/lib/reply.js +1 -1
  34. package/lib/server.js +32 -10
  35. package/lib/warnings.js +2 -0
  36. package/package.json +13 -11
  37. package/test/404s.test.js +16 -16
  38. package/test/500s.test.js +1 -1
  39. package/test/als.test.js +1 -1
  40. package/test/async-await.test.js +7 -7
  41. package/test/bodyLimit.test.js +1 -1
  42. package/test/build-certificate.js +6 -7
  43. package/test/case-insensitive.test.js +4 -4
  44. package/test/close-pipelining.test.js +2 -2
  45. package/test/close.test.js +11 -11
  46. package/test/custom-http-server.test.js +1 -1
  47. package/test/custom-parser-async.test.js +1 -1
  48. package/test/custom-parser.test.js +38 -38
  49. package/test/custom-querystring-parser.test.js +3 -3
  50. package/test/decorator.test.js +10 -10
  51. package/test/delete.test.js +1 -1
  52. package/test/genReqId.test.js +1 -1
  53. package/test/get.test.js +1 -1
  54. package/test/handler-context.test.js +2 -2
  55. package/test/head.test.js +1 -1
  56. package/test/helper.js +1 -1
  57. package/test/hooks-async.test.js +1 -1
  58. package/test/hooks.on-ready.test.js +1 -1
  59. package/test/hooks.test.js +20 -20
  60. package/test/http2/closing.test.js +5 -5
  61. package/test/http2/constraint.test.js +1 -1
  62. package/test/http2/head.test.js +1 -1
  63. package/test/http2/plain.test.js +1 -1
  64. package/test/http2/secure-with-fallback.test.js +1 -1
  65. package/test/http2/secure.test.js +1 -1
  66. package/test/http2/unknown-http-method.test.js +1 -1
  67. package/test/https/custom-https-server.test.js +1 -1
  68. package/test/https/https.test.js +1 -1
  69. package/test/input-validation.js +1 -1
  70. package/test/internals/handleRequest.test.js +3 -3
  71. package/test/internals/initialConfig.test.js +9 -1
  72. package/test/internals/logger.test.js +2 -2
  73. package/test/internals/reply.test.js +41 -42
  74. package/test/internals/server.test.js +5 -5
  75. package/test/listen.deprecated.test.js +202 -0
  76. package/test/listen.test.js +41 -156
  77. package/test/logger.test.js +15 -15
  78. package/test/maxRequestsPerSocket.test.js +2 -2
  79. package/test/nullable-validation.test.js +3 -3
  80. package/test/output-validation.test.js +1 -1
  81. package/test/plugin.test.js +16 -16
  82. package/test/promises.test.js +1 -1
  83. package/test/proto-poisoning.test.js +6 -6
  84. package/test/register.test.js +3 -3
  85. package/test/reply-error.test.js +3 -3
  86. package/test/request-error.test.js +1 -1
  87. package/test/route-hooks.test.js +1 -1
  88. package/test/route.test.js +3 -3
  89. package/test/router-options.test.js +1 -1
  90. package/test/schema-feature.test.js +1 -1
  91. package/test/schema-special-usage.test.js +0 -81
  92. package/test/skip-reply-send.test.js +1 -1
  93. package/test/stream.test.js +60 -12
  94. package/test/trust-proxy.test.js +6 -6
  95. package/test/types/instance.test-d.ts +33 -3
  96. package/test/types/reply.test-d.ts +2 -1
  97. package/test/url-rewriting.test.js +3 -3
  98. package/test/versioned-routes.test.js +3 -3
  99. package/types/.eslintrc.json +3 -1
  100. package/types/instance.d.ts +120 -14
  101. package/types/reply.d.ts +2 -1
@@ -13,7 +13,7 @@ const handler = (req, res) => {
13
13
 
14
14
  test('start listening', async t => {
15
15
  const { server, listen } = createServer({}, handler)
16
- await listen.call(Fastify(), 0, 'localhost')
16
+ await listen.call(Fastify(), { port: 0, host: 'localhost' })
17
17
  server.close()
18
18
  t.pass('server started')
19
19
  })
@@ -27,7 +27,7 @@ test('DNS errors does not stop the main server on localhost - promise interface'
27
27
  }
28
28
  })
29
29
  const { server, listen } = createServer({}, handler)
30
- await listen.call(Fastify(), 0, 'localhost')
30
+ await listen.call(Fastify(), { port: 0, host: 'localhost' })
31
31
  server.close()
32
32
  t.pass('server started')
33
33
  })
@@ -42,7 +42,7 @@ test('DNS errors does not stop the main server on localhost - callback interface
42
42
  }
43
43
  })
44
44
  const { server, listen } = createServer({}, handler)
45
- listen.call(Fastify(), 0, 'localhost', (err) => {
45
+ listen.call(Fastify(), { port: 0, host: 'localhost' }, (err) => {
46
46
  t.error(err)
47
47
  server.close()
48
48
  t.pass('server started')
@@ -59,7 +59,7 @@ test('DNS returns empty binding', t => {
59
59
  }
60
60
  })
61
61
  const { server, listen } = createServer({}, handler)
62
- listen.call(Fastify(), 0, 'localhost', (err) => {
62
+ listen.call(Fastify(), { port: 0, host: 'localhost' }, (err) => {
63
63
  t.error(err)
64
64
  server.close()
65
65
  t.pass('server started')
@@ -80,7 +80,7 @@ test('DNS returns more than two binding', t => {
80
80
  }
81
81
  })
82
82
  const { server, listen } = createServer({}, handler)
83
- listen.call(Fastify(), 0, 'localhost', (err) => {
83
+ listen.call(Fastify(), { port: 0, host: 'localhost' }, (err) => {
84
84
  t.error(err)
85
85
  server.close()
86
86
  t.pass('server started')
@@ -0,0 +1,202 @@
1
+ 'use strict'
2
+
3
+ // Tests for deprecated `.listen` signature. This file should be
4
+ // removed when the deprecation is complete.
5
+
6
+ const { test, before } = require('tap')
7
+ const dns = require('dns').promises
8
+ const Fastify = require('..')
9
+
10
+ let localhost
11
+ let localhostForURL
12
+
13
+ process.removeAllListeners('warning')
14
+
15
+ before(async function (t) {
16
+ const lookup = await dns.lookup('localhost')
17
+ localhost = lookup.address
18
+ if (lookup.family === 6) {
19
+ localhostForURL = `[${lookup.address}]`
20
+ } else {
21
+ localhostForURL = localhost
22
+ }
23
+ })
24
+
25
+ test('listen accepts a port and a callback', t => {
26
+ t.plan(2)
27
+ const fastify = Fastify()
28
+ t.teardown(fastify.close.bind(fastify))
29
+ fastify.listen(0, (err) => {
30
+ t.equal(fastify.server.address().address, localhost)
31
+ t.error(err)
32
+ })
33
+ })
34
+
35
+ test('listen accepts a port and a callback with (err, address)', t => {
36
+ t.plan(2)
37
+ const fastify = Fastify()
38
+ t.teardown(fastify.close.bind(fastify))
39
+ fastify.listen(0, (err, address) => {
40
+ t.equal(address, `http://${localhostForURL}:${fastify.server.address().port}`)
41
+ t.error(err)
42
+ })
43
+ })
44
+
45
+ test('listen accepts a port, address, and callback', t => {
46
+ t.plan(1)
47
+ const fastify = Fastify()
48
+ t.teardown(fastify.close.bind(fastify))
49
+ fastify.listen(0, localhost, (err) => {
50
+ t.error(err)
51
+ })
52
+ })
53
+
54
+ test('listen accepts options, backlog and a callback', t => {
55
+ t.plan(1)
56
+ const fastify = Fastify()
57
+ t.teardown(fastify.close.bind(fastify))
58
+ fastify.listen({
59
+ port: 0,
60
+ host: 'localhost'
61
+ }, 511, (err) => {
62
+ t.error(err)
63
+ })
64
+ })
65
+
66
+ test('listen accepts options (no port), backlog and a callback', t => {
67
+ t.plan(1)
68
+ const fastify = Fastify()
69
+ t.teardown(fastify.close.bind(fastify))
70
+ fastify.listen({
71
+ host: 'localhost'
72
+ }, 511, (err) => {
73
+ t.error(err)
74
+ })
75
+ })
76
+
77
+ test('listen accepts options (no host), backlog and a callback', t => {
78
+ t.plan(1)
79
+ const fastify = Fastify()
80
+ t.teardown(fastify.close.bind(fastify))
81
+ fastify.listen({
82
+ port: 0
83
+ }, 511, (err) => {
84
+ t.error(err)
85
+ })
86
+ })
87
+
88
+ test('listen accepts options (no port, no host), backlog and a callback', t => {
89
+ t.plan(1)
90
+ const fastify = Fastify()
91
+ t.teardown(fastify.close.bind(fastify))
92
+ fastify.listen({
93
+ ipv6Only: false
94
+ }, 511, (err) => {
95
+ t.error(err)
96
+ })
97
+ })
98
+
99
+ test('listen accepts a port, address and a callback with (err, address)', t => {
100
+ t.plan(2)
101
+ const fastify = Fastify()
102
+ t.teardown(fastify.close.bind(fastify))
103
+ fastify.listen(0, localhost, (err, address) => {
104
+ t.equal(address, `http://${localhostForURL}:${fastify.server.address().port}`)
105
+ t.error(err)
106
+ })
107
+ })
108
+
109
+ test('listen accepts a port, address, backlog and callback', t => {
110
+ t.plan(1)
111
+ const fastify = Fastify()
112
+ t.teardown(fastify.close.bind(fastify))
113
+ fastify.listen(0, localhost, 511, (err) => {
114
+ t.error(err)
115
+ })
116
+ })
117
+
118
+ test('listen accepts a port, address, backlog and callback with (err, address)', t => {
119
+ t.plan(2)
120
+ const fastify = Fastify()
121
+ t.teardown(fastify.close.bind(fastify))
122
+ fastify.listen(0, localhost, 511, (err, address) => {
123
+ t.equal(address, `http://${localhostForURL}:${fastify.server.address().port}`)
124
+ t.error(err)
125
+ })
126
+ })
127
+
128
+ test('listen without callback (port zero)', t => {
129
+ t.plan(1)
130
+ const fastify = Fastify()
131
+ t.teardown(fastify.close.bind(fastify))
132
+ fastify.listen(0)
133
+ .then(() => {
134
+ t.equal(fastify.server.address().address, localhost)
135
+ })
136
+ })
137
+
138
+ test('listen without callback (port not given)', t => {
139
+ t.plan(1)
140
+ const fastify = Fastify()
141
+ t.teardown(fastify.close.bind(fastify))
142
+ fastify.listen()
143
+ .then(() => {
144
+ t.equal(fastify.server.address().address, localhost)
145
+ })
146
+ })
147
+
148
+ test('listen null without callback with (address)', t => {
149
+ t.plan(1)
150
+ const fastify = Fastify()
151
+ t.teardown(fastify.close.bind(fastify))
152
+ fastify.listen(null)
153
+ .then(address => {
154
+ t.equal(address, `http://${localhostForURL}:${fastify.server.address().port}`)
155
+ })
156
+ })
157
+
158
+ test('listen without port without callback with (address)', t => {
159
+ t.plan(1)
160
+ const fastify = Fastify()
161
+ t.teardown(fastify.close.bind(fastify))
162
+ fastify.listen()
163
+ .then(address => {
164
+ t.equal(address, `http://${localhostForURL}:${fastify.server.address().port}`)
165
+ })
166
+ })
167
+
168
+ test('listen with undefined without callback with (address)', t => {
169
+ t.plan(1)
170
+ const fastify = Fastify()
171
+ t.teardown(fastify.close.bind(fastify))
172
+ fastify.listen(undefined)
173
+ .then(address => {
174
+ t.equal(address, `http://${localhostForURL}:${fastify.server.address().port}`)
175
+ })
176
+ })
177
+
178
+ test('listen when firstArg is string(pipe) and without backlog', async t => {
179
+ t.plan(1)
180
+ const fastify = Fastify()
181
+ t.teardown(fastify.close.bind(fastify))
182
+ const address = await fastify.listen('\\\\.\\pipe\\testPipe')
183
+ t.equal(address, '\\\\.\\pipe\\testPipe')
184
+ })
185
+
186
+ test('listen when firstArg is string(pipe) and with backlog', async t => {
187
+ t.plan(1)
188
+ const fastify = Fastify()
189
+ t.teardown(fastify.close.bind(fastify))
190
+ const address = await fastify.listen('\\\\.\\pipe\\testPipe2', 511)
191
+ t.equal(address, '\\\\.\\pipe\\testPipe2')
192
+ })
193
+
194
+ test('listen when firstArg is { path: string(pipe) } and with backlog and callback', t => {
195
+ t.plan(2)
196
+ const fastify = Fastify()
197
+ t.teardown(fastify.close.bind(fastify))
198
+ fastify.listen({ path: '\\\\.\\pipe\\testPipe3' }, 511, (err, address) => {
199
+ t.error(err)
200
+ t.equal(address, '\\\\.\\pipe\\testPipe3')
201
+ })
202
+ })
@@ -22,46 +22,38 @@ before(async function () {
22
22
  }
23
23
  })
24
24
 
25
- test('listen accepts a callback', t => {
26
- t.plan(2)
27
- const fastify = Fastify()
28
- t.teardown(fastify.close.bind(fastify))
29
- fastify.listen((err) => {
30
- t.equal(fastify.server.address().address, localhost)
31
- t.error(err)
25
+ test('listen works without arguments', async t => {
26
+ process.on('warning', () => {
27
+ t.fail('should not be deprecated')
32
28
  })
33
- })
34
29
 
35
- test('listen accepts a port and a callback', t => {
36
- t.plan(2)
37
30
  const fastify = Fastify()
38
31
  t.teardown(fastify.close.bind(fastify))
39
- fastify.listen(0, (err) => {
40
- t.equal(fastify.server.address().address, localhost)
41
- t.error(err)
42
- })
32
+ await fastify.listen()
33
+ const address = fastify.server.address()
34
+ t.equal(address.address, localhost)
35
+ t.ok(address.port > 0)
43
36
  })
44
37
 
45
- test('listen accepts a port and a callback with (err, address)', t => {
46
- t.plan(2)
47
- const fastify = Fastify()
48
- t.teardown(fastify.close.bind(fastify))
49
- fastify.listen(0, (err, address) => {
50
- t.equal(address, `http://${localhostForURL}:${fastify.server.address().port}`)
51
- t.error(err)
38
+ test('listen accepts a callback', t => {
39
+ process.on('warning', () => {
40
+ t.fail('should not be deprecated')
52
41
  })
53
- })
54
42
 
55
- test('listen accepts a port, address, and callback', t => {
56
- t.plan(1)
43
+ t.plan(2)
57
44
  const fastify = Fastify()
58
45
  t.teardown(fastify.close.bind(fastify))
59
- fastify.listen(0, localhost, (err) => {
46
+ fastify.listen({ port: 0 }, (err) => {
47
+ t.equal(fastify.server.address().address, localhost)
60
48
  t.error(err)
61
49
  })
62
50
  })
63
51
 
64
52
  test('listen accepts options and a callback', t => {
53
+ process.on('warning', () => {
54
+ t.fail('should not be deprecated')
55
+ })
56
+
65
57
  t.plan(1)
66
58
  const fastify = Fastify()
67
59
  t.teardown(fastify.close.bind(fastify))
@@ -78,54 +70,13 @@ test('listen accepts options and a callback', t => {
78
70
  })
79
71
  })
80
72
 
81
- test('listen accepts options, backlog and a callback', t => {
82
- t.plan(1)
83
- const fastify = Fastify()
84
- t.teardown(fastify.close.bind(fastify))
85
- fastify.listen({
86
- port: 0,
87
- host: 'localhost'
88
- }, 511, (err) => {
89
- t.error(err)
90
- })
91
- })
92
-
93
- test('listen accepts a port, address and a callback with (err, address)', t => {
94
- t.plan(2)
95
- const fastify = Fastify()
96
- t.teardown(fastify.close.bind(fastify))
97
- fastify.listen(0, localhost, (err, address) => {
98
- t.equal(address, `http://${localhostForURL}:${fastify.server.address().port}`)
99
- t.error(err)
100
- })
101
- })
102
-
103
- test('listen accepts a port, address, backlog and callback', t => {
104
- t.plan(1)
105
- const fastify = Fastify()
106
- t.teardown(fastify.close.bind(fastify))
107
- fastify.listen(0, localhost, 511, (err) => {
108
- t.error(err)
109
- })
110
- })
111
-
112
- test('listen accepts a port, address, backlog and callback with (err, address)', t => {
113
- t.plan(2)
114
- const fastify = Fastify()
115
- t.teardown(fastify.close.bind(fastify))
116
- fastify.listen(0, localhost, 511, (err, address) => {
117
- t.equal(address, `http://${localhostForURL}:${fastify.server.address().port}`)
118
- t.error(err)
119
- })
120
- })
121
-
122
73
  test('listen after Promise.resolve()', t => {
123
74
  t.plan(2)
124
75
  const f = Fastify()
125
76
  t.teardown(f.close.bind(f))
126
77
  Promise.resolve()
127
78
  .then(() => {
128
- f.listen(0, (err, address) => {
79
+ f.listen({ port: 0 }, (err, address) => {
129
80
  f.server.unref()
130
81
  t.equal(address, `http://${localhostForURL}:${f.server.address().port}`)
131
82
  t.error(err)
@@ -155,9 +106,9 @@ test('double listen errors', t => {
155
106
  t.plan(3)
156
107
  const fastify = Fastify()
157
108
  t.teardown(fastify.close.bind(fastify))
158
- fastify.listen(0, (err) => {
109
+ fastify.listen({ port: 0 }, (err) => {
159
110
  t.error(err)
160
- fastify.listen(fastify.server.address().port, (err, address) => {
111
+ fastify.listen({ port: fastify.server.address().port }, (err, address) => {
161
112
  t.equal(address, null)
162
113
  t.ok(err)
163
114
  })
@@ -168,10 +119,10 @@ test('double listen errors callback with (err, address)', t => {
168
119
  t.plan(4)
169
120
  const fastify = Fastify()
170
121
  t.teardown(fastify.close.bind(fastify))
171
- fastify.listen(0, (err1, address1) => {
122
+ fastify.listen({ port: 0 }, (err1, address1) => {
172
123
  t.equal(address1, `http://${localhostForURL}:${fastify.server.address().port}`)
173
124
  t.error(err1)
174
- fastify.listen(fastify.server.address().port, (err2, address2) => {
125
+ fastify.listen({ port: fastify.server.address().port }, (err2, address2) => {
175
126
  t.equal(address2, null)
176
127
  t.ok(err2)
177
128
  })
@@ -182,12 +133,12 @@ test('listen twice on the same port', t => {
182
133
  t.plan(4)
183
134
  const fastify = Fastify()
184
135
  t.teardown(fastify.close.bind(fastify))
185
- fastify.listen(0, (err1, address1) => {
136
+ fastify.listen({ port: 0 }, (err1, address1) => {
186
137
  t.equal(address1, `http://${localhostForURL}:${fastify.server.address().port}`)
187
138
  t.error(err1)
188
139
  const s2 = Fastify()
189
140
  t.teardown(s2.close.bind(s2))
190
- s2.listen(fastify.server.address().port, (err2, address2) => {
141
+ s2.listen({ port: fastify.server.address().port }, (err2, address2) => {
191
142
  t.equal(address2, null)
192
143
  t.ok(err2)
193
144
  })
@@ -198,13 +149,13 @@ test('listen twice on the same port callback with (err, address)', t => {
198
149
  t.plan(4)
199
150
  const fastify = Fastify()
200
151
  t.teardown(fastify.close.bind(fastify))
201
- fastify.listen(0, (err1, address1) => {
152
+ fastify.listen({ port: 0 }, (err1, address1) => {
202
153
  const _port = fastify.server.address().port
203
154
  t.equal(address1, `http://${localhostForURL}:${_port}`)
204
155
  t.error(err1)
205
156
  const s2 = Fastify()
206
157
  t.teardown(s2.close.bind(s2))
207
- s2.listen(_port, (err2, address2) => {
158
+ s2.listen({ port: _port }, (err2, address2) => {
208
159
  t.equal(address2, null)
209
160
  t.ok(err2)
210
161
  })
@@ -223,7 +174,7 @@ if (os.platform() !== 'win32') {
223
174
  fs.unlinkSync(sockFile)
224
175
  } catch (e) { }
225
176
 
226
- fastify.listen(sockFile, (err, address) => {
177
+ fastify.listen({ path: sockFile }, (err, address) => {
227
178
  t.error(err)
228
179
  t.equal(sockFile, fastify.server.address())
229
180
  t.equal(address, sockFile)
@@ -231,61 +182,11 @@ if (os.platform() !== 'win32') {
231
182
  })
232
183
  }
233
184
 
234
- test('listen without callback (port zero)', t => {
235
- t.plan(1)
236
- const fastify = Fastify()
237
- t.teardown(fastify.close.bind(fastify))
238
- fastify.listen(0)
239
- .then(() => {
240
- t.equal(fastify.server.address().address, localhost)
241
- })
242
- })
243
-
244
- test('listen without callback (port not given)', t => {
245
- t.plan(1)
246
- const fastify = Fastify()
247
- t.teardown(fastify.close.bind(fastify))
248
- fastify.listen()
249
- .then(() => {
250
- t.equal(fastify.server.address().address, localhost)
251
- })
252
- })
253
-
254
- test('listen null without callback with (address)', t => {
255
- t.plan(1)
256
- const fastify = Fastify()
257
- t.teardown(fastify.close.bind(fastify))
258
- fastify.listen(null)
259
- .then(address => {
260
- t.equal(address, `http://${localhostForURL}:${fastify.server.address().port}`)
261
- })
262
- })
263
-
264
- test('listen without port without callback with (address)', t => {
265
- t.plan(1)
266
- const fastify = Fastify()
267
- t.teardown(fastify.close.bind(fastify))
268
- fastify.listen()
269
- .then(address => {
270
- t.equal(address, `http://${localhostForURL}:${fastify.server.address().port}`)
271
- })
272
- })
273
-
274
- test('listen with undefined without callback with (address)', t => {
275
- t.plan(1)
276
- const fastify = Fastify()
277
- t.teardown(fastify.close.bind(fastify))
278
- fastify.listen(undefined)
279
- .then(address => {
280
- t.equal(address, `http://${localhostForURL}:${fastify.server.address().port}`)
281
- })
282
- })
283
-
284
185
  test('listen without callback with (address)', t => {
285
186
  t.plan(1)
286
187
  const fastify = Fastify()
287
188
  t.teardown(fastify.close.bind(fastify))
288
- fastify.listen(0)
189
+ fastify.listen({ port: 0 })
289
190
  .then(address => {
290
191
  t.equal(address, `http://${localhostForURL}:${fastify.server.address().port}`)
291
192
  })
@@ -295,9 +196,9 @@ test('double listen without callback rejects', t => {
295
196
  t.plan(1)
296
197
  const fastify = Fastify()
297
198
  t.teardown(fastify.close.bind(fastify))
298
- fastify.listen(0)
199
+ fastify.listen({ port: 0 })
299
200
  .then(() => {
300
- fastify.listen(0)
201
+ fastify.listen({ port: 0 })
301
202
  .catch(err => {
302
203
  t.ok(err)
303
204
  })
@@ -309,10 +210,10 @@ test('double listen without callback with (address)', t => {
309
210
  t.plan(2)
310
211
  const fastify = Fastify()
311
212
  t.teardown(fastify.close.bind(fastify))
312
- fastify.listen(0)
213
+ fastify.listen({ port: 0 })
313
214
  .then(address => {
314
215
  t.equal(address, `http://${localhostForURL}:${fastify.server.address().port}`)
315
- fastify.listen(0)
216
+ fastify.listen({ port: 0 })
316
217
  .catch(err => {
317
218
  t.ok(err)
318
219
  })
@@ -325,11 +226,11 @@ test('listen twice on the same port without callback rejects', t => {
325
226
  const fastify = Fastify()
326
227
  t.teardown(fastify.close.bind(fastify))
327
228
 
328
- fastify.listen(0)
229
+ fastify.listen({ port: 0 })
329
230
  .then(() => {
330
231
  const s2 = Fastify()
331
232
  t.teardown(s2.close.bind(s2))
332
- s2.listen(fastify.server.address().port)
233
+ s2.listen({ port: fastify.server.address().port })
333
234
  .catch(err => {
334
235
  t.ok(err)
335
236
  })
@@ -341,12 +242,12 @@ test('listen twice on the same port without callback rejects with (address)', t
341
242
  t.plan(2)
342
243
  const fastify = Fastify()
343
244
  t.teardown(fastify.close.bind(fastify))
344
- fastify.listen(0)
245
+ fastify.listen({ port: 0 })
345
246
  .then(address => {
346
247
  const s2 = Fastify()
347
248
  t.teardown(s2.close.bind(s2))
348
249
  t.equal(address, `http://${localhostForURL}:${fastify.server.address().port}`)
349
- s2.listen(fastify.server.address().port)
250
+ s2.listen({ port: fastify.server.address().port })
350
251
  .catch(err => {
351
252
  t.ok(err)
352
253
  })
@@ -357,7 +258,7 @@ test('listen twice on the same port without callback rejects with (address)', t
357
258
  test('listen on invalid port without callback rejects', t => {
358
259
  const fastify = Fastify()
359
260
  t.teardown(fastify.close.bind(fastify))
360
- return fastify.listen(-1)
261
+ return fastify.listen({ port: -1 })
361
262
  .catch(err => {
362
263
  t.ok(err)
363
264
  return true
@@ -374,28 +275,12 @@ test('listen logs the port as info', t => {
374
275
  msgs.push(msg)
375
276
  }
376
277
 
377
- fastify.listen(0)
278
+ fastify.listen({ port: 0 })
378
279
  .then(() => {
379
280
  t.ok(/http:\/\//.test(msgs[0]))
380
281
  })
381
282
  })
382
283
 
383
- test('listen when firstArg is string(pipe) and without backlog', async t => {
384
- t.plan(1)
385
- const fastify = Fastify()
386
- t.teardown(fastify.close.bind(fastify))
387
- const address = await fastify.listen('\\\\.\\pipe\\testPipe')
388
- t.equal(address, '\\\\.\\pipe\\testPipe')
389
- })
390
-
391
- test('listen when firstArg is string(pipe) and with backlog', async t => {
392
- t.plan(1)
393
- const fastify = Fastify()
394
- t.teardown(fastify.close.bind(fastify))
395
- const address = await fastify.listen('\\\\.\\pipe\\testPipe', 511)
396
- t.equal(address, '\\\\.\\pipe\\testPipe')
397
- })
398
-
399
284
  test('listen on localhost binds IPv4 and IPv6 - promise interface', async t => {
400
285
  const lookups = await dns.lookup('localhost', { all: true })
401
286
  t.plan(2 * lookups.length)
@@ -403,7 +288,7 @@ test('listen on localhost binds IPv4 and IPv6 - promise interface', async t => {
403
288
  const app = Fastify()
404
289
  app.get('/', async () => 'hello localhost')
405
290
  t.teardown(app.close.bind(app))
406
- await app.listen(0, 'localhost')
291
+ await app.listen({ port: 0, host: 'localhost' })
407
292
 
408
293
  for (const lookup of lookups) {
409
294
  await new Promise((resolve, reject) => {
@@ -427,7 +312,7 @@ test('listen on localhost binds to all interfaces (both IPv4 and IPv6 if present
427
312
 
428
313
  const app = Fastify()
429
314
  app.get('/', async () => 'hello localhost')
430
- app.listen(0, 'localhost', (err) => {
315
+ app.listen({ port: 0, host: 'localhost' }, (err) => {
431
316
  t.error(err)
432
317
  t.teardown(app.close.bind(app))
433
318
 
@@ -454,7 +339,7 @@ test('addresses getter', async t => {
454
339
  await app.ready()
455
340
 
456
341
  t.same(app.addresses(), [], 'after ready')
457
- await app.listen(0, 'localhost')
342
+ await app.listen({ port: 0, host: 'localhost' })
458
343
  const { port } = app.server.address()
459
344
  const localAddresses = await dns.lookup('localhost', { all: true })
460
345
  for (const address of localAddresses) {