fastify 5.3.2 → 5.4.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/README.md +2 -0
- package/build/build-validation.js +2 -1
- package/docs/Guides/Delay-Accepting-Requests.md +3 -3
- package/docs/Guides/Ecosystem.md +16 -7
- package/docs/Guides/Serverless.md +28 -69
- package/docs/Reference/ContentTypeParser.md +1 -1
- package/docs/Reference/Errors.md +2 -4
- package/docs/Reference/Hooks.md +14 -14
- 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 +1 -1
- package/docs/Reference/Routes.md +3 -3
- package/docs/Reference/Server.md +40 -10
- package/docs/Reference/Validation-and-Serialization.md +1 -1
- package/eslint.config.js +17 -9
- package/fastify.d.ts +2 -1
- package/fastify.js +20 -4
- package/lib/configValidator.js +1 -1
- package/lib/decorate.js +2 -2
- package/lib/errors.js +6 -8
- package/lib/logger-factory.js +1 -1
- package/lib/logger-pino.js +2 -2
- package/lib/pluginOverride.js +3 -1
- package/lib/reply.js +9 -13
- package/lib/request.js +4 -11
- package/lib/server.js +30 -51
- package/lib/symbols.js +1 -0
- package/lib/warnings.js +8 -0
- package/package.json +11 -7
- 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 +11 -2
- package/test/body-limit.test.js +41 -65
- package/test/build-certificate.js +1 -1
- package/test/close-pipelining.test.js +5 -4
- package/test/custom-parser-async.test.js +17 -22
- package/test/decorator-namespace.test._js_ +3 -4
- package/test/decorator.test.js +422 -341
- package/test/diagnostics-channel/async-delay-request.test.js +7 -16
- package/test/diagnostics-channel/sync-delay-request.test.js +7 -16
- package/test/helper.js +108 -70
- package/test/hooks-async.test.js +248 -218
- package/test/hooks.on-listen.test.js +255 -239
- package/test/hooks.on-ready.test.js +110 -92
- package/test/hooks.test.js +910 -769
- package/test/http-methods/lock.test.js +31 -31
- package/test/http-methods/mkcol.test.js +5 -9
- 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/http2/closing.test.js +38 -20
- package/test/http2/secure-with-fallback.test.js +28 -27
- package/test/https/https.test.js +56 -53
- package/test/inject.test.js +114 -97
- package/test/input-validation.js +63 -53
- package/test/internals/errors.test.js +0 -10
- package/test/internals/handle-request.test.js +49 -66
- package/test/internals/hooks.test.js +17 -0
- package/test/issue-4959.test.js +14 -5
- package/test/listen.4.test.js +31 -43
- package/test/logger/response.test.js +19 -20
- package/test/nullable-validation.test.js +33 -46
- package/test/options.error-handler.test.js +1 -1
- package/test/options.test.js +1 -1
- package/test/output-validation.test.js +49 -72
- package/test/patch.error-handler.test.js +1 -1
- package/test/patch.test.js +1 -1
- package/test/plugin.1.test.js +71 -60
- package/test/plugin.2.test.js +104 -86
- package/test/plugin.3.test.js +56 -35
- package/test/plugin.4.test.js +124 -119
- package/test/promises.test.js +36 -30
- package/test/proto-poisoning.test.js +78 -97
- package/test/put.error-handler.test.js +1 -1
- package/test/put.test.js +1 -1
- package/test/reply-error.test.js +169 -148
- package/test/reply-trailers.test.js +119 -108
- package/test/request-error.test.js +0 -46
- package/test/route-hooks.test.js +112 -92
- package/test/route-prefix.test.js +194 -133
- package/test/schema-feature.test.js +309 -238
- package/test/schema-serialization.test.js +177 -154
- package/test/schema-special-usage.test.js +165 -132
- package/test/schema-validation.test.js +278 -199
- package/test/set-error-handler.test.js +58 -1
- package/test/skip-reply-send.test.js +64 -69
- package/test/stream.1.test.js +30 -27
- package/test/stream.2.test.js +20 -10
- package/test/stream.3.test.js +37 -31
- package/test/trust-proxy.test.js +32 -58
- package/test/types/errors.test-d.ts +0 -1
- package/test/types/fastify.test-d.ts +3 -0
- package/test/types/plugin.test-d.ts +1 -1
- package/test/types/register.test-d.ts +1 -1
- package/test/types/request.test-d.ts +1 -0
- package/test/url-rewriting.test.js +45 -62
- package/test/use-semicolon-delimiter.test.js +1 -1
- package/types/errors.d.ts +0 -1
- package/types/request.d.ts +1 -0
- package/.taprc +0 -7
- package/test/http2/missing-http2-module.test.js +0 -17
package/test/plugin.4.test.js
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
-
const
|
|
4
|
-
const test = t.test
|
|
3
|
+
const { test, describe } = require('node:test')
|
|
5
4
|
const Fastify = require('../fastify')
|
|
6
5
|
const fp = require('fastify-plugin')
|
|
7
6
|
const fakeTimer = require('@sinonjs/fake-timers')
|
|
8
7
|
const { FST_ERR_PLUGIN_INVALID_ASYNC_HANDLER } = require('../lib/errors')
|
|
9
8
|
|
|
10
|
-
test('pluginTimeout', t => {
|
|
9
|
+
test('pluginTimeout', (t, testDone) => {
|
|
11
10
|
t.plan(5)
|
|
12
11
|
const fastify = Fastify({
|
|
13
12
|
pluginTimeout: 10
|
|
@@ -16,16 +15,17 @@ test('pluginTimeout', t => {
|
|
|
16
15
|
// to no call done on purpose
|
|
17
16
|
})
|
|
18
17
|
fastify.ready((err) => {
|
|
19
|
-
t.ok(err)
|
|
20
|
-
t.
|
|
18
|
+
t.assert.ok(err)
|
|
19
|
+
t.assert.strictEqual(err.message,
|
|
21
20
|
"fastify-plugin: Plugin did not start in time: 'function (app, opts, done) { -- // to no call done on purpose'. You may have forgotten to call 'done' function or to resolve a Promise")
|
|
22
|
-
t.
|
|
23
|
-
t.ok(err.cause)
|
|
24
|
-
t.
|
|
21
|
+
t.assert.strictEqual(err.code, 'FST_ERR_PLUGIN_TIMEOUT')
|
|
22
|
+
t.assert.ok(err.cause)
|
|
23
|
+
t.assert.strictEqual(err.cause.code, 'AVV_ERR_PLUGIN_EXEC_TIMEOUT')
|
|
24
|
+
testDone()
|
|
25
25
|
})
|
|
26
26
|
})
|
|
27
27
|
|
|
28
|
-
test('pluginTimeout - named function', t => {
|
|
28
|
+
test('pluginTimeout - named function', (t, testDone) => {
|
|
29
29
|
t.plan(5)
|
|
30
30
|
const fastify = Fastify({
|
|
31
31
|
pluginTimeout: 10
|
|
@@ -34,16 +34,17 @@ test('pluginTimeout - named function', t => {
|
|
|
34
34
|
// to no call done on purpose
|
|
35
35
|
})
|
|
36
36
|
fastify.ready((err) => {
|
|
37
|
-
t.ok(err)
|
|
38
|
-
t.
|
|
37
|
+
t.assert.ok(err)
|
|
38
|
+
t.assert.strictEqual(err.message,
|
|
39
39
|
"fastify-plugin: Plugin did not start in time: 'nameFunction'. You may have forgotten to call 'done' function or to resolve a Promise")
|
|
40
|
-
t.
|
|
41
|
-
t.ok(err.cause)
|
|
42
|
-
t.
|
|
40
|
+
t.assert.strictEqual(err.code, 'FST_ERR_PLUGIN_TIMEOUT')
|
|
41
|
+
t.assert.ok(err.cause)
|
|
42
|
+
t.assert.strictEqual(err.cause.code, 'AVV_ERR_PLUGIN_EXEC_TIMEOUT')
|
|
43
|
+
testDone()
|
|
43
44
|
})
|
|
44
45
|
})
|
|
45
46
|
|
|
46
|
-
test('pluginTimeout default', t => {
|
|
47
|
+
test('pluginTimeout default', (t, testDone) => {
|
|
47
48
|
t.plan(5)
|
|
48
49
|
const clock = fakeTimer.install({ shouldClearNativeTimers: true })
|
|
49
50
|
|
|
@@ -54,18 +55,19 @@ test('pluginTimeout default', t => {
|
|
|
54
55
|
})
|
|
55
56
|
|
|
56
57
|
fastify.ready((err) => {
|
|
57
|
-
t.ok(err)
|
|
58
|
-
t.
|
|
58
|
+
t.assert.ok(err)
|
|
59
|
+
t.assert.strictEqual(err.message,
|
|
59
60
|
"fastify-plugin: Plugin did not start in time: 'function (app, opts, done) { -- // default time elapsed without calling done'. You may have forgotten to call 'done' function or to resolve a Promise")
|
|
60
|
-
t.
|
|
61
|
-
t.ok(err.cause)
|
|
62
|
-
t.
|
|
61
|
+
t.assert.strictEqual(err.code, 'FST_ERR_PLUGIN_TIMEOUT')
|
|
62
|
+
t.assert.ok(err.cause)
|
|
63
|
+
t.assert.strictEqual(err.cause.code, 'AVV_ERR_PLUGIN_EXEC_TIMEOUT')
|
|
64
|
+
testDone()
|
|
63
65
|
})
|
|
64
66
|
|
|
65
|
-
t.
|
|
67
|
+
t.after(clock.uninstall)
|
|
66
68
|
})
|
|
67
69
|
|
|
68
|
-
test('plugin metadata - version', t => {
|
|
70
|
+
test('plugin metadata - version', (t, testDone) => {
|
|
69
71
|
t.plan(1)
|
|
70
72
|
const fastify = Fastify()
|
|
71
73
|
|
|
@@ -78,7 +80,8 @@ test('plugin metadata - version', t => {
|
|
|
78
80
|
fastify.register(plugin)
|
|
79
81
|
|
|
80
82
|
fastify.ready(() => {
|
|
81
|
-
t.
|
|
83
|
+
t.assert.ok('everything right')
|
|
84
|
+
testDone()
|
|
82
85
|
})
|
|
83
86
|
|
|
84
87
|
function plugin (instance, opts, done) {
|
|
@@ -86,7 +89,7 @@ test('plugin metadata - version', t => {
|
|
|
86
89
|
}
|
|
87
90
|
})
|
|
88
91
|
|
|
89
|
-
test('plugin metadata - version range', t => {
|
|
92
|
+
test('plugin metadata - version range', (t, testDone) => {
|
|
90
93
|
t.plan(1)
|
|
91
94
|
const fastify = Fastify()
|
|
92
95
|
|
|
@@ -99,7 +102,8 @@ test('plugin metadata - version range', t => {
|
|
|
99
102
|
fastify.register(plugin)
|
|
100
103
|
|
|
101
104
|
fastify.ready(() => {
|
|
102
|
-
t.
|
|
105
|
+
t.assert.ok('everything right')
|
|
106
|
+
testDone()
|
|
103
107
|
})
|
|
104
108
|
|
|
105
109
|
function plugin (instance, opts, done) {
|
|
@@ -107,7 +111,7 @@ test('plugin metadata - version range', t => {
|
|
|
107
111
|
}
|
|
108
112
|
})
|
|
109
113
|
|
|
110
|
-
test('plugin metadata - version not matching requirement', t => {
|
|
114
|
+
test('plugin metadata - version not matching requirement', (t, testDone) => {
|
|
111
115
|
t.plan(2)
|
|
112
116
|
const fastify = Fastify()
|
|
113
117
|
|
|
@@ -120,8 +124,9 @@ test('plugin metadata - version not matching requirement', t => {
|
|
|
120
124
|
fastify.register(plugin)
|
|
121
125
|
|
|
122
126
|
fastify.ready((err) => {
|
|
123
|
-
t.ok(err)
|
|
124
|
-
t.
|
|
127
|
+
t.assert.ok(err)
|
|
128
|
+
t.assert.strictEqual(err.code, 'FST_ERR_PLUGIN_VERSION_MISMATCH')
|
|
129
|
+
testDone()
|
|
125
130
|
})
|
|
126
131
|
|
|
127
132
|
function plugin (instance, opts, done) {
|
|
@@ -129,7 +134,7 @@ test('plugin metadata - version not matching requirement', t => {
|
|
|
129
134
|
}
|
|
130
135
|
})
|
|
131
136
|
|
|
132
|
-
test('plugin metadata - version not matching requirement 2', t => {
|
|
137
|
+
test('plugin metadata - version not matching requirement 2', (t, testDone) => {
|
|
133
138
|
t.plan(2)
|
|
134
139
|
const fastify = Fastify()
|
|
135
140
|
Object.defineProperty(fastify, 'version', {
|
|
@@ -145,8 +150,9 @@ test('plugin metadata - version not matching requirement 2', t => {
|
|
|
145
150
|
fastify.register(plugin)
|
|
146
151
|
|
|
147
152
|
fastify.ready((err) => {
|
|
148
|
-
t.ok(err)
|
|
149
|
-
t.
|
|
153
|
+
t.assert.ok(err)
|
|
154
|
+
t.assert.strictEqual(err.code, 'FST_ERR_PLUGIN_VERSION_MISMATCH')
|
|
155
|
+
testDone()
|
|
150
156
|
})
|
|
151
157
|
|
|
152
158
|
function plugin (instance, opts, done) {
|
|
@@ -154,7 +160,7 @@ test('plugin metadata - version not matching requirement 2', t => {
|
|
|
154
160
|
}
|
|
155
161
|
})
|
|
156
162
|
|
|
157
|
-
test('plugin metadata - version not matching requirement 3', t => {
|
|
163
|
+
test('plugin metadata - version not matching requirement 3', (t, testDone) => {
|
|
158
164
|
t.plan(2)
|
|
159
165
|
const fastify = Fastify()
|
|
160
166
|
|
|
@@ -167,8 +173,9 @@ test('plugin metadata - version not matching requirement 3', t => {
|
|
|
167
173
|
fastify.register(plugin)
|
|
168
174
|
|
|
169
175
|
fastify.ready((err) => {
|
|
170
|
-
t.ok(err)
|
|
171
|
-
t.
|
|
176
|
+
t.assert.ok(err)
|
|
177
|
+
t.assert.strictEqual(err.code, 'FST_ERR_PLUGIN_VERSION_MISMATCH')
|
|
178
|
+
testDone()
|
|
172
179
|
})
|
|
173
180
|
|
|
174
181
|
function plugin (instance, opts, done) {
|
|
@@ -176,7 +183,7 @@ test('plugin metadata - version not matching requirement 3', t => {
|
|
|
176
183
|
}
|
|
177
184
|
})
|
|
178
185
|
|
|
179
|
-
test('plugin metadata - release candidate', t => {
|
|
186
|
+
test('plugin metadata - release candidate', (t, testDone) => {
|
|
180
187
|
t.plan(2)
|
|
181
188
|
const fastify = Fastify()
|
|
182
189
|
Object.defineProperty(fastify, 'version', {
|
|
@@ -191,8 +198,9 @@ test('plugin metadata - release candidate', t => {
|
|
|
191
198
|
fastify.register(plugin)
|
|
192
199
|
|
|
193
200
|
fastify.ready((err) => {
|
|
194
|
-
t.
|
|
195
|
-
t.
|
|
201
|
+
t.assert.ifError(err)
|
|
202
|
+
t.assert.ok('everything right')
|
|
203
|
+
testDone()
|
|
196
204
|
})
|
|
197
205
|
|
|
198
206
|
function plugin (instance, opts, done) {
|
|
@@ -200,9 +208,9 @@ test('plugin metadata - release candidate', t => {
|
|
|
200
208
|
}
|
|
201
209
|
})
|
|
202
210
|
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
t.plan(
|
|
211
|
+
describe('fastify-rc loads prior version plugins', async () => {
|
|
212
|
+
test('baseline (rc)', (t, testDone) => {
|
|
213
|
+
t.plan(1)
|
|
206
214
|
|
|
207
215
|
const fastify = Fastify()
|
|
208
216
|
Object.defineProperty(fastify, 'version', {
|
|
@@ -221,8 +229,8 @@ test('fastify-rc loads prior version plugins', async t => {
|
|
|
221
229
|
fastify.register(plugin)
|
|
222
230
|
|
|
223
231
|
fastify.ready((err) => {
|
|
224
|
-
t.
|
|
225
|
-
|
|
232
|
+
t.assert.ifError(err)
|
|
233
|
+
testDone()
|
|
226
234
|
})
|
|
227
235
|
|
|
228
236
|
function plugin (instance, opts, done) {
|
|
@@ -234,8 +242,8 @@ test('fastify-rc loads prior version plugins', async t => {
|
|
|
234
242
|
}
|
|
235
243
|
})
|
|
236
244
|
|
|
237
|
-
|
|
238
|
-
t.plan(
|
|
245
|
+
test('pre', (t, testDone) => {
|
|
246
|
+
t.plan(1)
|
|
239
247
|
|
|
240
248
|
const fastify = Fastify()
|
|
241
249
|
Object.defineProperty(fastify, 'version', { value: '99.0.0-pre.1' })
|
|
@@ -245,15 +253,15 @@ test('fastify-rc loads prior version plugins', async t => {
|
|
|
245
253
|
fastify.register(plugin)
|
|
246
254
|
|
|
247
255
|
fastify.ready((err) => {
|
|
248
|
-
t.
|
|
249
|
-
|
|
256
|
+
t.assert.ifError(err)
|
|
257
|
+
testDone()
|
|
250
258
|
})
|
|
251
259
|
|
|
252
260
|
function plugin (instance, opts, done) { done() }
|
|
253
261
|
})
|
|
254
262
|
|
|
255
|
-
|
|
256
|
-
t.plan(
|
|
263
|
+
test('alpha', (t, testDone) => {
|
|
264
|
+
t.plan(1)
|
|
257
265
|
|
|
258
266
|
const fastify = Fastify()
|
|
259
267
|
Object.defineProperty(fastify, 'version', { value: '99.0.0-pre.1' })
|
|
@@ -263,19 +271,17 @@ test('fastify-rc loads prior version plugins', async t => {
|
|
|
263
271
|
fastify.register(plugin)
|
|
264
272
|
|
|
265
273
|
fastify.ready((err) => {
|
|
266
|
-
t.
|
|
267
|
-
|
|
274
|
+
t.assert.ifError(err)
|
|
275
|
+
testDone()
|
|
268
276
|
})
|
|
269
277
|
|
|
270
278
|
function plugin (instance, opts, done) { done() }
|
|
271
279
|
})
|
|
272
280
|
})
|
|
273
281
|
|
|
274
|
-
test('hasPlugin method exists as a function', t => {
|
|
275
|
-
t.plan(1)
|
|
276
|
-
|
|
282
|
+
test('hasPlugin method exists as a function', (t) => {
|
|
277
283
|
const fastify = Fastify()
|
|
278
|
-
t.
|
|
284
|
+
t.assert.strictEqual(typeof fastify.hasPlugin, 'function')
|
|
279
285
|
})
|
|
280
286
|
|
|
281
287
|
test('hasPlugin returns true if the specified plugin has been registered', async t => {
|
|
@@ -284,60 +290,59 @@ test('hasPlugin returns true if the specified plugin has been registered', async
|
|
|
284
290
|
const fastify = Fastify()
|
|
285
291
|
|
|
286
292
|
function pluginA (fastify, opts, done) {
|
|
287
|
-
t.ok(fastify.hasPlugin('plugin-A'))
|
|
293
|
+
t.assert.ok(fastify.hasPlugin('plugin-A'))
|
|
288
294
|
done()
|
|
289
295
|
}
|
|
290
296
|
pluginA[Symbol.for('fastify.display-name')] = 'plugin-A'
|
|
291
297
|
fastify.register(pluginA)
|
|
292
298
|
|
|
293
299
|
fastify.register(function pluginB (fastify, opts, done) {
|
|
294
|
-
t.ok(fastify.hasPlugin('pluginB'))
|
|
300
|
+
t.assert.ok(fastify.hasPlugin('pluginB'))
|
|
295
301
|
done()
|
|
296
302
|
})
|
|
297
303
|
|
|
298
304
|
fastify.register(function (fastify, opts, done) {
|
|
299
305
|
// one line
|
|
300
|
-
t.ok(fastify.hasPlugin('function (fastify, opts, done) { -- // one line'))
|
|
306
|
+
t.assert.ok(fastify.hasPlugin('function (fastify, opts, done) { -- // one line'))
|
|
301
307
|
done()
|
|
302
308
|
})
|
|
303
309
|
|
|
304
310
|
await fastify.ready()
|
|
305
311
|
|
|
306
|
-
t.ok(fastify.hasPlugin('fastify'))
|
|
312
|
+
t.assert.ok(fastify.hasPlugin('fastify'))
|
|
307
313
|
})
|
|
308
314
|
|
|
309
|
-
test('hasPlugin returns false if the specified plugin has not been registered', t => {
|
|
310
|
-
t.plan(1)
|
|
311
|
-
|
|
315
|
+
test('hasPlugin returns false if the specified plugin has not been registered', (t) => {
|
|
312
316
|
const fastify = Fastify()
|
|
313
|
-
t.
|
|
317
|
+
t.assert.ok(!fastify.hasPlugin('pluginFoo'))
|
|
314
318
|
})
|
|
315
319
|
|
|
316
320
|
test('hasPlugin returns false when using encapsulation', async t => {
|
|
317
321
|
t.plan(25)
|
|
318
322
|
|
|
319
323
|
const fastify = Fastify()
|
|
324
|
+
t.after(() => fastify.close())
|
|
320
325
|
|
|
321
326
|
fastify.register(function pluginA (fastify, opts, done) {
|
|
322
|
-
t.ok(fastify.hasPlugin('pluginA'))
|
|
323
|
-
t.
|
|
324
|
-
t.
|
|
325
|
-
t.
|
|
326
|
-
t.
|
|
327
|
+
t.assert.ok(fastify.hasPlugin('pluginA'))
|
|
328
|
+
t.assert.ok(!fastify.hasPlugin('pluginAA'))
|
|
329
|
+
t.assert.ok(!fastify.hasPlugin('pluginAAA'))
|
|
330
|
+
t.assert.ok(!fastify.hasPlugin('pluginAB'))
|
|
331
|
+
t.assert.ok(!fastify.hasPlugin('pluginB'))
|
|
327
332
|
|
|
328
333
|
fastify.register(function pluginAA (fastify, opts, done) {
|
|
329
|
-
t.
|
|
330
|
-
t.ok(fastify.hasPlugin('pluginAA'))
|
|
331
|
-
t.
|
|
332
|
-
t.
|
|
333
|
-
t.
|
|
334
|
+
t.assert.ok(!fastify.hasPlugin('pluginA'))
|
|
335
|
+
t.assert.ok(fastify.hasPlugin('pluginAA'))
|
|
336
|
+
t.assert.ok(!fastify.hasPlugin('pluginAAA'))
|
|
337
|
+
t.assert.ok(!fastify.hasPlugin('pluginAB'))
|
|
338
|
+
t.assert.ok(!fastify.hasPlugin('pluginB'))
|
|
334
339
|
|
|
335
340
|
fastify.register(function pluginAAA (fastify, opts, done) {
|
|
336
|
-
t.
|
|
337
|
-
t.
|
|
338
|
-
t.ok(fastify.hasPlugin('pluginAAA'))
|
|
339
|
-
t.
|
|
340
|
-
t.
|
|
341
|
+
t.assert.ok(!fastify.hasPlugin('pluginA'))
|
|
342
|
+
t.assert.ok(!fastify.hasPlugin('pluginAA'))
|
|
343
|
+
t.assert.ok(fastify.hasPlugin('pluginAAA'))
|
|
344
|
+
t.assert.ok(!fastify.hasPlugin('pluginAB'))
|
|
345
|
+
t.assert.ok(!fastify.hasPlugin('pluginB'))
|
|
341
346
|
|
|
342
347
|
done()
|
|
343
348
|
})
|
|
@@ -346,11 +351,11 @@ test('hasPlugin returns false when using encapsulation', async t => {
|
|
|
346
351
|
})
|
|
347
352
|
|
|
348
353
|
fastify.register(function pluginAB (fastify, opts, done) {
|
|
349
|
-
t.
|
|
350
|
-
t.
|
|
351
|
-
t.
|
|
352
|
-
t.ok(fastify.hasPlugin('pluginAB'))
|
|
353
|
-
t.
|
|
354
|
+
t.assert.ok(!fastify.hasPlugin('pluginA'))
|
|
355
|
+
t.assert.ok(!fastify.hasPlugin('pluginAA'))
|
|
356
|
+
t.assert.ok(!fastify.hasPlugin('pluginAAA'))
|
|
357
|
+
t.assert.ok(fastify.hasPlugin('pluginAB'))
|
|
358
|
+
t.assert.ok(!fastify.hasPlugin('pluginB'))
|
|
354
359
|
|
|
355
360
|
done()
|
|
356
361
|
})
|
|
@@ -359,11 +364,11 @@ test('hasPlugin returns false when using encapsulation', async t => {
|
|
|
359
364
|
})
|
|
360
365
|
|
|
361
366
|
fastify.register(function pluginB (fastify, opts, done) {
|
|
362
|
-
t.
|
|
363
|
-
t.
|
|
364
|
-
t.
|
|
365
|
-
t.
|
|
366
|
-
t.ok(fastify.hasPlugin('pluginB'))
|
|
367
|
+
t.assert.ok(!fastify.hasPlugin('pluginA'))
|
|
368
|
+
t.assert.ok(!fastify.hasPlugin('pluginAA'))
|
|
369
|
+
t.assert.ok(!fastify.hasPlugin('pluginAAA'))
|
|
370
|
+
t.assert.ok(!fastify.hasPlugin('pluginAB'))
|
|
371
|
+
t.assert.ok(fastify.hasPlugin('pluginB'))
|
|
367
372
|
|
|
368
373
|
done()
|
|
369
374
|
})
|
|
@@ -377,26 +382,26 @@ test('hasPlugin returns true when using no encapsulation', async t => {
|
|
|
377
382
|
const fastify = Fastify()
|
|
378
383
|
|
|
379
384
|
fastify.register(fp((fastify, opts, done) => {
|
|
380
|
-
t.
|
|
381
|
-
t.ok(fastify.hasPlugin('plugin-AA'))
|
|
382
|
-
t.
|
|
383
|
-
t.
|
|
384
|
-
t.
|
|
385
|
-
t.
|
|
385
|
+
t.assert.strictEqual(fastify.pluginName, 'fastify -> plugin-AA')
|
|
386
|
+
t.assert.ok(fastify.hasPlugin('plugin-AA'))
|
|
387
|
+
t.assert.ok(!fastify.hasPlugin('plugin-A'))
|
|
388
|
+
t.assert.ok(!fastify.hasPlugin('plugin-AAA'))
|
|
389
|
+
t.assert.ok(!fastify.hasPlugin('plugin-AB'))
|
|
390
|
+
t.assert.ok(!fastify.hasPlugin('plugin-B'))
|
|
386
391
|
|
|
387
392
|
fastify.register(fp((fastify, opts, done) => {
|
|
388
|
-
t.ok(fastify.hasPlugin('plugin-AA'))
|
|
389
|
-
t.ok(fastify.hasPlugin('plugin-A'))
|
|
390
|
-
t.
|
|
391
|
-
t.
|
|
392
|
-
t.
|
|
393
|
+
t.assert.ok(fastify.hasPlugin('plugin-AA'))
|
|
394
|
+
t.assert.ok(fastify.hasPlugin('plugin-A'))
|
|
395
|
+
t.assert.ok(!fastify.hasPlugin('plugin-AAA'))
|
|
396
|
+
t.assert.ok(!fastify.hasPlugin('plugin-AB'))
|
|
397
|
+
t.assert.ok(!fastify.hasPlugin('plugin-B'))
|
|
393
398
|
|
|
394
399
|
fastify.register(fp((fastify, opts, done) => {
|
|
395
|
-
t.ok(fastify.hasPlugin('plugin-AA'))
|
|
396
|
-
t.ok(fastify.hasPlugin('plugin-A'))
|
|
397
|
-
t.ok(fastify.hasPlugin('plugin-AAA'))
|
|
398
|
-
t.
|
|
399
|
-
t.
|
|
400
|
+
t.assert.ok(fastify.hasPlugin('plugin-AA'))
|
|
401
|
+
t.assert.ok(fastify.hasPlugin('plugin-A'))
|
|
402
|
+
t.assert.ok(fastify.hasPlugin('plugin-AAA'))
|
|
403
|
+
t.assert.ok(!fastify.hasPlugin('plugin-AB'))
|
|
404
|
+
t.assert.ok(!fastify.hasPlugin('plugin-B'))
|
|
400
405
|
|
|
401
406
|
done()
|
|
402
407
|
}, { name: 'plugin-AAA' }))
|
|
@@ -405,11 +410,11 @@ test('hasPlugin returns true when using no encapsulation', async t => {
|
|
|
405
410
|
}, { name: 'plugin-A' }))
|
|
406
411
|
|
|
407
412
|
fastify.register(fp((fastify, opts, done) => {
|
|
408
|
-
t.ok(fastify.hasPlugin('plugin-AA'))
|
|
409
|
-
t.ok(fastify.hasPlugin('plugin-A'))
|
|
410
|
-
t.ok(fastify.hasPlugin('plugin-AAA'))
|
|
411
|
-
t.ok(fastify.hasPlugin('plugin-AB'))
|
|
412
|
-
t.
|
|
413
|
+
t.assert.ok(fastify.hasPlugin('plugin-AA'))
|
|
414
|
+
t.assert.ok(fastify.hasPlugin('plugin-A'))
|
|
415
|
+
t.assert.ok(fastify.hasPlugin('plugin-AAA'))
|
|
416
|
+
t.assert.ok(fastify.hasPlugin('plugin-AB'))
|
|
417
|
+
t.assert.ok(!fastify.hasPlugin('plugin-B'))
|
|
413
418
|
|
|
414
419
|
done()
|
|
415
420
|
}, { name: 'plugin-AB' }))
|
|
@@ -418,11 +423,11 @@ test('hasPlugin returns true when using no encapsulation', async t => {
|
|
|
418
423
|
}, { name: 'plugin-AA' }))
|
|
419
424
|
|
|
420
425
|
fastify.register(fp((fastify, opts, done) => {
|
|
421
|
-
t.ok(fastify.hasPlugin('plugin-AA'))
|
|
422
|
-
t.ok(fastify.hasPlugin('plugin-A'))
|
|
423
|
-
t.ok(fastify.hasPlugin('plugin-AAA'))
|
|
424
|
-
t.ok(fastify.hasPlugin('plugin-AB'))
|
|
425
|
-
t.ok(fastify.hasPlugin('plugin-B'))
|
|
426
|
+
t.assert.ok(fastify.hasPlugin('plugin-AA'))
|
|
427
|
+
t.assert.ok(fastify.hasPlugin('plugin-A'))
|
|
428
|
+
t.assert.ok(fastify.hasPlugin('plugin-AAA'))
|
|
429
|
+
t.assert.ok(fastify.hasPlugin('plugin-AB'))
|
|
430
|
+
t.assert.ok(fastify.hasPlugin('plugin-B'))
|
|
426
431
|
|
|
427
432
|
done()
|
|
428
433
|
}, { name: 'plugin-B' }))
|
|
@@ -444,12 +449,12 @@ test('hasPlugin returns true when using encapsulation', async t => {
|
|
|
444
449
|
fastify.register(plugin)
|
|
445
450
|
|
|
446
451
|
fastify.register(async (server) => {
|
|
447
|
-
t.ok(server.hasPlugin(pluginName))
|
|
452
|
+
t.assert.ok(server.hasPlugin(pluginName))
|
|
448
453
|
})
|
|
449
454
|
|
|
450
455
|
fastify.register(async function foo (server) {
|
|
451
456
|
server.register(async function bar (server) {
|
|
452
|
-
t.ok(server.hasPlugin(pluginName))
|
|
457
|
+
t.assert.ok(server.hasPlugin(pluginName))
|
|
453
458
|
})
|
|
454
459
|
})
|
|
455
460
|
|
|
@@ -471,8 +476,8 @@ test('registering anonymous plugin with mixed style should throw', async t => {
|
|
|
471
476
|
await fastify.ready()
|
|
472
477
|
t.fail('should throw')
|
|
473
478
|
} catch (error) {
|
|
474
|
-
t.
|
|
475
|
-
t.
|
|
479
|
+
t.assert.ok(error instanceof FST_ERR_PLUGIN_INVALID_ASYNC_HANDLER)
|
|
480
|
+
t.assert.strictEqual(error.message, 'The anonymousPlugin plugin being registered mixes async and callback styles. Async plugin should not mix async and callback style.')
|
|
476
481
|
}
|
|
477
482
|
})
|
|
478
483
|
|
|
@@ -493,7 +498,7 @@ test('registering named plugin with mixed style should throw', async t => {
|
|
|
493
498
|
await fastify.ready()
|
|
494
499
|
t.fail('should throw')
|
|
495
500
|
} catch (error) {
|
|
496
|
-
t.
|
|
497
|
-
t.
|
|
501
|
+
t.assert.ok(error instanceof FST_ERR_PLUGIN_INVALID_ASYNC_HANDLER)
|
|
502
|
+
t.assert.strictEqual(error.message, 'The error-plugin plugin being registered mixes async and callback styles. Async plugin should not mix async and callback style.')
|
|
498
503
|
}
|
|
499
504
|
})
|
package/test/promises.test.js
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
-
const
|
|
4
|
-
const
|
|
3
|
+
const { test } = require('node:test')
|
|
4
|
+
const assert = require('node:assert')
|
|
5
5
|
const sget = require('simple-get').concat
|
|
6
6
|
const fastify = require('..')()
|
|
7
7
|
|
|
8
|
+
test.after(() => fastify.close())
|
|
9
|
+
|
|
8
10
|
const opts = {
|
|
9
11
|
schema: {
|
|
10
12
|
response: {
|
|
@@ -61,80 +63,84 @@ fastify.get('/return-reply', opts, function (req, reply) {
|
|
|
61
63
|
})
|
|
62
64
|
|
|
63
65
|
fastify.listen({ port: 0 }, err => {
|
|
64
|
-
|
|
65
|
-
t.teardown(() => { fastify.close() })
|
|
66
|
+
assert.ifError(err)
|
|
66
67
|
|
|
67
|
-
test('shorthand - sget return promise es6 get', t => {
|
|
68
|
+
test('shorthand - sget return promise es6 get', (t, done) => {
|
|
68
69
|
t.plan(4)
|
|
69
70
|
sget({
|
|
70
71
|
method: 'GET',
|
|
71
72
|
url: 'http://localhost:' + fastify.server.address().port + '/return'
|
|
72
73
|
}, (err, response, body) => {
|
|
73
|
-
t.
|
|
74
|
-
t.
|
|
75
|
-
t.
|
|
76
|
-
t.
|
|
74
|
+
t.assert.ifError(err)
|
|
75
|
+
t.assert.strictEqual(response.statusCode, 200)
|
|
76
|
+
t.assert.strictEqual(response.headers['content-length'], '' + body.length)
|
|
77
|
+
t.assert.deepStrictEqual(JSON.parse(body), { hello: 'world' })
|
|
78
|
+
done()
|
|
77
79
|
})
|
|
78
80
|
})
|
|
79
81
|
|
|
80
|
-
test('shorthand - sget promise es6 get return error', t => {
|
|
82
|
+
test('shorthand - sget promise es6 get return error', (t, done) => {
|
|
81
83
|
t.plan(2)
|
|
82
84
|
sget({
|
|
83
85
|
method: 'GET',
|
|
84
86
|
url: 'http://localhost:' + fastify.server.address().port + '/return-error'
|
|
85
87
|
}, (err, response, body) => {
|
|
86
|
-
t.
|
|
87
|
-
t.
|
|
88
|
+
t.assert.ifError(err)
|
|
89
|
+
t.assert.strictEqual(response.statusCode, 500)
|
|
90
|
+
done()
|
|
88
91
|
})
|
|
89
92
|
})
|
|
90
93
|
|
|
91
|
-
test('sget promise double send', t => {
|
|
94
|
+
test('sget promise double send', (t, done) => {
|
|
92
95
|
t.plan(3)
|
|
93
|
-
|
|
94
96
|
sget({
|
|
95
97
|
method: 'GET',
|
|
96
98
|
url: 'http://localhost:' + fastify.server.address().port + '/double'
|
|
97
99
|
}, (err, response, body) => {
|
|
98
|
-
t.
|
|
99
|
-
t.
|
|
100
|
-
t.
|
|
100
|
+
t.assert.ifError(err)
|
|
101
|
+
t.assert.strictEqual(response.statusCode, 200)
|
|
102
|
+
t.assert.deepStrictEqual(JSON.parse(body), { hello: '42' })
|
|
103
|
+
done()
|
|
101
104
|
})
|
|
102
105
|
})
|
|
103
106
|
|
|
104
|
-
test('thenable', t => {
|
|
107
|
+
test('thenable', (t, done) => {
|
|
105
108
|
t.plan(4)
|
|
106
109
|
sget({
|
|
107
110
|
method: 'GET',
|
|
108
111
|
url: 'http://localhost:' + fastify.server.address().port + '/thenable'
|
|
109
112
|
}, (err, response, body) => {
|
|
110
|
-
t.
|
|
111
|
-
t.
|
|
112
|
-
t.
|
|
113
|
-
t.
|
|
113
|
+
t.assert.ifError(err)
|
|
114
|
+
t.assert.strictEqual(response.statusCode, 200)
|
|
115
|
+
t.assert.strictEqual(response.headers['content-length'], '' + body.length)
|
|
116
|
+
t.assert.deepStrictEqual(JSON.parse(body), { hello: 'world' })
|
|
117
|
+
done()
|
|
114
118
|
})
|
|
115
119
|
})
|
|
116
120
|
|
|
117
|
-
test('thenable (error)', t => {
|
|
121
|
+
test('thenable (error)', (t, done) => {
|
|
118
122
|
t.plan(2)
|
|
119
123
|
sget({
|
|
120
124
|
method: 'GET',
|
|
121
125
|
url: 'http://localhost:' + fastify.server.address().port + '/thenable-error'
|
|
122
126
|
}, (err, response, body) => {
|
|
123
|
-
t.
|
|
124
|
-
t.
|
|
127
|
+
t.assert.ifError(err)
|
|
128
|
+
t.assert.strictEqual(response.statusCode, 500)
|
|
129
|
+
done()
|
|
125
130
|
})
|
|
126
131
|
})
|
|
127
132
|
|
|
128
|
-
test('return-reply', t => {
|
|
133
|
+
test('return-reply', (t, done) => {
|
|
129
134
|
t.plan(4)
|
|
130
135
|
sget({
|
|
131
136
|
method: 'GET',
|
|
132
137
|
url: 'http://localhost:' + fastify.server.address().port + '/return-reply'
|
|
133
138
|
}, (err, response, body) => {
|
|
134
|
-
t.
|
|
135
|
-
t.
|
|
136
|
-
t.
|
|
137
|
-
t.
|
|
139
|
+
t.assert.ifError(err)
|
|
140
|
+
t.assert.strictEqual(response.statusCode, 200)
|
|
141
|
+
t.assert.strictEqual(response.headers['content-length'], '' + body.length)
|
|
142
|
+
t.assert.deepStrictEqual(JSON.parse(body), { hello: 'world' })
|
|
143
|
+
done()
|
|
138
144
|
})
|
|
139
145
|
})
|
|
140
146
|
})
|