fastify 5.2.2 → 5.3.1
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/SPONSORS.md +0 -1
- package/docs/Guides/Ecosystem.md +2 -0
- package/docs/Reference/Decorators.md +199 -0
- package/docs/Reference/Errors.md +2 -0
- package/fastify.js +3 -2
- package/lib/decorate.js +18 -3
- package/lib/errors.js +4 -0
- package/lib/reply.js +17 -2
- package/lib/request.js +28 -2
- package/lib/validation.js +11 -1
- package/package.json +3 -3
- package/test/build/error-serializer.test.js +1 -2
- package/test/custom-parser.0.test.js +160 -129
- package/test/custom-parser.1.test.js +77 -63
- package/test/custom-parser.4.test.js +55 -38
- package/test/custom-querystring-parser.test.js +46 -28
- package/test/decorator.test.js +174 -4
- package/test/fastify-instance.test.js +12 -2
- package/test/hooks.on-listen.test.js +17 -14
- package/test/internals/errors.test.js +14 -1
- package/test/listen.2.test.js +4 -1
- 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 +120 -0
- package/test/server.test.js +175 -0
- package/test/stream.4.test.js +38 -33
- package/test/toolkit.js +31 -0
- package/test/types/instance.test-d.ts +3 -0
- package/test/types/reply.test-d.ts +1 -0
- package/test/types/request.test-d.ts +4 -0
- package/test/types/type-provider.test-d.ts +40 -0
- package/test/upgrade.test.js +3 -6
- package/types/instance.d.ts +2 -0
- package/types/reply.d.ts +1 -0
- package/types/request.d.ts +2 -0
- package/types/type-provider.d.ts +12 -3
|
@@ -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,19 +1,18 @@
|
|
|
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 prefer string content types over RegExp ones', t => {
|
|
12
|
+
test('should prefer string content types over RegExp ones', (t, testDone) => {
|
|
13
13
|
t.plan(7)
|
|
14
14
|
const fastify = Fastify()
|
|
15
|
-
t.
|
|
16
|
-
|
|
15
|
+
t.after(() => { fastify.close() })
|
|
17
16
|
fastify.post('/', (req, reply) => {
|
|
18
17
|
reply.send(req.body)
|
|
19
18
|
})
|
|
@@ -33,7 +32,8 @@ test('should prefer string content types over RegExp ones', t => {
|
|
|
33
32
|
})
|
|
34
33
|
|
|
35
34
|
fastify.listen({ port: 0 }, err => {
|
|
36
|
-
t.
|
|
35
|
+
t.assert.ifError(err)
|
|
36
|
+
const completion = waitForCb({ steps: 2 })
|
|
37
37
|
|
|
38
38
|
sget({
|
|
39
39
|
method: 'POST',
|
|
@@ -43,9 +43,10 @@ test('should prefer string content types over RegExp ones', t => {
|
|
|
43
43
|
'Content-Type': 'application/json'
|
|
44
44
|
}
|
|
45
45
|
}, (err, response, body) => {
|
|
46
|
-
t.
|
|
47
|
-
t.
|
|
48
|
-
t.
|
|
46
|
+
t.assert.ifError(err)
|
|
47
|
+
t.assert.strictEqual(response.statusCode, 200)
|
|
48
|
+
t.assert.equal(body.toString(), JSON.stringify({ k1: 'myValue', k2: 'myValue' }))
|
|
49
|
+
completion.stepIn()
|
|
49
50
|
})
|
|
50
51
|
|
|
51
52
|
sget({
|
|
@@ -56,18 +57,21 @@ test('should prefer string content types over RegExp ones', t => {
|
|
|
56
57
|
'Content-Type': 'application/javascript'
|
|
57
58
|
}
|
|
58
59
|
}, (err, response, body) => {
|
|
59
|
-
t.
|
|
60
|
-
t.
|
|
61
|
-
t.
|
|
60
|
+
t.assert.ifError(err)
|
|
61
|
+
t.assert.strictEqual(response.statusCode, 200)
|
|
62
|
+
t.assert.equal(body.toString(), 'javascript')
|
|
63
|
+
completion.stepIn()
|
|
62
64
|
})
|
|
65
|
+
|
|
66
|
+
completion.patience.then(testDone)
|
|
63
67
|
})
|
|
64
68
|
})
|
|
65
69
|
|
|
66
|
-
test('removeContentTypeParser should support arrays of content types to remove', t => {
|
|
70
|
+
test('removeContentTypeParser should support arrays of content types to remove', (t, testDone) => {
|
|
67
71
|
t.plan(8)
|
|
68
72
|
|
|
69
73
|
const fastify = Fastify()
|
|
70
|
-
t.
|
|
74
|
+
t.after(() => fastify.close())
|
|
71
75
|
|
|
72
76
|
fastify.addContentTypeParser('application/xml', function (req, payload, done) {
|
|
73
77
|
payload.on('data', () => {})
|
|
@@ -90,7 +94,8 @@ test('removeContentTypeParser should support arrays of content types to remove',
|
|
|
90
94
|
})
|
|
91
95
|
|
|
92
96
|
fastify.listen({ port: 0 }, err => {
|
|
93
|
-
t.
|
|
97
|
+
t.assert.ifError(err)
|
|
98
|
+
const completion = waitForCb({ steps: 3 })
|
|
94
99
|
|
|
95
100
|
sget({
|
|
96
101
|
method: 'POST',
|
|
@@ -100,9 +105,10 @@ test('removeContentTypeParser should support arrays of content types to remove',
|
|
|
100
105
|
'Content-Type': 'application/xml'
|
|
101
106
|
}
|
|
102
107
|
}, (err, response, body) => {
|
|
103
|
-
t.
|
|
104
|
-
t.
|
|
105
|
-
t.
|
|
108
|
+
t.assert.ifError(err)
|
|
109
|
+
t.assert.strictEqual(response.statusCode, 200)
|
|
110
|
+
t.assert.equal(body.toString(), 'xml')
|
|
111
|
+
completion.stepIn()
|
|
106
112
|
})
|
|
107
113
|
|
|
108
114
|
sget({
|
|
@@ -113,8 +119,9 @@ test('removeContentTypeParser should support arrays of content types to remove',
|
|
|
113
119
|
'Content-Type': 'image/png'
|
|
114
120
|
}
|
|
115
121
|
}, (err, response, body) => {
|
|
116
|
-
t.
|
|
117
|
-
t.
|
|
122
|
+
t.assert.ifError(err)
|
|
123
|
+
t.assert.strictEqual(response.statusCode, 415)
|
|
124
|
+
completion.stepIn()
|
|
118
125
|
})
|
|
119
126
|
|
|
120
127
|
sget({
|
|
@@ -125,16 +132,19 @@ test('removeContentTypeParser should support arrays of content types to remove',
|
|
|
125
132
|
'Content-Type': 'application/json'
|
|
126
133
|
}
|
|
127
134
|
}, (err, response, body) => {
|
|
128
|
-
t.
|
|
129
|
-
t.
|
|
135
|
+
t.assert.ifError(err)
|
|
136
|
+
t.assert.strictEqual(response.statusCode, 415)
|
|
137
|
+
completion.stepIn()
|
|
130
138
|
})
|
|
139
|
+
completion.patience.then(testDone)
|
|
131
140
|
})
|
|
132
141
|
})
|
|
133
142
|
|
|
134
|
-
test('removeContentTypeParser should support encapsulation', t => {
|
|
143
|
+
test('removeContentTypeParser should support encapsulation', (t, testDone) => {
|
|
135
144
|
t.plan(6)
|
|
136
145
|
|
|
137
146
|
const fastify = Fastify()
|
|
147
|
+
t.after(() => fastify.close())
|
|
138
148
|
|
|
139
149
|
fastify.addContentTypeParser('application/xml', function (req, payload, done) {
|
|
140
150
|
payload.on('data', () => {})
|
|
@@ -158,7 +168,8 @@ test('removeContentTypeParser should support encapsulation', t => {
|
|
|
158
168
|
})
|
|
159
169
|
|
|
160
170
|
fastify.listen({ port: 0 }, err => {
|
|
161
|
-
t.
|
|
171
|
+
t.assert.ifError(err)
|
|
172
|
+
const completion = waitForCb({ steps: 2 })
|
|
162
173
|
|
|
163
174
|
sget({
|
|
164
175
|
method: 'POST',
|
|
@@ -168,8 +179,9 @@ test('removeContentTypeParser should support encapsulation', t => {
|
|
|
168
179
|
'Content-Type': 'application/xml'
|
|
169
180
|
}
|
|
170
181
|
}, (err, response, body) => {
|
|
171
|
-
t.
|
|
172
|
-
t.
|
|
182
|
+
t.assert.ifError(err)
|
|
183
|
+
t.assert.strictEqual(response.statusCode, 415)
|
|
184
|
+
completion.stepIn()
|
|
173
185
|
})
|
|
174
186
|
|
|
175
187
|
sget({
|
|
@@ -180,18 +192,20 @@ test('removeContentTypeParser should support encapsulation', t => {
|
|
|
180
192
|
'Content-Type': 'application/xml'
|
|
181
193
|
}
|
|
182
194
|
}, (err, response, body) => {
|
|
183
|
-
t.
|
|
184
|
-
t.
|
|
185
|
-
t.
|
|
186
|
-
|
|
195
|
+
t.assert.ifError(err)
|
|
196
|
+
t.assert.strictEqual(response.statusCode, 200)
|
|
197
|
+
t.assert.equal(body.toString(), 'xml')
|
|
198
|
+
completion.stepIn()
|
|
187
199
|
})
|
|
200
|
+
completion.patience.then(testDone)
|
|
188
201
|
})
|
|
189
202
|
})
|
|
190
203
|
|
|
191
|
-
test('removeAllContentTypeParsers should support encapsulation', t => {
|
|
204
|
+
test('removeAllContentTypeParsers should support encapsulation', (t, testDone) => {
|
|
192
205
|
t.plan(6)
|
|
193
206
|
|
|
194
207
|
const fastify = Fastify()
|
|
208
|
+
t.after(() => fastify.close())
|
|
195
209
|
|
|
196
210
|
fastify.post('/', (req, reply) => {
|
|
197
211
|
reply.send(req.body)
|
|
@@ -208,7 +222,8 @@ test('removeAllContentTypeParsers should support encapsulation', t => {
|
|
|
208
222
|
})
|
|
209
223
|
|
|
210
224
|
fastify.listen({ port: 0 }, err => {
|
|
211
|
-
t.
|
|
225
|
+
t.assert.ifError(err)
|
|
226
|
+
const completion = waitForCb({ steps: 2 })
|
|
212
227
|
|
|
213
228
|
sget({
|
|
214
229
|
method: 'POST',
|
|
@@ -218,8 +233,9 @@ test('removeAllContentTypeParsers should support encapsulation', t => {
|
|
|
218
233
|
'Content-Type': 'application/json'
|
|
219
234
|
}
|
|
220
235
|
}, (err, response, body) => {
|
|
221
|
-
t.
|
|
222
|
-
t.
|
|
236
|
+
t.assert.ifError(err)
|
|
237
|
+
t.assert.strictEqual(response.statusCode, 415)
|
|
238
|
+
completion.stepIn()
|
|
223
239
|
})
|
|
224
240
|
|
|
225
241
|
sget({
|
|
@@ -230,10 +246,11 @@ test('removeAllContentTypeParsers should support encapsulation', t => {
|
|
|
230
246
|
'Content-Type': 'application/json'
|
|
231
247
|
}
|
|
232
248
|
}, (err, response, body) => {
|
|
233
|
-
t.
|
|
234
|
-
t.
|
|
235
|
-
t.
|
|
236
|
-
|
|
249
|
+
t.assert.ifError(err)
|
|
250
|
+
t.assert.strictEqual(response.statusCode, 200)
|
|
251
|
+
t.assert.equal(JSON.parse(body.toString()).test, 1)
|
|
252
|
+
completion.stepIn()
|
|
237
253
|
})
|
|
254
|
+
completion.patience.then(testDone)
|
|
238
255
|
})
|
|
239
256
|
})
|