fastify 5.3.3 → 5.5.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.
- package/.vscode/settings.json +15 -15
- package/LICENSE +1 -1
- package/README.md +2 -0
- package/SECURITY.md +158 -2
- package/build/build-validation.js +20 -1
- package/docs/Guides/Delay-Accepting-Requests.md +8 -5
- package/docs/Guides/Ecosystem.md +20 -5
- package/docs/Guides/Migration-Guide-V5.md +6 -10
- package/docs/Guides/Recommendations.md +1 -1
- package/docs/Reference/ContentTypeParser.md +1 -1
- package/docs/Reference/Errors.md +5 -3
- package/docs/Reference/Hooks.md +16 -20
- package/docs/Reference/Lifecycle.md +2 -2
- package/docs/Reference/Logging.md +3 -3
- package/docs/Reference/Middleware.md +1 -1
- package/docs/Reference/Reply.md +8 -8
- package/docs/Reference/Request.md +2 -2
- package/docs/Reference/Routes.md +7 -6
- package/docs/Reference/Server.md +341 -200
- package/docs/Reference/TypeScript.md +1 -3
- package/docs/Reference/Validation-and-Serialization.md +56 -4
- package/docs/Reference/Warnings.md +2 -1
- package/fastify.d.ts +4 -3
- package/fastify.js +47 -34
- package/lib/configValidator.js +196 -28
- package/lib/contentTypeParser.js +41 -48
- package/lib/error-handler.js +3 -3
- package/lib/errors.js +11 -0
- package/lib/handleRequest.js +13 -17
- package/lib/pluginOverride.js +3 -1
- package/lib/promise.js +23 -0
- package/lib/reply.js +24 -30
- package/lib/request.js +3 -10
- package/lib/route.js +37 -3
- package/lib/server.js +36 -35
- package/lib/symbols.js +1 -0
- package/lib/warnings.js +19 -1
- package/package.json +14 -10
- package/test/404s.test.js +226 -325
- package/test/allow-unsafe-regex.test.js +19 -48
- package/test/als.test.js +28 -40
- package/test/async-await.test.js +84 -128
- package/test/async_hooks.test.js +18 -37
- package/test/body-limit.test.js +90 -63
- package/test/buffer.test.js +22 -0
- package/test/build-certificate.js +1 -1
- package/test/case-insensitive.test.js +44 -65
- package/test/check.test.js +17 -21
- package/test/close-pipelining.test.js +24 -15
- package/test/constrained-routes.test.js +231 -0
- package/test/custom-http-server.test.js +7 -15
- package/test/custom-parser-async.test.js +17 -22
- package/test/custom-parser.0.test.js +267 -348
- package/test/custom-parser.1.test.js +141 -191
- package/test/custom-parser.2.test.js +34 -44
- package/test/custom-parser.3.test.js +56 -104
- package/test/custom-parser.4.test.js +106 -144
- package/test/custom-parser.5.test.js +56 -75
- package/test/custom-querystring-parser.test.js +51 -77
- package/test/decorator-namespace.test._js_ +3 -4
- package/test/decorator.test.js +76 -259
- package/test/delete.test.js +101 -110
- package/test/diagnostics-channel/404.test.js +7 -15
- package/test/diagnostics-channel/async-delay-request.test.js +7 -16
- package/test/diagnostics-channel/async-request.test.js +8 -16
- package/test/diagnostics-channel/error-request.test.js +7 -15
- package/test/diagnostics-channel/sync-delay-request.test.js +7 -16
- package/test/diagnostics-channel/sync-request-reply.test.js +9 -16
- package/test/diagnostics-channel/sync-request.test.js +9 -16
- package/test/fastify-instance.test.js +1 -1
- package/test/header-overflow.test.js +18 -29
- package/test/helper.js +139 -135
- package/test/hooks-async.test.js +259 -235
- package/test/hooks.test.js +951 -996
- package/test/http-methods/copy.test.js +14 -19
- package/test/http-methods/get.test.js +131 -143
- package/test/http-methods/head.test.js +53 -84
- package/test/http-methods/lock.test.js +31 -31
- package/test/http-methods/mkcalendar.test.js +45 -72
- package/test/http-methods/mkcol.test.js +5 -9
- package/test/http-methods/move.test.js +6 -10
- package/test/http-methods/propfind.test.js +34 -44
- package/test/http-methods/proppatch.test.js +23 -29
- package/test/http-methods/report.test.js +44 -69
- package/test/http-methods/search.test.js +67 -82
- package/test/http-methods/unlock.test.js +5 -9
- package/test/http2/closing.test.js +38 -20
- package/test/http2/secure-with-fallback.test.js +31 -28
- package/test/https/custom-https-server.test.js +9 -13
- package/test/https/https.test.js +56 -53
- package/test/input-validation.js +139 -150
- package/test/internals/errors.test.js +50 -1
- package/test/internals/handle-request.test.js +72 -65
- package/test/internals/promise.test.js +63 -0
- package/test/internals/reply.test.js +277 -496
- package/test/issue-4959.test.js +12 -3
- package/test/listen.4.test.js +31 -43
- package/test/nullable-validation.test.js +33 -46
- package/test/output-validation.test.js +24 -26
- package/test/plugin.1.test.js +40 -68
- package/test/plugin.2.test.js +108 -120
- package/test/plugin.3.test.js +50 -72
- package/test/plugin.4.test.js +124 -119
- package/test/promises.test.js +42 -63
- package/test/proto-poisoning.test.js +78 -97
- package/test/register.test.js +8 -18
- package/test/request-error.test.js +57 -146
- package/test/request-id.test.js +30 -49
- package/test/route-hooks.test.js +117 -101
- package/test/route-prefix.test.js +194 -133
- package/test/route-shorthand.test.js +9 -27
- package/test/route.1.test.js +74 -131
- package/test/route.8.test.js +9 -17
- package/test/router-options.test.js +450 -0
- package/test/schema-serialization.test.js +177 -154
- package/test/schema-special-usage.test.js +165 -132
- package/test/schema-validation.test.js +254 -218
- package/test/server.test.js +143 -5
- package/test/set-error-handler.test.js +58 -1
- package/test/skip-reply-send.test.js +64 -69
- package/test/stream.1.test.js +33 -50
- package/test/stream.4.test.js +18 -28
- package/test/stream.5.test.js +11 -19
- package/test/trust-proxy.test.js +32 -58
- package/test/types/errors.test-d.ts +13 -1
- package/test/types/fastify.test-d.ts +3 -0
- package/test/types/request.test-d.ts +1 -0
- package/test/types/type-provider.test-d.ts +55 -0
- package/test/url-rewriting.test.js +45 -62
- package/test/use-semicolon-delimiter.test.js +117 -59
- package/test/versioned-routes.test.js +39 -56
- package/types/errors.d.ts +11 -1
- package/types/hooks.d.ts +1 -1
- package/types/instance.d.ts +1 -1
- package/types/reply.d.ts +2 -2
- package/types/request.d.ts +1 -0
- package/.taprc +0 -7
package/test/delete.test.js
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
-
const assert = require('node:assert')
|
|
4
3
|
const { test } = require('node:test')
|
|
5
|
-
const sget = require('simple-get').concat
|
|
6
4
|
const fastify = require('..')()
|
|
7
5
|
|
|
8
6
|
const schema = {
|
|
@@ -159,155 +157,148 @@ test('body - delete', t => {
|
|
|
159
157
|
}
|
|
160
158
|
})
|
|
161
159
|
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
160
|
+
test('delete tests', async t => {
|
|
161
|
+
const fastifyServer = await fastify.listen({ port: 0 })
|
|
162
|
+
t.after(() => { fastify.close() })
|
|
165
163
|
|
|
166
|
-
test('shorthand - request delete',
|
|
164
|
+
await t.test('shorthand - request delete', async t => {
|
|
167
165
|
t.plan(4)
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
}, (err, response, body) => {
|
|
172
|
-
t.assert.ifError(err)
|
|
173
|
-
t.assert.strictEqual(response.statusCode, 200)
|
|
174
|
-
t.assert.strictEqual(response.headers['content-length'], '' + body.length)
|
|
175
|
-
t.assert.deepStrictEqual(JSON.parse(body), { hello: 'world' })
|
|
176
|
-
done()
|
|
166
|
+
|
|
167
|
+
const response = await fetch(fastifyServer, {
|
|
168
|
+
method: 'DELETE'
|
|
177
169
|
})
|
|
170
|
+
t.assert.ok(response.ok)
|
|
171
|
+
t.assert.strictEqual(response.status, 200)
|
|
172
|
+
const body = await response.text()
|
|
173
|
+
t.assert.strictEqual(response.headers.get('content-length'), '' + body.length)
|
|
174
|
+
t.assert.deepStrictEqual(JSON.parse(body), { hello: 'world' })
|
|
178
175
|
})
|
|
179
176
|
|
|
180
|
-
test('shorthand - request delete params schema',
|
|
177
|
+
await t.test('shorthand - request delete params schema', async t => {
|
|
181
178
|
t.plan(4)
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
}, (err, response, body) => {
|
|
186
|
-
t.assert.ifError(err)
|
|
187
|
-
t.assert.strictEqual(response.statusCode, 200)
|
|
188
|
-
t.assert.strictEqual(response.headers['content-length'], '' + body.length)
|
|
189
|
-
t.assert.deepStrictEqual(JSON.parse(body), { foo: 'world', test: 123 })
|
|
190
|
-
done()
|
|
179
|
+
|
|
180
|
+
const response = await fetch(fastifyServer + '/params/world/123', {
|
|
181
|
+
method: 'DELETE'
|
|
191
182
|
})
|
|
183
|
+
t.assert.ok(response.ok)
|
|
184
|
+
t.assert.strictEqual(response.status, 200)
|
|
185
|
+
const body = await response.text()
|
|
186
|
+
t.assert.strictEqual(response.headers.get('content-length'), '' + body.length)
|
|
187
|
+
t.assert.deepStrictEqual(JSON.parse(body), { foo: 'world', test: 123 })
|
|
192
188
|
})
|
|
193
189
|
|
|
194
|
-
test('shorthand - request delete params schema error',
|
|
190
|
+
await t.test('shorthand - request delete params schema error', async t => {
|
|
195
191
|
t.plan(3)
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
done()
|
|
192
|
+
|
|
193
|
+
const response = await fetch(fastifyServer + '/params/world/string', {
|
|
194
|
+
method: 'DELETE'
|
|
195
|
+
})
|
|
196
|
+
|
|
197
|
+
t.assert.ok(!response.ok)
|
|
198
|
+
t.assert.strictEqual(response.status, 400)
|
|
199
|
+
t.assert.deepStrictEqual(await response.json(), {
|
|
200
|
+
error: 'Bad Request',
|
|
201
|
+
code: 'FST_ERR_VALIDATION',
|
|
202
|
+
message: 'params/test must be integer',
|
|
203
|
+
statusCode: 400
|
|
209
204
|
})
|
|
210
205
|
})
|
|
211
206
|
|
|
212
|
-
test('shorthand - request delete headers schema',
|
|
207
|
+
await t.test('shorthand - request delete headers schema', async t => {
|
|
213
208
|
t.plan(4)
|
|
214
|
-
|
|
209
|
+
|
|
210
|
+
const response = await fetch(fastifyServer + '/headers', {
|
|
215
211
|
method: 'DELETE',
|
|
216
212
|
headers: {
|
|
217
|
-
'x-test': 1
|
|
218
|
-
}
|
|
219
|
-
url: 'http://localhost:' + fastify.server.address().port + '/headers'
|
|
220
|
-
}, (err, response, body) => {
|
|
221
|
-
t.assert.ifError(err)
|
|
222
|
-
t.assert.strictEqual(response.statusCode, 200)
|
|
223
|
-
t.assert.strictEqual(response.headers['content-length'], '' + body.length)
|
|
224
|
-
t.assert.strictEqual(JSON.parse(body)['x-test'], 1)
|
|
225
|
-
done()
|
|
213
|
+
'x-test': '1'
|
|
214
|
+
}
|
|
226
215
|
})
|
|
216
|
+
t.assert.ok(response.ok)
|
|
217
|
+
t.assert.strictEqual(response.status, 200)
|
|
218
|
+
const body = await response.text()
|
|
219
|
+
t.assert.strictEqual(response.headers.get('content-length'), '' + body.length)
|
|
220
|
+
t.assert.strictEqual(JSON.parse(body)['x-test'], 1)
|
|
227
221
|
})
|
|
228
222
|
|
|
229
|
-
test('shorthand - request delete headers schema error',
|
|
223
|
+
await t.test('shorthand - request delete headers schema error', async t => {
|
|
230
224
|
t.plan(3)
|
|
231
|
-
|
|
225
|
+
|
|
226
|
+
const response = await fetch(fastifyServer + '/headers', {
|
|
232
227
|
method: 'DELETE',
|
|
233
228
|
headers: {
|
|
234
229
|
'x-test': 'abc'
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
done()
|
|
230
|
+
}
|
|
231
|
+
})
|
|
232
|
+
|
|
233
|
+
t.assert.ok(!response.ok)
|
|
234
|
+
t.assert.strictEqual(response.status, 400)
|
|
235
|
+
const body = await response.text()
|
|
236
|
+
t.assert.deepStrictEqual(JSON.parse(body), {
|
|
237
|
+
error: 'Bad Request',
|
|
238
|
+
code: 'FST_ERR_VALIDATION',
|
|
239
|
+
message: 'headers/x-test must be number',
|
|
240
|
+
statusCode: 400
|
|
247
241
|
})
|
|
248
242
|
})
|
|
249
243
|
|
|
250
|
-
test('shorthand - request delete querystring schema',
|
|
244
|
+
await t.test('shorthand - request delete querystring schema', async t => {
|
|
251
245
|
t.plan(4)
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
}, (err, response, body) => {
|
|
256
|
-
t.assert.ifError(err)
|
|
257
|
-
t.assert.strictEqual(response.statusCode, 200)
|
|
258
|
-
t.assert.strictEqual(response.headers['content-length'], '' + body.length)
|
|
259
|
-
t.assert.deepStrictEqual(JSON.parse(body), { hello: 123 })
|
|
260
|
-
done()
|
|
246
|
+
|
|
247
|
+
const response = await fetch(fastifyServer + '/query?hello=123', {
|
|
248
|
+
method: 'DELETE'
|
|
261
249
|
})
|
|
250
|
+
t.assert.ok(response.ok)
|
|
251
|
+
t.assert.strictEqual(response.status, 200)
|
|
252
|
+
const body = await response.text()
|
|
253
|
+
t.assert.strictEqual(response.headers.get('content-length'), '' + body.length)
|
|
254
|
+
t.assert.deepStrictEqual(JSON.parse(body), { hello: 123 })
|
|
262
255
|
})
|
|
263
256
|
|
|
264
|
-
test('shorthand - request delete querystring schema error',
|
|
257
|
+
await t.test('shorthand - request delete querystring schema error', async t => {
|
|
265
258
|
t.plan(3)
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
}
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
259
|
+
|
|
260
|
+
const response = await fetch(fastifyServer + '/query?hello=world', {
|
|
261
|
+
method: 'DELETE'
|
|
262
|
+
})
|
|
263
|
+
|
|
264
|
+
t.assert.ok(!response.ok)
|
|
265
|
+
t.assert.strictEqual(response.status, 400)
|
|
266
|
+
const body = await response.text()
|
|
267
|
+
t.assert.deepStrictEqual(JSON.parse(body), {
|
|
268
|
+
error: 'Bad Request',
|
|
269
|
+
code: 'FST_ERR_VALIDATION',
|
|
270
|
+
message: 'querystring/hello must be integer',
|
|
271
|
+
statusCode: 400
|
|
279
272
|
})
|
|
280
273
|
})
|
|
281
274
|
|
|
282
|
-
test('shorthand - request delete missing schema',
|
|
275
|
+
await t.test('shorthand - request delete missing schema', async t => {
|
|
283
276
|
t.plan(4)
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
}, (err, response, body) => {
|
|
288
|
-
t.assert.ifError(err)
|
|
289
|
-
t.assert.strictEqual(response.statusCode, 200)
|
|
290
|
-
t.assert.strictEqual(response.headers['content-length'], '' + body.length)
|
|
291
|
-
t.assert.deepStrictEqual(JSON.parse(body), { hello: 'world' })
|
|
292
|
-
done()
|
|
277
|
+
|
|
278
|
+
const response = await fetch(fastifyServer + '/missing', {
|
|
279
|
+
method: 'DELETE'
|
|
293
280
|
})
|
|
281
|
+
t.assert.ok(response.ok)
|
|
282
|
+
t.assert.strictEqual(response.status, 200)
|
|
283
|
+
const body = await response.text()
|
|
284
|
+
t.assert.strictEqual(response.headers.get('content-length'), '' + body.length)
|
|
285
|
+
t.assert.deepStrictEqual(JSON.parse(body), { hello: 'world' })
|
|
294
286
|
})
|
|
295
287
|
|
|
296
|
-
test('shorthand - delete with body',
|
|
288
|
+
await t.test('shorthand - delete with body', async t => {
|
|
297
289
|
t.plan(3)
|
|
298
|
-
|
|
290
|
+
|
|
291
|
+
const response = await fetch(fastifyServer + '/body', {
|
|
299
292
|
method: 'DELETE',
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
}
|
|
304
|
-
json: true
|
|
305
|
-
}, (err, response, body) => {
|
|
306
|
-
t.assert.ifError(err)
|
|
307
|
-
t.assert.strictEqual(response.statusCode, 200)
|
|
308
|
-
t.assert.deepStrictEqual(body, { hello: 'world' })
|
|
309
|
-
done()
|
|
293
|
+
body: JSON.stringify({ hello: 'world' }),
|
|
294
|
+
headers: {
|
|
295
|
+
'Content-Type': 'application/json'
|
|
296
|
+
}
|
|
310
297
|
})
|
|
298
|
+
t.assert.ok(response.ok)
|
|
299
|
+
t.assert.strictEqual(response.status, 200)
|
|
300
|
+
const body = await response.json()
|
|
301
|
+
t.assert.deepStrictEqual(body, { hello: 'world' })
|
|
311
302
|
})
|
|
312
303
|
})
|
|
313
304
|
|
|
@@ -2,13 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
const { test } = require('node:test')
|
|
4
4
|
const diagnostics = require('node:diagnostics_channel')
|
|
5
|
-
const sget = require('simple-get').concat
|
|
6
5
|
const Fastify = require('../..')
|
|
7
|
-
const { getServerUrl } = require('../helper')
|
|
8
6
|
const Request = require('../../lib/request')
|
|
9
7
|
const Reply = require('../../lib/reply')
|
|
10
8
|
|
|
11
|
-
test('diagnostics channel sync events fire in expected order',
|
|
9
|
+
test('diagnostics channel sync events fire in expected order', async t => {
|
|
12
10
|
t.plan(9)
|
|
13
11
|
let callOrder = 0
|
|
14
12
|
let firstEncounteredMessage
|
|
@@ -40,18 +38,12 @@ test('diagnostics channel sync events fire in expected order', (t, done) => {
|
|
|
40
38
|
}
|
|
41
39
|
})
|
|
42
40
|
|
|
43
|
-
fastify.listen({ port: 0 }
|
|
44
|
-
|
|
41
|
+
const fastifyServer = await fastify.listen({ port: 0 })
|
|
42
|
+
t.after(() => { fastify.close() })
|
|
45
43
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
sget({
|
|
49
|
-
method: 'GET',
|
|
50
|
-
url: getServerUrl(fastify) + '/'
|
|
51
|
-
}, (err, response, body) => {
|
|
52
|
-
t.assert.ifError(err)
|
|
53
|
-
t.assert.strictEqual(response.statusCode, 404)
|
|
54
|
-
done()
|
|
55
|
-
})
|
|
44
|
+
const response = await fetch(fastifyServer, {
|
|
45
|
+
method: 'GET'
|
|
56
46
|
})
|
|
47
|
+
t.assert.ok(!response.ok)
|
|
48
|
+
t.assert.strictEqual(response.status, 404)
|
|
57
49
|
})
|
|
@@ -2,13 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
const diagnostics = require('node:diagnostics_channel')
|
|
4
4
|
const { test } = require('node:test')
|
|
5
|
-
const sget = require('simple-get').concat
|
|
6
5
|
const Fastify = require('../..')
|
|
7
|
-
const { getServerUrl } = require('../helper')
|
|
8
6
|
const Request = require('../../lib/request')
|
|
9
7
|
const Reply = require('../../lib/reply')
|
|
10
8
|
|
|
11
|
-
test('diagnostics channel async events fire in expected order',
|
|
9
|
+
test('diagnostics channel async events fire in expected order', async t => {
|
|
12
10
|
t.plan(19)
|
|
13
11
|
let callOrder = 0
|
|
14
12
|
let firstEncounteredMessage
|
|
@@ -56,19 +54,12 @@ test('diagnostics channel async events fire in expected order', (t, done) => {
|
|
|
56
54
|
}
|
|
57
55
|
})
|
|
58
56
|
|
|
59
|
-
|
|
60
|
-
if (err) t.assert.ifError(err)
|
|
57
|
+
t.after(() => { fastify.close() })
|
|
61
58
|
|
|
62
|
-
|
|
59
|
+
const fastifyServer = await fastify.listen({ port: 0 })
|
|
63
60
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
t.assert.ifError(err)
|
|
69
|
-
t.assert.strictEqual(response.statusCode, 200)
|
|
70
|
-
t.assert.deepStrictEqual(JSON.parse(body), { hello: 'world' })
|
|
71
|
-
done()
|
|
72
|
-
})
|
|
73
|
-
})
|
|
61
|
+
const result = await fetch(fastifyServer + '/')
|
|
62
|
+
t.assert.ok(result.ok)
|
|
63
|
+
t.assert.strictEqual(result.status, 200)
|
|
64
|
+
t.assert.deepStrictEqual(await result.json(), { hello: 'world' })
|
|
74
65
|
})
|
|
@@ -2,13 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
const { test } = require('node:test')
|
|
4
4
|
const diagnostics = require('node:diagnostics_channel')
|
|
5
|
-
const sget = require('simple-get').concat
|
|
6
5
|
const Fastify = require('../..')
|
|
7
|
-
const { getServerUrl } = require('../helper')
|
|
8
6
|
const Request = require('../../lib/request')
|
|
9
7
|
const Reply = require('../../lib/reply')
|
|
10
8
|
|
|
11
|
-
test('diagnostics channel async events fire in expected order',
|
|
9
|
+
test('diagnostics channel async events fire in expected order', async t => {
|
|
12
10
|
t.plan(18)
|
|
13
11
|
let callOrder = 0
|
|
14
12
|
let firstEncounteredMessage
|
|
@@ -54,19 +52,13 @@ test('diagnostics channel async events fire in expected order', (t, done) => {
|
|
|
54
52
|
}
|
|
55
53
|
})
|
|
56
54
|
|
|
57
|
-
fastify.listen({ port: 0 }
|
|
58
|
-
if (err) t.assert.ifError(err)
|
|
55
|
+
const fastifyServer = await fastify.listen({ port: 0 })
|
|
59
56
|
|
|
60
|
-
|
|
57
|
+
t.after(() => { fastify.close() })
|
|
61
58
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
t.assert.strictEqual(response.statusCode, 200)
|
|
68
|
-
t.assert.deepStrictEqual(JSON.parse(body), { hello: 'world' })
|
|
69
|
-
done()
|
|
70
|
-
})
|
|
71
|
-
})
|
|
59
|
+
const response = await fetch(fastifyServer)
|
|
60
|
+
t.assert.ok(response.ok)
|
|
61
|
+
t.assert.strictEqual(response.status, 200)
|
|
62
|
+
const body = await response.text()
|
|
63
|
+
t.assert.deepStrictEqual(JSON.parse(body), { hello: 'world' })
|
|
72
64
|
})
|
|
@@ -2,13 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
const { test } = require('node:test')
|
|
4
4
|
const diagnostics = require('node:diagnostics_channel')
|
|
5
|
-
const sget = require('simple-get').concat
|
|
6
5
|
const Fastify = require('../..')
|
|
7
|
-
const { getServerUrl } = require('../helper')
|
|
8
6
|
const Request = require('../../lib/request')
|
|
9
7
|
const Reply = require('../../lib/reply')
|
|
10
8
|
|
|
11
|
-
test('diagnostics channel events report on errors',
|
|
9
|
+
test('diagnostics channel events report on errors', async t => {
|
|
12
10
|
t.plan(14)
|
|
13
11
|
let callOrder = 0
|
|
14
12
|
let firstEncounteredMessage
|
|
@@ -44,18 +42,12 @@ test('diagnostics channel events report on errors', (t, done) => {
|
|
|
44
42
|
}
|
|
45
43
|
})
|
|
46
44
|
|
|
47
|
-
fastify.listen({ port: 0 }
|
|
48
|
-
|
|
45
|
+
const fastifyServer = await fastify.listen({ port: 0 })
|
|
46
|
+
t.after(() => { fastify.close() })
|
|
49
47
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
sget({
|
|
53
|
-
method: 'GET',
|
|
54
|
-
url: getServerUrl(fastify) + '/'
|
|
55
|
-
}, (err, response, body) => {
|
|
56
|
-
t.assert.ifError(err)
|
|
57
|
-
t.assert.strictEqual(response.statusCode, 500)
|
|
58
|
-
done()
|
|
59
|
-
})
|
|
48
|
+
const response = await fetch(fastifyServer, {
|
|
49
|
+
method: 'GET'
|
|
60
50
|
})
|
|
51
|
+
t.assert.ok(!response.ok)
|
|
52
|
+
t.assert.strictEqual(response.status, 500)
|
|
61
53
|
})
|
|
@@ -2,13 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
const { test } = require('node:test')
|
|
4
4
|
const diagnostics = require('node:diagnostics_channel')
|
|
5
|
-
const sget = require('simple-get').concat
|
|
6
5
|
const Fastify = require('../..')
|
|
7
|
-
const { getServerUrl } = require('../helper')
|
|
8
6
|
const Request = require('../../lib/request')
|
|
9
7
|
const Reply = require('../../lib/reply')
|
|
10
8
|
|
|
11
|
-
test('diagnostics channel sync events fire in expected order',
|
|
9
|
+
test('diagnostics channel sync events fire in expected order', async t => {
|
|
12
10
|
t.plan(10)
|
|
13
11
|
let callOrder = 0
|
|
14
12
|
let firstEncounteredMessage
|
|
@@ -40,19 +38,12 @@ test('diagnostics channel sync events fire in expected order', (t, done) => {
|
|
|
40
38
|
}
|
|
41
39
|
})
|
|
42
40
|
|
|
43
|
-
|
|
44
|
-
if (err) t.assert.ifError(err)
|
|
41
|
+
t.after(() => { fastify.close() })
|
|
45
42
|
|
|
46
|
-
|
|
43
|
+
const fastifyServer = await fastify.listen({ port: 0 })
|
|
47
44
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
t.assert.ifError(err)
|
|
53
|
-
t.assert.strictEqual(response.statusCode, 200)
|
|
54
|
-
t.assert.deepStrictEqual(JSON.parse(body), { hello: 'world' })
|
|
55
|
-
done()
|
|
56
|
-
})
|
|
57
|
-
})
|
|
45
|
+
const result = await fetch(fastifyServer + '/')
|
|
46
|
+
t.assert.ok(result.ok)
|
|
47
|
+
t.assert.strictEqual(result.status, 200)
|
|
48
|
+
t.assert.deepStrictEqual(await result.json(), { hello: 'world' })
|
|
58
49
|
})
|
|
@@ -2,13 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
const { test } = require('node:test')
|
|
4
4
|
const diagnostics = require('node:diagnostics_channel')
|
|
5
|
-
const sget = require('simple-get').concat
|
|
6
5
|
const Fastify = require('../..')
|
|
7
|
-
const { getServerUrl } = require('../helper')
|
|
8
6
|
const Request = require('../../lib/request')
|
|
9
7
|
const Reply = require('../../lib/reply')
|
|
10
8
|
|
|
11
|
-
test('diagnostics channel sync events fire in expected order',
|
|
9
|
+
test('diagnostics channel sync events fire in expected order', async t => {
|
|
12
10
|
t.plan(10)
|
|
13
11
|
let callOrder = 0
|
|
14
12
|
let firstEncounteredMessage
|
|
@@ -40,19 +38,14 @@ test('diagnostics channel sync events fire in expected order', (t, done) => {
|
|
|
40
38
|
}
|
|
41
39
|
})
|
|
42
40
|
|
|
43
|
-
fastify.listen({ port: 0 }
|
|
44
|
-
|
|
41
|
+
const fastifyServer = await fastify.listen({ port: 0 })
|
|
42
|
+
t.after(() => { fastify.close() })
|
|
45
43
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
sget({
|
|
49
|
-
method: 'GET',
|
|
50
|
-
url: getServerUrl(fastify) + '/'
|
|
51
|
-
}, (err, response, body) => {
|
|
52
|
-
t.assert.ifError(err)
|
|
53
|
-
t.assert.strictEqual(response.statusCode, 200)
|
|
54
|
-
t.assert.deepStrictEqual(JSON.parse(body), { hello: 'world' })
|
|
55
|
-
done()
|
|
56
|
-
})
|
|
44
|
+
const response = await fetch(fastifyServer, {
|
|
45
|
+
method: 'GET'
|
|
57
46
|
})
|
|
47
|
+
t.assert.ok(response.ok)
|
|
48
|
+
t.assert.strictEqual(response.status, 200)
|
|
49
|
+
const body = await response.text()
|
|
50
|
+
t.assert.deepStrictEqual(JSON.parse(body), { hello: 'world' })
|
|
58
51
|
})
|
|
@@ -2,13 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
const { test } = require('node:test')
|
|
4
4
|
const diagnostics = require('node:diagnostics_channel')
|
|
5
|
-
const sget = require('simple-get').concat
|
|
6
5
|
const Fastify = require('../..')
|
|
7
|
-
const { getServerUrl } = require('../helper')
|
|
8
6
|
const Request = require('../../lib/request')
|
|
9
7
|
const Reply = require('../../lib/reply')
|
|
10
8
|
|
|
11
|
-
test('diagnostics channel sync events fire in expected order',
|
|
9
|
+
test('diagnostics channel sync events fire in expected order', async t => {
|
|
12
10
|
t.plan(13)
|
|
13
11
|
let callOrder = 0
|
|
14
12
|
let firstEncounteredMessage
|
|
@@ -43,19 +41,14 @@ test('diagnostics channel sync events fire in expected order', (t, done) => {
|
|
|
43
41
|
}
|
|
44
42
|
})
|
|
45
43
|
|
|
46
|
-
fastify.listen({ port: 0 }
|
|
47
|
-
|
|
44
|
+
const fastifyServer = await fastify.listen({ port: 0 })
|
|
45
|
+
t.after(() => { fastify.close() })
|
|
48
46
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
sget({
|
|
52
|
-
method: 'GET',
|
|
53
|
-
url: getServerUrl(fastify) + '/7'
|
|
54
|
-
}, (err, response, body) => {
|
|
55
|
-
t.assert.ifError(err)
|
|
56
|
-
t.assert.strictEqual(response.statusCode, 200)
|
|
57
|
-
t.assert.deepStrictEqual(JSON.parse(body), { hello: 'world' })
|
|
58
|
-
done()
|
|
59
|
-
})
|
|
47
|
+
const response = await fetch(fastifyServer + '/7', {
|
|
48
|
+
method: 'GET'
|
|
60
49
|
})
|
|
50
|
+
t.assert.ok(response.ok)
|
|
51
|
+
t.assert.strictEqual(response.status, 200)
|
|
52
|
+
const body = await response.text()
|
|
53
|
+
t.assert.deepStrictEqual(JSON.parse(body), { hello: 'world' })
|
|
61
54
|
})
|
|
@@ -296,5 +296,5 @@ test('fastify instance should ensure ready promise cleanup on ready', async t =>
|
|
|
296
296
|
t.plan(1)
|
|
297
297
|
const fastify = Fastify()
|
|
298
298
|
await fastify.ready()
|
|
299
|
-
t.assert.strictEqual(fastify[kState].
|
|
299
|
+
t.assert.strictEqual(fastify[kState].readyResolver, null)
|
|
300
300
|
})
|
|
@@ -2,12 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
const { test } = require('node:test')
|
|
4
4
|
const Fastify = require('..')
|
|
5
|
-
const sget = require('simple-get').concat
|
|
6
5
|
|
|
7
6
|
const maxHeaderSize = 1024
|
|
8
7
|
|
|
9
|
-
test('Should return 431 if request header fields are too large', (t
|
|
10
|
-
t.plan(
|
|
8
|
+
test('Should return 431 if request header fields are too large', async (t) => {
|
|
9
|
+
t.plan(2)
|
|
11
10
|
|
|
12
11
|
const fastify = Fastify({ http: { maxHeaderSize } })
|
|
13
12
|
fastify.route({
|
|
@@ -18,27 +17,23 @@ test('Should return 431 if request header fields are too large', (t, done) => {
|
|
|
18
17
|
}
|
|
19
18
|
})
|
|
20
19
|
|
|
21
|
-
fastify.listen({ port: 0 }
|
|
22
|
-
t.assert.ifError(err)
|
|
20
|
+
const fastifyServer = await fastify.listen({ port: 0 })
|
|
23
21
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
}
|
|
30
|
-
}, (err, res) => {
|
|
31
|
-
t.assert.ifError(err)
|
|
32
|
-
t.assert.strictEqual(res.statusCode, 431)
|
|
33
|
-
done()
|
|
34
|
-
})
|
|
22
|
+
const result = await fetch(fastifyServer, {
|
|
23
|
+
method: 'GET',
|
|
24
|
+
headers: {
|
|
25
|
+
'Large-Header': 'a'.repeat(maxHeaderSize)
|
|
26
|
+
}
|
|
35
27
|
})
|
|
36
28
|
|
|
29
|
+
t.assert.ok(!result.ok)
|
|
30
|
+
t.assert.strictEqual(result.status, 431)
|
|
31
|
+
|
|
37
32
|
t.after(() => fastify.close())
|
|
38
33
|
})
|
|
39
34
|
|
|
40
|
-
test('Should return 431 if URI is too long', (t
|
|
41
|
-
t.plan(
|
|
35
|
+
test('Should return 431 if URI is too long', async (t) => {
|
|
36
|
+
t.plan(2)
|
|
42
37
|
|
|
43
38
|
const fastify = Fastify({ http: { maxHeaderSize } })
|
|
44
39
|
fastify.route({
|
|
@@ -49,18 +44,12 @@ test('Should return 431 if URI is too long', (t, done) => {
|
|
|
49
44
|
}
|
|
50
45
|
})
|
|
51
46
|
|
|
52
|
-
fastify.listen({ port: 0 }
|
|
53
|
-
t.assert.ifError(err)
|
|
47
|
+
const fastifyServer = await fastify.listen({ port: 0 })
|
|
54
48
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
t.assert.ifError(err)
|
|
60
|
-
t.assert.strictEqual(res.statusCode, 431)
|
|
61
|
-
done()
|
|
62
|
-
})
|
|
63
|
-
})
|
|
49
|
+
const result = await fetch(`${fastifyServer}/${'a'.repeat(maxHeaderSize)}`)
|
|
50
|
+
|
|
51
|
+
t.assert.ok(!result.ok)
|
|
52
|
+
t.assert.strictEqual(result.status, 431)
|
|
64
53
|
|
|
65
54
|
t.after(() => fastify.close())
|
|
66
55
|
})
|