fastify 5.3.0 → 5.3.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.
- package/docs/Guides/Benchmarking.md +1 -1
- package/fastify.js +1 -1
- package/lib/validation.js +11 -1
- package/package.json +1 -1
- package/test/custom-parser.0.test.js +160 -129
- package/test/custom-parser.1.test.js +77 -63
- package/test/custom-querystring-parser.test.js +46 -28
- package/test/logger/instantiation.test.js +89 -96
- package/test/logger/logging.test.js +116 -120
- package/test/logger/options.test.js +97 -99
- package/test/logger/request.test.js +66 -66
- package/test/schema-validation.test.js +136 -0
- package/test/stream.4.test.js +38 -33
- package/test/toolkit.js +31 -0
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
-
const
|
|
4
|
-
const test = t.test
|
|
3
|
+
const { test } = require('node:test')
|
|
5
4
|
const sget = require('simple-get').concat
|
|
6
5
|
const Fastify = require('../fastify')
|
|
7
6
|
const jsonParser = require('fast-json-body')
|
|
8
7
|
const { getServerUrl } = require('./helper')
|
|
8
|
+
const { waitForCb } = require('./toolkit')
|
|
9
9
|
|
|
10
10
|
process.removeAllListeners('warning')
|
|
11
11
|
|
|
12
|
-
test('Should have typeof body object with no custom parser defined, null body and content type = \'text/plain\'', t => {
|
|
12
|
+
test('Should have typeof body object with no custom parser defined, null body and content type = \'text/plain\'', (t, testDone) => {
|
|
13
13
|
t.plan(4)
|
|
14
14
|
const fastify = Fastify()
|
|
15
15
|
|
|
@@ -18,7 +18,7 @@ test('Should have typeof body object with no custom parser defined, null body an
|
|
|
18
18
|
})
|
|
19
19
|
|
|
20
20
|
fastify.listen({ port: 0 }, err => {
|
|
21
|
-
t.
|
|
21
|
+
t.assert.ifError(err)
|
|
22
22
|
|
|
23
23
|
sget({
|
|
24
24
|
method: 'POST',
|
|
@@ -28,15 +28,16 @@ test('Should have typeof body object with no custom parser defined, null body an
|
|
|
28
28
|
'Content-Type': 'text/plain'
|
|
29
29
|
}
|
|
30
30
|
}, (err, response, body) => {
|
|
31
|
-
t.
|
|
32
|
-
t.
|
|
33
|
-
t.
|
|
31
|
+
t.assert.ifError(err)
|
|
32
|
+
t.assert.strictEqual(response.statusCode, 200)
|
|
33
|
+
t.assert.strictEqual(typeof body, 'object')
|
|
34
34
|
fastify.close()
|
|
35
|
+
testDone()
|
|
35
36
|
})
|
|
36
37
|
})
|
|
37
38
|
})
|
|
38
39
|
|
|
39
|
-
test('Should have typeof body object with no custom parser defined, undefined body and content type = \'text/plain\'', t => {
|
|
40
|
+
test('Should have typeof body object with no custom parser defined, undefined body and content type = \'text/plain\'', (t, testDone) => {
|
|
40
41
|
t.plan(4)
|
|
41
42
|
const fastify = Fastify()
|
|
42
43
|
|
|
@@ -45,7 +46,7 @@ test('Should have typeof body object with no custom parser defined, undefined bo
|
|
|
45
46
|
})
|
|
46
47
|
|
|
47
48
|
fastify.listen({ port: 0 }, err => {
|
|
48
|
-
t.
|
|
49
|
+
t.assert.ifError(err)
|
|
49
50
|
|
|
50
51
|
sget({
|
|
51
52
|
method: 'POST',
|
|
@@ -55,15 +56,16 @@ test('Should have typeof body object with no custom parser defined, undefined bo
|
|
|
55
56
|
'Content-Type': 'text/plain'
|
|
56
57
|
}
|
|
57
58
|
}, (err, response, body) => {
|
|
58
|
-
t.
|
|
59
|
-
t.
|
|
60
|
-
t.
|
|
59
|
+
t.assert.ifError(err)
|
|
60
|
+
t.assert.strictEqual(response.statusCode, 200)
|
|
61
|
+
t.assert.strictEqual(typeof body, 'object')
|
|
61
62
|
fastify.close()
|
|
63
|
+
testDone()
|
|
62
64
|
})
|
|
63
65
|
})
|
|
64
66
|
})
|
|
65
67
|
|
|
66
|
-
test('Should get the body as string /1', t => {
|
|
68
|
+
test('Should get the body as string /1', (t, testDone) => {
|
|
67
69
|
t.plan(6)
|
|
68
70
|
const fastify = Fastify()
|
|
69
71
|
|
|
@@ -72,8 +74,8 @@ test('Should get the body as string /1', t => {
|
|
|
72
74
|
})
|
|
73
75
|
|
|
74
76
|
fastify.addContentTypeParser('text/plain', { parseAs: 'string' }, function (req, body, done) {
|
|
75
|
-
t.ok('called')
|
|
76
|
-
t.ok(typeof body === 'string')
|
|
77
|
+
t.assert.ok('called')
|
|
78
|
+
t.assert.ok(typeof body === 'string')
|
|
77
79
|
try {
|
|
78
80
|
const plainText = body
|
|
79
81
|
done(null, plainText)
|
|
@@ -84,7 +86,7 @@ test('Should get the body as string /1', t => {
|
|
|
84
86
|
})
|
|
85
87
|
|
|
86
88
|
fastify.listen({ port: 0 }, err => {
|
|
87
|
-
t.
|
|
89
|
+
t.assert.ifError(err)
|
|
88
90
|
|
|
89
91
|
sget({
|
|
90
92
|
method: 'POST',
|
|
@@ -94,15 +96,16 @@ test('Should get the body as string /1', t => {
|
|
|
94
96
|
'Content-Type': 'text/plain'
|
|
95
97
|
}
|
|
96
98
|
}, (err, response, body) => {
|
|
97
|
-
t.
|
|
98
|
-
t.
|
|
99
|
-
t.
|
|
99
|
+
t.assert.ifError(err)
|
|
100
|
+
t.assert.strictEqual(response.statusCode, 200)
|
|
101
|
+
t.assert.strictEqual(body.toString(), 'hello world')
|
|
100
102
|
fastify.close()
|
|
103
|
+
testDone()
|
|
101
104
|
})
|
|
102
105
|
})
|
|
103
106
|
})
|
|
104
107
|
|
|
105
|
-
test('Should get the body as string /2', t => {
|
|
108
|
+
test('Should get the body as string /2', (t, testDone) => {
|
|
106
109
|
t.plan(6)
|
|
107
110
|
const fastify = Fastify()
|
|
108
111
|
|
|
@@ -111,8 +114,8 @@ test('Should get the body as string /2', t => {
|
|
|
111
114
|
})
|
|
112
115
|
|
|
113
116
|
fastify.addContentTypeParser('text/plain/test', { parseAs: 'string' }, function (req, body, done) {
|
|
114
|
-
t.ok('called')
|
|
115
|
-
t.ok(typeof body === 'string')
|
|
117
|
+
t.assert.ok('called')
|
|
118
|
+
t.assert.ok(typeof body === 'string')
|
|
116
119
|
try {
|
|
117
120
|
const plainText = body
|
|
118
121
|
done(null, plainText)
|
|
@@ -123,7 +126,7 @@ test('Should get the body as string /2', t => {
|
|
|
123
126
|
})
|
|
124
127
|
|
|
125
128
|
fastify.listen({ port: 0 }, err => {
|
|
126
|
-
t.
|
|
129
|
+
t.assert.ifError(err)
|
|
127
130
|
|
|
128
131
|
sget({
|
|
129
132
|
method: 'POST',
|
|
@@ -133,15 +136,16 @@ test('Should get the body as string /2', t => {
|
|
|
133
136
|
'Content-Type': ' text/plain/test '
|
|
134
137
|
}
|
|
135
138
|
}, (err, response, body) => {
|
|
136
|
-
t.
|
|
137
|
-
t.
|
|
138
|
-
t.
|
|
139
|
+
t.assert.ifError(err)
|
|
140
|
+
t.assert.strictEqual(response.statusCode, 200)
|
|
141
|
+
t.assert.strictEqual(body.toString(), 'hello world')
|
|
139
142
|
fastify.close()
|
|
143
|
+
testDone()
|
|
140
144
|
})
|
|
141
145
|
})
|
|
142
146
|
})
|
|
143
147
|
|
|
144
|
-
test('Should get the body as buffer', t => {
|
|
148
|
+
test('Should get the body as buffer', (t, testDone) => {
|
|
145
149
|
t.plan(6)
|
|
146
150
|
const fastify = Fastify()
|
|
147
151
|
|
|
@@ -150,8 +154,8 @@ test('Should get the body as buffer', t => {
|
|
|
150
154
|
})
|
|
151
155
|
|
|
152
156
|
fastify.addContentTypeParser('application/json', { parseAs: 'buffer' }, function (req, body, done) {
|
|
153
|
-
t.ok('called')
|
|
154
|
-
t.ok(body instanceof Buffer)
|
|
157
|
+
t.assert.ok('called')
|
|
158
|
+
t.assert.ok(body instanceof Buffer)
|
|
155
159
|
try {
|
|
156
160
|
const json = JSON.parse(body)
|
|
157
161
|
done(null, json)
|
|
@@ -162,7 +166,7 @@ test('Should get the body as buffer', t => {
|
|
|
162
166
|
})
|
|
163
167
|
|
|
164
168
|
fastify.listen({ port: 0 }, err => {
|
|
165
|
-
t.
|
|
169
|
+
t.assert.ifError(err)
|
|
166
170
|
|
|
167
171
|
sget({
|
|
168
172
|
method: 'POST',
|
|
@@ -172,15 +176,16 @@ test('Should get the body as buffer', t => {
|
|
|
172
176
|
'Content-Type': 'application/json'
|
|
173
177
|
}
|
|
174
178
|
}, (err, response, body) => {
|
|
175
|
-
t.
|
|
176
|
-
t.
|
|
177
|
-
t.
|
|
179
|
+
t.assert.ifError(err)
|
|
180
|
+
t.assert.strictEqual(response.statusCode, 200)
|
|
181
|
+
t.assert.strictEqual(body.toString(), '{"hello":"world"}')
|
|
178
182
|
fastify.close()
|
|
183
|
+
testDone()
|
|
179
184
|
})
|
|
180
185
|
})
|
|
181
186
|
})
|
|
182
187
|
|
|
183
|
-
test('Should get the body as buffer', t => {
|
|
188
|
+
test('Should get the body as buffer', (t, testDone) => {
|
|
184
189
|
t.plan(6)
|
|
185
190
|
const fastify = Fastify()
|
|
186
191
|
|
|
@@ -189,8 +194,8 @@ test('Should get the body as buffer', t => {
|
|
|
189
194
|
})
|
|
190
195
|
|
|
191
196
|
fastify.addContentTypeParser('text/plain', { parseAs: 'buffer' }, function (req, body, done) {
|
|
192
|
-
t.ok('called')
|
|
193
|
-
t.ok(body instanceof Buffer)
|
|
197
|
+
t.assert.ok('called')
|
|
198
|
+
t.assert.ok(body instanceof Buffer)
|
|
194
199
|
try {
|
|
195
200
|
const plainText = body
|
|
196
201
|
done(null, plainText)
|
|
@@ -201,7 +206,7 @@ test('Should get the body as buffer', t => {
|
|
|
201
206
|
})
|
|
202
207
|
|
|
203
208
|
fastify.listen({ port: 0 }, err => {
|
|
204
|
-
t.
|
|
209
|
+
t.assert.ifError(err)
|
|
205
210
|
|
|
206
211
|
sget({
|
|
207
212
|
method: 'POST',
|
|
@@ -211,20 +216,21 @@ test('Should get the body as buffer', t => {
|
|
|
211
216
|
'Content-Type': 'text/plain'
|
|
212
217
|
}
|
|
213
218
|
}, (err, response, body) => {
|
|
214
|
-
t.
|
|
215
|
-
t.
|
|
216
|
-
t.
|
|
219
|
+
t.assert.ifError(err)
|
|
220
|
+
t.assert.strictEqual(response.statusCode, 200)
|
|
221
|
+
t.assert.strictEqual(body.toString(), 'hello world')
|
|
217
222
|
fastify.close()
|
|
223
|
+
testDone()
|
|
218
224
|
})
|
|
219
225
|
})
|
|
220
226
|
})
|
|
221
227
|
|
|
222
|
-
test('Should parse empty bodies as a string', t => {
|
|
228
|
+
test('Should parse empty bodies as a string', (t) => {
|
|
223
229
|
t.plan(9)
|
|
224
230
|
const fastify = Fastify()
|
|
225
231
|
|
|
226
232
|
fastify.addContentTypeParser('text/plain', { parseAs: 'string' }, (req, body, done) => {
|
|
227
|
-
t.
|
|
233
|
+
t.assert.strictEqual(body, '')
|
|
228
234
|
done(null, body)
|
|
229
235
|
})
|
|
230
236
|
|
|
@@ -236,9 +242,11 @@ test('Should parse empty bodies as a string', t => {
|
|
|
236
242
|
}
|
|
237
243
|
})
|
|
238
244
|
|
|
245
|
+
const completion = waitForCb({ steps: 2 })
|
|
246
|
+
|
|
239
247
|
fastify.listen({ port: 0 }, err => {
|
|
240
|
-
t.
|
|
241
|
-
t.
|
|
248
|
+
t.assert.ifError(err)
|
|
249
|
+
t.after(() => { fastify.close() })
|
|
242
250
|
|
|
243
251
|
sget({
|
|
244
252
|
method: 'POST',
|
|
@@ -248,9 +256,10 @@ test('Should parse empty bodies as a string', t => {
|
|
|
248
256
|
'Content-Type': 'text/plain'
|
|
249
257
|
}
|
|
250
258
|
}, (err, response, body) => {
|
|
251
|
-
t.
|
|
252
|
-
t.
|
|
253
|
-
t.
|
|
259
|
+
t.assert.ifError(err)
|
|
260
|
+
t.assert.strictEqual(response.statusCode, 200)
|
|
261
|
+
t.assert.strictEqual(body.toString(), '')
|
|
262
|
+
completion.stepIn()
|
|
254
263
|
})
|
|
255
264
|
|
|
256
265
|
sget({
|
|
@@ -262,14 +271,17 @@ test('Should parse empty bodies as a string', t => {
|
|
|
262
271
|
'Content-Length': '0'
|
|
263
272
|
}
|
|
264
273
|
}, (err, response, body) => {
|
|
265
|
-
t.
|
|
266
|
-
t.
|
|
267
|
-
t.
|
|
274
|
+
t.assert.ifError(err)
|
|
275
|
+
t.assert.strictEqual(response.statusCode, 200)
|
|
276
|
+
t.assert.strictEqual(body.toString(), '')
|
|
277
|
+
completion.stepIn()
|
|
268
278
|
})
|
|
269
279
|
})
|
|
280
|
+
|
|
281
|
+
return completion.patience
|
|
270
282
|
})
|
|
271
283
|
|
|
272
|
-
test('Should parse empty bodies as a buffer', t => {
|
|
284
|
+
test('Should parse empty bodies as a buffer', (t, testDone) => {
|
|
273
285
|
t.plan(6)
|
|
274
286
|
const fastify = Fastify()
|
|
275
287
|
|
|
@@ -278,13 +290,13 @@ test('Should parse empty bodies as a buffer', t => {
|
|
|
278
290
|
})
|
|
279
291
|
|
|
280
292
|
fastify.addContentTypeParser('text/plain', { parseAs: 'buffer' }, function (req, body, done) {
|
|
281
|
-
t.ok(body instanceof Buffer)
|
|
282
|
-
t.
|
|
293
|
+
t.assert.ok(body instanceof Buffer)
|
|
294
|
+
t.assert.strictEqual(body.length, 0)
|
|
283
295
|
done(null, body)
|
|
284
296
|
})
|
|
285
297
|
|
|
286
298
|
fastify.listen({ port: 0 }, err => {
|
|
287
|
-
t.
|
|
299
|
+
t.assert.ifError(err)
|
|
288
300
|
|
|
289
301
|
sget({
|
|
290
302
|
method: 'POST',
|
|
@@ -294,15 +306,16 @@ test('Should parse empty bodies as a buffer', t => {
|
|
|
294
306
|
'Content-Type': 'text/plain'
|
|
295
307
|
}
|
|
296
308
|
}, (err, response, body) => {
|
|
297
|
-
t.
|
|
298
|
-
t.
|
|
299
|
-
t.
|
|
309
|
+
t.assert.ifError(err)
|
|
310
|
+
t.assert.strictEqual(response.statusCode, 200)
|
|
311
|
+
t.assert.strictEqual(body.length, 0)
|
|
300
312
|
fastify.close()
|
|
313
|
+
testDone()
|
|
301
314
|
})
|
|
302
315
|
})
|
|
303
316
|
})
|
|
304
317
|
|
|
305
|
-
test('The charset should not interfere with the content type handling', t => {
|
|
318
|
+
test('The charset should not interfere with the content type handling', (t, testDone) => {
|
|
306
319
|
t.plan(5)
|
|
307
320
|
const fastify = Fastify()
|
|
308
321
|
|
|
@@ -311,14 +324,14 @@ test('The charset should not interfere with the content type handling', t => {
|
|
|
311
324
|
})
|
|
312
325
|
|
|
313
326
|
fastify.addContentTypeParser('application/json', function (req, payload, done) {
|
|
314
|
-
t.ok('called')
|
|
327
|
+
t.assert.ok('called')
|
|
315
328
|
jsonParser(payload, function (err, body) {
|
|
316
329
|
done(err, body)
|
|
317
330
|
})
|
|
318
331
|
})
|
|
319
332
|
|
|
320
333
|
fastify.listen({ port: 0 }, err => {
|
|
321
|
-
t.
|
|
334
|
+
t.assert.ifError(err)
|
|
322
335
|
|
|
323
336
|
sget({
|
|
324
337
|
method: 'POST',
|
|
@@ -328,10 +341,11 @@ test('The charset should not interfere with the content type handling', t => {
|
|
|
328
341
|
'Content-Type': 'application/json; charset=utf-8'
|
|
329
342
|
}
|
|
330
343
|
}, (err, response, body) => {
|
|
331
|
-
t.
|
|
332
|
-
t.
|
|
333
|
-
t.
|
|
344
|
+
t.assert.ifError(err)
|
|
345
|
+
t.assert.strictEqual(response.statusCode, 200)
|
|
346
|
+
t.assert.strictEqual(body.toString(), '{"hello":"world"}')
|
|
334
347
|
fastify.close()
|
|
348
|
+
testDone()
|
|
335
349
|
})
|
|
336
350
|
})
|
|
337
351
|
})
|
|
@@ -1,49 +1,55 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
-
const
|
|
4
|
-
const test = t.test
|
|
3
|
+
const { test } = require('node:test')
|
|
5
4
|
const querystring = require('node:querystring')
|
|
6
5
|
const sget = require('simple-get').concat
|
|
7
6
|
const Fastify = require('..')
|
|
7
|
+
const { waitForCb } = require('./toolkit')
|
|
8
8
|
|
|
9
9
|
test('Custom querystring parser', t => {
|
|
10
10
|
t.plan(9)
|
|
11
11
|
|
|
12
12
|
const fastify = Fastify({
|
|
13
13
|
querystringParser: function (str) {
|
|
14
|
-
t.
|
|
14
|
+
t.assert.strictEqual(str, 'foo=bar&baz=faz')
|
|
15
15
|
return querystring.parse(str)
|
|
16
16
|
}
|
|
17
17
|
})
|
|
18
18
|
|
|
19
19
|
fastify.get('/', (req, reply) => {
|
|
20
|
-
t.
|
|
20
|
+
t.assert.deepEqual(req.query, {
|
|
21
21
|
foo: 'bar',
|
|
22
22
|
baz: 'faz'
|
|
23
23
|
})
|
|
24
24
|
reply.send({ hello: 'world' })
|
|
25
25
|
})
|
|
26
26
|
|
|
27
|
+
const completion = waitForCb({ steps: 2 })
|
|
28
|
+
|
|
27
29
|
fastify.listen({ port: 0 }, (err, address) => {
|
|
28
|
-
t.
|
|
29
|
-
t.
|
|
30
|
+
t.assert.ifError(err)
|
|
31
|
+
t.after(() => fastify.close())
|
|
30
32
|
|
|
31
33
|
sget({
|
|
32
34
|
method: 'GET',
|
|
33
35
|
url: `${address}?foo=bar&baz=faz`
|
|
34
36
|
}, (err, response, body) => {
|
|
35
|
-
t.
|
|
36
|
-
t.
|
|
37
|
+
t.assert.ifError(err)
|
|
38
|
+
t.assert.strictEqual(response.statusCode, 200)
|
|
39
|
+
completion.stepIn()
|
|
37
40
|
})
|
|
38
41
|
|
|
39
42
|
fastify.inject({
|
|
40
43
|
method: 'GET',
|
|
41
44
|
url: `${address}?foo=bar&baz=faz`
|
|
42
45
|
}, (err, response, body) => {
|
|
43
|
-
t.
|
|
44
|
-
t.
|
|
46
|
+
t.assert.ifError(err)
|
|
47
|
+
t.assert.strictEqual(response.statusCode, 200)
|
|
48
|
+
completion.stepIn()
|
|
45
49
|
})
|
|
46
50
|
})
|
|
51
|
+
|
|
52
|
+
return completion.patience
|
|
47
53
|
})
|
|
48
54
|
|
|
49
55
|
test('Custom querystring parser should be called also if there is nothing to parse', t => {
|
|
@@ -51,36 +57,42 @@ test('Custom querystring parser should be called also if there is nothing to par
|
|
|
51
57
|
|
|
52
58
|
const fastify = Fastify({
|
|
53
59
|
querystringParser: function (str) {
|
|
54
|
-
t.
|
|
60
|
+
t.assert.strictEqual(str, '')
|
|
55
61
|
return querystring.parse(str)
|
|
56
62
|
}
|
|
57
63
|
})
|
|
58
64
|
|
|
59
65
|
fastify.get('/', (req, reply) => {
|
|
60
|
-
t.
|
|
66
|
+
t.assert.deepEqual(req.query, {})
|
|
61
67
|
reply.send({ hello: 'world' })
|
|
62
68
|
})
|
|
63
69
|
|
|
70
|
+
const completion = waitForCb({ steps: 2 })
|
|
71
|
+
|
|
64
72
|
fastify.listen({ port: 0 }, (err, address) => {
|
|
65
|
-
t.
|
|
66
|
-
t.
|
|
73
|
+
t.assert.ifError(err)
|
|
74
|
+
t.after(() => fastify.close())
|
|
67
75
|
|
|
68
76
|
sget({
|
|
69
77
|
method: 'GET',
|
|
70
78
|
url: address
|
|
71
79
|
}, (err, response, body) => {
|
|
72
|
-
t.
|
|
73
|
-
t.
|
|
80
|
+
t.assert.ifError(err)
|
|
81
|
+
t.assert.strictEqual(response.statusCode, 200)
|
|
82
|
+
completion.stepIn()
|
|
74
83
|
})
|
|
75
84
|
|
|
76
85
|
fastify.inject({
|
|
77
86
|
method: 'GET',
|
|
78
87
|
url: address
|
|
79
88
|
}, (err, response, body) => {
|
|
80
|
-
t.
|
|
81
|
-
t.
|
|
89
|
+
t.assert.ifError(err)
|
|
90
|
+
t.assert.strictEqual(response.statusCode, 200)
|
|
91
|
+
completion.stepIn()
|
|
82
92
|
})
|
|
83
93
|
})
|
|
94
|
+
|
|
95
|
+
return completion.patience
|
|
84
96
|
})
|
|
85
97
|
|
|
86
98
|
test('Querystring without value', t => {
|
|
@@ -88,36 +100,42 @@ test('Querystring without value', t => {
|
|
|
88
100
|
|
|
89
101
|
const fastify = Fastify({
|
|
90
102
|
querystringParser: function (str) {
|
|
91
|
-
t.
|
|
103
|
+
t.assert.strictEqual(str, 'foo')
|
|
92
104
|
return querystring.parse(str)
|
|
93
105
|
}
|
|
94
106
|
})
|
|
95
107
|
|
|
96
108
|
fastify.get('/', (req, reply) => {
|
|
97
|
-
t.
|
|
109
|
+
t.assert.deepEqual(req.query, { foo: '' })
|
|
98
110
|
reply.send({ hello: 'world' })
|
|
99
111
|
})
|
|
100
112
|
|
|
113
|
+
const completion = waitForCb({ steps: 2 })
|
|
114
|
+
|
|
101
115
|
fastify.listen({ port: 0 }, (err, address) => {
|
|
102
|
-
t.
|
|
103
|
-
t.
|
|
116
|
+
t.assert.ifError(err)
|
|
117
|
+
t.after(() => fastify.close())
|
|
104
118
|
|
|
105
119
|
sget({
|
|
106
120
|
method: 'GET',
|
|
107
121
|
url: `${address}?foo`
|
|
108
122
|
}, (err, response, body) => {
|
|
109
|
-
t.
|
|
110
|
-
t.
|
|
123
|
+
t.assert.ifError(err)
|
|
124
|
+
t.assert.strictEqual(response.statusCode, 200)
|
|
125
|
+
completion.stepIn()
|
|
111
126
|
})
|
|
112
127
|
|
|
113
128
|
fastify.inject({
|
|
114
129
|
method: 'GET',
|
|
115
130
|
url: `${address}?foo`
|
|
116
131
|
}, (err, response, body) => {
|
|
117
|
-
t.
|
|
118
|
-
t.
|
|
132
|
+
t.assert.ifError(err)
|
|
133
|
+
t.assert.strictEqual(response.statusCode, 200)
|
|
134
|
+
completion.stepIn()
|
|
119
135
|
})
|
|
120
136
|
})
|
|
137
|
+
|
|
138
|
+
return completion.patience
|
|
121
139
|
})
|
|
122
140
|
|
|
123
141
|
test('Custom querystring parser should be a function', t => {
|
|
@@ -127,9 +145,9 @@ test('Custom querystring parser should be a function', t => {
|
|
|
127
145
|
Fastify({
|
|
128
146
|
querystringParser: 10
|
|
129
147
|
})
|
|
130
|
-
t.fail('Should throw')
|
|
148
|
+
t.assert.fail('Should throw')
|
|
131
149
|
} catch (err) {
|
|
132
|
-
t.
|
|
150
|
+
t.assert.strictEqual(
|
|
133
151
|
err.message,
|
|
134
152
|
"querystringParser option should be a function, instead got 'number'"
|
|
135
153
|
)
|