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,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
|
)
|
package/test/decorator.test.js
CHANGED
|
@@ -925,9 +925,9 @@ test('Request/reply decorators should be able to access the server instance', as
|
|
|
925
925
|
server.decorateRequest('assert', rootAssert)
|
|
926
926
|
server.decorateReply('assert', rootAssert)
|
|
927
927
|
|
|
928
|
-
server.get('/root-assert', async (req,
|
|
928
|
+
server.get('/root-assert', async (req, res) => {
|
|
929
929
|
req.assert()
|
|
930
|
-
|
|
930
|
+
res.assert()
|
|
931
931
|
return 'done'
|
|
932
932
|
})
|
|
933
933
|
|
|
@@ -936,9 +936,9 @@ test('Request/reply decorators should be able to access the server instance', as
|
|
|
936
936
|
instance.decorateReply('assert', nestedAssert)
|
|
937
937
|
instance.decorate('foo', 'bar')
|
|
938
938
|
|
|
939
|
-
instance.get('/nested-assert', async (req,
|
|
939
|
+
instance.get('/nested-assert', async (req, res) => {
|
|
940
940
|
req.assert()
|
|
941
|
-
|
|
941
|
+
res.assert()
|
|
942
942
|
return 'done'
|
|
943
943
|
})
|
|
944
944
|
})
|
|
@@ -1260,3 +1260,173 @@ test('chain of decorators on Reply', async (t) => {
|
|
|
1260
1260
|
t.equal(response.body, 'tata')
|
|
1261
1261
|
}
|
|
1262
1262
|
})
|
|
1263
|
+
|
|
1264
|
+
test('getDecorator should return the decorator', t => {
|
|
1265
|
+
t.plan(12)
|
|
1266
|
+
const fastify = Fastify()
|
|
1267
|
+
|
|
1268
|
+
fastify.decorate('root', 'from_root')
|
|
1269
|
+
fastify.decorateRequest('root', 'from_root_request')
|
|
1270
|
+
fastify.decorateReply('root', 'from_root_reply')
|
|
1271
|
+
|
|
1272
|
+
t.equal(fastify.getDecorator('root'), 'from_root')
|
|
1273
|
+
fastify.get('/', async (req, res) => {
|
|
1274
|
+
t.equal(req.getDecorator('root'), 'from_root_request')
|
|
1275
|
+
t.equal(res.getDecorator('root'), 'from_root_reply')
|
|
1276
|
+
|
|
1277
|
+
res.send()
|
|
1278
|
+
})
|
|
1279
|
+
|
|
1280
|
+
fastify.register((child) => {
|
|
1281
|
+
child.decorate('child', 'from_child')
|
|
1282
|
+
|
|
1283
|
+
t.equal(child.getDecorator('child'), 'from_child')
|
|
1284
|
+
t.equal(child.getDecorator('root'), 'from_root')
|
|
1285
|
+
|
|
1286
|
+
child.get('/child', async (req, res) => {
|
|
1287
|
+
t.equal(req.getDecorator('root'), 'from_root_request')
|
|
1288
|
+
t.equal(res.getDecorator('root'), 'from_root_reply')
|
|
1289
|
+
|
|
1290
|
+
res.send()
|
|
1291
|
+
})
|
|
1292
|
+
})
|
|
1293
|
+
|
|
1294
|
+
fastify.ready((err) => {
|
|
1295
|
+
t.error(err)
|
|
1296
|
+
fastify.inject({ url: '/' }, (err, res) => {
|
|
1297
|
+
t.error(err)
|
|
1298
|
+
t.pass()
|
|
1299
|
+
})
|
|
1300
|
+
|
|
1301
|
+
fastify.inject({ url: '/child' }, (err, res) => {
|
|
1302
|
+
t.error(err)
|
|
1303
|
+
t.pass()
|
|
1304
|
+
})
|
|
1305
|
+
})
|
|
1306
|
+
})
|
|
1307
|
+
|
|
1308
|
+
test('getDecorator should return function decorators with expected binded context', t => {
|
|
1309
|
+
t.plan(12)
|
|
1310
|
+
const fastify = Fastify()
|
|
1311
|
+
|
|
1312
|
+
fastify.decorate('a', function () {
|
|
1313
|
+
return this
|
|
1314
|
+
})
|
|
1315
|
+
fastify.decorateRequest('b', function () {
|
|
1316
|
+
return this
|
|
1317
|
+
})
|
|
1318
|
+
fastify.decorateReply('c', function () {
|
|
1319
|
+
return this
|
|
1320
|
+
})
|
|
1321
|
+
|
|
1322
|
+
fastify.register((child) => {
|
|
1323
|
+
child.decorate('a', function () {
|
|
1324
|
+
return this
|
|
1325
|
+
})
|
|
1326
|
+
|
|
1327
|
+
t.same(child.getDecorator('a')(), child)
|
|
1328
|
+
child.get('/child', async (req, res) => {
|
|
1329
|
+
t.same(req.getDecorator('b')(), req)
|
|
1330
|
+
t.same(res.getDecorator('c')(), res)
|
|
1331
|
+
|
|
1332
|
+
res.send()
|
|
1333
|
+
})
|
|
1334
|
+
})
|
|
1335
|
+
|
|
1336
|
+
t.same(fastify.getDecorator('a')(), fastify)
|
|
1337
|
+
fastify.get('/', async (req, res) => {
|
|
1338
|
+
t.same(req.getDecorator('b')(), req)
|
|
1339
|
+
t.same(res.getDecorator('c')(), res)
|
|
1340
|
+
|
|
1341
|
+
res.send()
|
|
1342
|
+
})
|
|
1343
|
+
|
|
1344
|
+
fastify.ready((err) => {
|
|
1345
|
+
t.error(err)
|
|
1346
|
+
fastify.inject({ url: '/' }, (err, res) => {
|
|
1347
|
+
t.error(err)
|
|
1348
|
+
t.pass()
|
|
1349
|
+
})
|
|
1350
|
+
|
|
1351
|
+
fastify.inject({ url: '/child' }, (err, res) => {
|
|
1352
|
+
t.error(err)
|
|
1353
|
+
t.pass()
|
|
1354
|
+
})
|
|
1355
|
+
|
|
1356
|
+
t.pass()
|
|
1357
|
+
})
|
|
1358
|
+
})
|
|
1359
|
+
|
|
1360
|
+
test('getDecorator should only return decorators existing in the scope', t => {
|
|
1361
|
+
t.plan(9)
|
|
1362
|
+
|
|
1363
|
+
function assertsThrowOnUndeclaredDecorator (notDecorated, instanceType) {
|
|
1364
|
+
try {
|
|
1365
|
+
notDecorated.getDecorator('foo')
|
|
1366
|
+
t.fail()
|
|
1367
|
+
} catch (e) {
|
|
1368
|
+
t.same(e.code, 'FST_ERR_DEC_UNDECLARED')
|
|
1369
|
+
t.same(e.message, `No decorator 'foo' has been declared on ${instanceType}.`)
|
|
1370
|
+
}
|
|
1371
|
+
}
|
|
1372
|
+
|
|
1373
|
+
const fastify = Fastify()
|
|
1374
|
+
fastify.register(child => {
|
|
1375
|
+
child.decorate('foo', true)
|
|
1376
|
+
child.decorateRequest('foo', true)
|
|
1377
|
+
child.decorateReply('foo', true)
|
|
1378
|
+
})
|
|
1379
|
+
|
|
1380
|
+
fastify.get('/', async (req, res) => {
|
|
1381
|
+
assertsThrowOnUndeclaredDecorator(req, 'request')
|
|
1382
|
+
assertsThrowOnUndeclaredDecorator(res, 'reply')
|
|
1383
|
+
|
|
1384
|
+
return { hello: 'world' }
|
|
1385
|
+
})
|
|
1386
|
+
|
|
1387
|
+
fastify.ready((err) => {
|
|
1388
|
+
t.error(err)
|
|
1389
|
+
|
|
1390
|
+
assertsThrowOnUndeclaredDecorator(fastify, 'instance')
|
|
1391
|
+
fastify.inject({ url: '/' }, (err, res) => {
|
|
1392
|
+
t.error(err)
|
|
1393
|
+
t.pass()
|
|
1394
|
+
})
|
|
1395
|
+
})
|
|
1396
|
+
})
|
|
1397
|
+
|
|
1398
|
+
test('Request.setDecorator should update an existing decorator', t => {
|
|
1399
|
+
t.plan(7)
|
|
1400
|
+
const fastify = Fastify()
|
|
1401
|
+
|
|
1402
|
+
fastify.decorateRequest('session', null)
|
|
1403
|
+
fastify.decorateRequest('utility', null)
|
|
1404
|
+
fastify.addHook('onRequest', async (req, reply) => {
|
|
1405
|
+
req.setDecorator('session', { user: 'Jean' })
|
|
1406
|
+
req.setDecorator('utility', function () {
|
|
1407
|
+
return this
|
|
1408
|
+
})
|
|
1409
|
+
try {
|
|
1410
|
+
req.setDecorator('foo', { user: 'Jean' })
|
|
1411
|
+
t.fail()
|
|
1412
|
+
} catch (e) {
|
|
1413
|
+
t.same(e.code, 'FST_ERR_DEC_UNDECLARED')
|
|
1414
|
+
t.same(e.message, "No decorator 'foo' has been declared on request.")
|
|
1415
|
+
}
|
|
1416
|
+
})
|
|
1417
|
+
|
|
1418
|
+
fastify.get('/', async (req, res) => {
|
|
1419
|
+
t.strictSame(req.getDecorator('session'), { user: 'Jean' })
|
|
1420
|
+
t.same(req.getDecorator('utility')(), req)
|
|
1421
|
+
|
|
1422
|
+
res.send()
|
|
1423
|
+
})
|
|
1424
|
+
|
|
1425
|
+
fastify.ready((err) => {
|
|
1426
|
+
t.error(err)
|
|
1427
|
+
fastify.inject({ url: '/' }, (err, res) => {
|
|
1428
|
+
t.error(err)
|
|
1429
|
+
t.pass()
|
|
1430
|
+
})
|
|
1431
|
+
})
|
|
1432
|
+
})
|
|
@@ -7,9 +7,12 @@ const os = require('node:os')
|
|
|
7
7
|
const {
|
|
8
8
|
kOptions,
|
|
9
9
|
kErrorHandler,
|
|
10
|
-
kChildLoggerFactory
|
|
10
|
+
kChildLoggerFactory,
|
|
11
|
+
kState
|
|
11
12
|
} = require('../lib/symbols')
|
|
12
13
|
|
|
14
|
+
const isIPv6Missing = !Object.values(os.networkInterfaces()).flat().some(({ family }) => family === 'IPv6')
|
|
15
|
+
|
|
13
16
|
test('root fastify instance is an object', t => {
|
|
14
17
|
t.plan(1)
|
|
15
18
|
t.assert.strictEqual(typeof Fastify(), 'object')
|
|
@@ -279,7 +282,7 @@ test('fastify instance should contains listeningOrigin property (unix socket)',
|
|
|
279
282
|
await fastify.close()
|
|
280
283
|
})
|
|
281
284
|
|
|
282
|
-
test('fastify instance should contains listeningOrigin property (IPv6)', async t => {
|
|
285
|
+
test('fastify instance should contains listeningOrigin property (IPv6)', { skip: isIPv6Missing }, async t => {
|
|
283
286
|
t.plan(1)
|
|
284
287
|
const port = 3000
|
|
285
288
|
const host = '::1'
|
|
@@ -288,3 +291,10 @@ test('fastify instance should contains listeningOrigin property (IPv6)', async t
|
|
|
288
291
|
t.assert.deepStrictEqual(fastify.listeningOrigin, `http://[::1]:${port}`)
|
|
289
292
|
await fastify.close()
|
|
290
293
|
})
|
|
294
|
+
|
|
295
|
+
test('fastify instance should ensure ready promise cleanup on ready', async t => {
|
|
296
|
+
t.plan(1)
|
|
297
|
+
const fastify = Fastify()
|
|
298
|
+
await fastify.ready()
|
|
299
|
+
t.assert.strictEqual(fastify[kState].readyPromise, null)
|
|
300
|
+
})
|
|
@@ -6,6 +6,9 @@ const fp = require('fastify-plugin')
|
|
|
6
6
|
const split = require('split2')
|
|
7
7
|
const helper = require('./helper')
|
|
8
8
|
const { kState } = require('../lib/symbols')
|
|
9
|
+
const { networkInterfaces } = require('node:os')
|
|
10
|
+
|
|
11
|
+
const isIPv6Missing = !Object.values(networkInterfaces()).flat().some(({ family }) => family === 'IPv6')
|
|
9
12
|
|
|
10
13
|
let localhost
|
|
11
14
|
before(async function () {
|
|
@@ -405,7 +408,7 @@ test('localhost onListen encapsulation should be called in order and should log
|
|
|
405
408
|
})
|
|
406
409
|
})
|
|
407
410
|
|
|
408
|
-
test('non-localhost onListen should be called in order', t => {
|
|
411
|
+
test('non-localhost onListen should be called in order', { skip: isIPv6Missing }, t => {
|
|
409
412
|
t.plan(2)
|
|
410
413
|
|
|
411
414
|
const fastify = Fastify()
|
|
@@ -428,7 +431,7 @@ test('non-localhost onListen should be called in order', t => {
|
|
|
428
431
|
})
|
|
429
432
|
})
|
|
430
433
|
|
|
431
|
-
test('non-localhost async onListen should be called in order', async t => {
|
|
434
|
+
test('non-localhost async onListen should be called in order', { skip: isIPv6Missing }, async t => {
|
|
432
435
|
t.plan(2)
|
|
433
436
|
const fastify = Fastify()
|
|
434
437
|
t.teardown(fastify.close.bind(fastify))
|
|
@@ -448,7 +451,7 @@ test('non-localhost async onListen should be called in order', async t => {
|
|
|
448
451
|
})
|
|
449
452
|
})
|
|
450
453
|
|
|
451
|
-
test('non-localhost sync onListen should log errors as warnings and continue', t => {
|
|
454
|
+
test('non-localhost sync onListen should log errors as warnings and continue', { skip: isIPv6Missing }, t => {
|
|
452
455
|
t.plan(4)
|
|
453
456
|
const stream = split(JSON.parse)
|
|
454
457
|
const fastify = Fastify({
|
|
@@ -488,7 +491,7 @@ test('non-localhost sync onListen should log errors as warnings and continue', t
|
|
|
488
491
|
})
|
|
489
492
|
})
|
|
490
493
|
|
|
491
|
-
test('non-localhost async onListen should log errors as warnings and continue', async t => {
|
|
494
|
+
test('non-localhost async onListen should log errors as warnings and continue', { skip: isIPv6Missing }, async t => {
|
|
492
495
|
t.plan(6)
|
|
493
496
|
const stream = split(JSON.parse)
|
|
494
497
|
const fastify = Fastify({
|
|
@@ -529,7 +532,7 @@ test('non-localhost async onListen should log errors as warnings and continue',
|
|
|
529
532
|
})
|
|
530
533
|
})
|
|
531
534
|
|
|
532
|
-
test('non-localhost Register onListen hook after a plugin inside a plugin', t => {
|
|
535
|
+
test('non-localhost Register onListen hook after a plugin inside a plugin', { skip: isIPv6Missing }, t => {
|
|
533
536
|
t.plan(3)
|
|
534
537
|
const fastify = Fastify()
|
|
535
538
|
t.teardown(fastify.close.bind(fastify))
|
|
@@ -562,7 +565,7 @@ test('non-localhost Register onListen hook after a plugin inside a plugin', t =>
|
|
|
562
565
|
})
|
|
563
566
|
})
|
|
564
567
|
|
|
565
|
-
test('non-localhost Register onListen hook after a plugin inside a plugin should log errors as warnings and continue', t => {
|
|
568
|
+
test('non-localhost Register onListen hook after a plugin inside a plugin should log errors as warnings and continue', { skip: isIPv6Missing }, t => {
|
|
566
569
|
t.plan(6)
|
|
567
570
|
const stream = split(JSON.parse)
|
|
568
571
|
const fastify = Fastify({
|
|
@@ -608,7 +611,7 @@ test('non-localhost Register onListen hook after a plugin inside a plugin should
|
|
|
608
611
|
})
|
|
609
612
|
})
|
|
610
613
|
|
|
611
|
-
test('non-localhost onListen encapsulation should be called in order', t => {
|
|
614
|
+
test('non-localhost onListen encapsulation should be called in order', { skip: isIPv6Missing }, t => {
|
|
612
615
|
t.plan(6)
|
|
613
616
|
const fastify = Fastify()
|
|
614
617
|
t.teardown(fastify.close.bind(fastify))
|
|
@@ -640,7 +643,7 @@ test('non-localhost onListen encapsulation should be called in order', t => {
|
|
|
640
643
|
})
|
|
641
644
|
})
|
|
642
645
|
|
|
643
|
-
test('non-localhost onListen encapsulation should be called in order and should log errors as warnings and continue', t => {
|
|
646
|
+
test('non-localhost onListen encapsulation should be called in order and should log errors as warnings and continue', { skip: isIPv6Missing }, t => {
|
|
644
647
|
t.plan(7)
|
|
645
648
|
const stream = split(JSON.parse)
|
|
646
649
|
const fastify = Fastify({
|
|
@@ -874,7 +877,7 @@ test('onListen localhost with callback encapsulation should be called in order',
|
|
|
874
877
|
})
|
|
875
878
|
})
|
|
876
879
|
|
|
877
|
-
test('onListen non-localhost should work in order with callback in sync', t => {
|
|
880
|
+
test('onListen non-localhost should work in order with callback in sync', { skip: isIPv6Missing }, t => {
|
|
878
881
|
t.plan(4)
|
|
879
882
|
const fastify = Fastify()
|
|
880
883
|
t.teardown(fastify.close.bind(fastify))
|
|
@@ -896,7 +899,7 @@ test('onListen non-localhost should work in order with callback in sync', t => {
|
|
|
896
899
|
})
|
|
897
900
|
})
|
|
898
901
|
|
|
899
|
-
test('onListen non-localhost should work in order with callback in async', t => {
|
|
902
|
+
test('onListen non-localhost should work in order with callback in async', { skip: isIPv6Missing }, t => {
|
|
900
903
|
t.plan(4)
|
|
901
904
|
const fastify = Fastify()
|
|
902
905
|
t.teardown(fastify.close.bind(fastify))
|
|
@@ -916,7 +919,7 @@ test('onListen non-localhost should work in order with callback in async', t =>
|
|
|
916
919
|
})
|
|
917
920
|
})
|
|
918
921
|
|
|
919
|
-
test('onListen non-localhost sync with callback should log errors as warnings and continue', t => {
|
|
922
|
+
test('onListen non-localhost sync with callback should log errors as warnings and continue', { skip: isIPv6Missing }, t => {
|
|
920
923
|
t.plan(8)
|
|
921
924
|
|
|
922
925
|
const stream = split(JSON.parse)
|
|
@@ -960,7 +963,7 @@ test('onListen non-localhost sync with callback should log errors as warnings an
|
|
|
960
963
|
})
|
|
961
964
|
})
|
|
962
965
|
|
|
963
|
-
test('onListen non-localhost async with callback should log errors as warnings and continue', t => {
|
|
966
|
+
test('onListen non-localhost async with callback should log errors as warnings and continue', { skip: isIPv6Missing }, t => {
|
|
964
967
|
t.plan(8)
|
|
965
968
|
|
|
966
969
|
const stream = split(JSON.parse)
|
|
@@ -1002,7 +1005,7 @@ test('onListen non-localhost async with callback should log errors as warnings a
|
|
|
1002
1005
|
})
|
|
1003
1006
|
})
|
|
1004
1007
|
|
|
1005
|
-
test('Register onListen hook non-localhost with callback after a plugin inside a plugin', t => {
|
|
1008
|
+
test('Register onListen hook non-localhost with callback after a plugin inside a plugin', { skip: isIPv6Missing }, t => {
|
|
1006
1009
|
t.plan(5)
|
|
1007
1010
|
const fastify = Fastify()
|
|
1008
1011
|
t.teardown(fastify.close.bind(fastify))
|
|
@@ -1035,7 +1038,7 @@ test('Register onListen hook non-localhost with callback after a plugin inside a
|
|
|
1035
1038
|
})
|
|
1036
1039
|
})
|
|
1037
1040
|
|
|
1038
|
-
test('onListen non-localhost with callback encapsulation should be called in order', t => {
|
|
1041
|
+
test('onListen non-localhost with callback encapsulation should be called in order', { skip: isIPv6Missing }, t => {
|
|
1039
1042
|
t.plan(8)
|
|
1040
1043
|
const fastify = Fastify()
|
|
1041
1044
|
t.teardown(fastify.close.bind(fastify))
|
|
@@ -5,7 +5,7 @@ const errors = require('../../lib/errors')
|
|
|
5
5
|
const { readFileSync } = require('node:fs')
|
|
6
6
|
const { resolve } = require('node:path')
|
|
7
7
|
|
|
8
|
-
const expectedErrors =
|
|
8
|
+
const expectedErrors = 85
|
|
9
9
|
|
|
10
10
|
test(`should expose ${expectedErrors} errors`, t => {
|
|
11
11
|
t.plan(1)
|
|
@@ -21,6 +21,7 @@ test(`should expose ${expectedErrors} errors`, t => {
|
|
|
21
21
|
|
|
22
22
|
test('ensure name and codes of Errors are identical', t => {
|
|
23
23
|
t.plan(expectedErrors)
|
|
24
|
+
|
|
24
25
|
const exportedKeys = Object.keys(errors)
|
|
25
26
|
for (const key of exportedKeys) {
|
|
26
27
|
if (errors[key].name === 'FastifyError') {
|
|
@@ -249,6 +250,16 @@ test('FST_ERR_DEC_REFERENCE_TYPE', t => {
|
|
|
249
250
|
t.assert.ok(error instanceof Error)
|
|
250
251
|
})
|
|
251
252
|
|
|
253
|
+
test('FST_ERR_DEC_UNDECLARED', t => {
|
|
254
|
+
t.plan(5)
|
|
255
|
+
const error = new errors.FST_ERR_DEC_UNDECLARED('myDecorator', 'request')
|
|
256
|
+
t.assert.strictEqual(error.name, 'FastifyError')
|
|
257
|
+
t.assert.strictEqual(error.code, 'FST_ERR_DEC_UNDECLARED')
|
|
258
|
+
t.assert.strictEqual(error.message, "No decorator 'myDecorator' has been declared on request.")
|
|
259
|
+
t.assert.strictEqual(error.statusCode, 500)
|
|
260
|
+
t.assert.ok(error instanceof Error)
|
|
261
|
+
})
|
|
262
|
+
|
|
252
263
|
test('FST_ERR_HOOK_INVALID_TYPE', t => {
|
|
253
264
|
t.plan(5)
|
|
254
265
|
const error = new errors.FST_ERR_HOOK_INVALID_TYPE()
|
|
@@ -881,6 +892,7 @@ test('FST_ERR_ERROR_HANDLER_NOT_FN', t => {
|
|
|
881
892
|
|
|
882
893
|
test('Ensure that all errors are in Errors.md TOC', t => {
|
|
883
894
|
t.plan(expectedErrors)
|
|
895
|
+
|
|
884
896
|
const errorsMd = readFileSync(resolve(__dirname, '../../docs/Reference/Errors.md'), 'utf8')
|
|
885
897
|
|
|
886
898
|
const exportedKeys = Object.keys(errors)
|
|
@@ -918,6 +930,7 @@ test('Ensure that all errors are in Errors.md documented', t => {
|
|
|
918
930
|
|
|
919
931
|
test('Ensure that non-existing errors are not in Errors.md documented', t => {
|
|
920
932
|
t.plan(expectedErrors)
|
|
933
|
+
|
|
921
934
|
const errorsMd = readFileSync(resolve(__dirname, '../../docs/Reference/Errors.md'), 'utf8')
|
|
922
935
|
|
|
923
936
|
const matchRE = /<a id="[0-9a-zA-Z_]+">([0-9a-zA-Z_]+)<\/a>/g
|
package/test/listen.2.test.js
CHANGED
|
@@ -3,6 +3,9 @@
|
|
|
3
3
|
const { test, before } = require('node:test')
|
|
4
4
|
const Fastify = require('..')
|
|
5
5
|
const helper = require('./helper')
|
|
6
|
+
const { networkInterfaces } = require('node:os')
|
|
7
|
+
|
|
8
|
+
const isIPv6Missing = !Object.values(networkInterfaces()).flat().some(({ family }) => family === 'IPv6')
|
|
6
9
|
|
|
7
10
|
let localhostForURL
|
|
8
11
|
|
|
@@ -59,7 +62,7 @@ test('double listen errors callback with (err, address)', (t, done) => {
|
|
|
59
62
|
})
|
|
60
63
|
})
|
|
61
64
|
|
|
62
|
-
test('nonlocalhost double listen errors callback with (err, address)', (t, done) => {
|
|
65
|
+
test('nonlocalhost double listen errors callback with (err, address)', { skip: isIPv6Missing }, (t, done) => {
|
|
63
66
|
t.plan(4)
|
|
64
67
|
const fastify = Fastify()
|
|
65
68
|
t.after(() => fastify.close())
|