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
|
@@ -2,47 +2,45 @@
|
|
|
2
2
|
|
|
3
3
|
const stream = require('node:stream')
|
|
4
4
|
|
|
5
|
-
const t = require('
|
|
5
|
+
const t = require('node:test')
|
|
6
6
|
const split = require('split2')
|
|
7
7
|
const pino = require('pino')
|
|
8
8
|
|
|
9
9
|
const Fastify = require('../../fastify')
|
|
10
10
|
const { on } = stream
|
|
11
11
|
|
|
12
|
-
t.test('logger options', (t) => {
|
|
13
|
-
t.setTimeout(60000)
|
|
14
|
-
|
|
12
|
+
t.test('logger options', { timeout: 60000 }, async (t) => {
|
|
15
13
|
t.plan(16)
|
|
16
14
|
|
|
17
|
-
t.test('logger can be silenced', (t) => {
|
|
15
|
+
await t.test('logger can be silenced', (t) => {
|
|
18
16
|
t.plan(17)
|
|
19
17
|
const fastify = Fastify({
|
|
20
18
|
logger: false
|
|
21
19
|
})
|
|
22
|
-
t.
|
|
23
|
-
t.ok(fastify.log)
|
|
24
|
-
t.
|
|
25
|
-
t.
|
|
26
|
-
t.
|
|
27
|
-
t.
|
|
28
|
-
t.
|
|
29
|
-
t.
|
|
30
|
-
t.
|
|
31
|
-
t.
|
|
20
|
+
t.after(() => fastify.close())
|
|
21
|
+
t.assert.ok(fastify.log)
|
|
22
|
+
t.assert.deepEqual(typeof fastify.log, 'object')
|
|
23
|
+
t.assert.deepEqual(typeof fastify.log.fatal, 'function')
|
|
24
|
+
t.assert.deepEqual(typeof fastify.log.error, 'function')
|
|
25
|
+
t.assert.deepEqual(typeof fastify.log.warn, 'function')
|
|
26
|
+
t.assert.deepEqual(typeof fastify.log.info, 'function')
|
|
27
|
+
t.assert.deepEqual(typeof fastify.log.debug, 'function')
|
|
28
|
+
t.assert.deepEqual(typeof fastify.log.trace, 'function')
|
|
29
|
+
t.assert.deepEqual(typeof fastify.log.child, 'function')
|
|
32
30
|
|
|
33
31
|
const childLog = fastify.log.child()
|
|
34
32
|
|
|
35
|
-
t.
|
|
36
|
-
t.
|
|
37
|
-
t.
|
|
38
|
-
t.
|
|
39
|
-
t.
|
|
40
|
-
t.
|
|
41
|
-
t.
|
|
42
|
-
t.
|
|
33
|
+
t.assert.deepEqual(typeof childLog, 'object')
|
|
34
|
+
t.assert.deepEqual(typeof childLog.fatal, 'function')
|
|
35
|
+
t.assert.deepEqual(typeof childLog.error, 'function')
|
|
36
|
+
t.assert.deepEqual(typeof childLog.warn, 'function')
|
|
37
|
+
t.assert.deepEqual(typeof childLog.info, 'function')
|
|
38
|
+
t.assert.deepEqual(typeof childLog.debug, 'function')
|
|
39
|
+
t.assert.deepEqual(typeof childLog.trace, 'function')
|
|
40
|
+
t.assert.deepEqual(typeof childLog.child, 'function')
|
|
43
41
|
})
|
|
44
42
|
|
|
45
|
-
t.test('Should set a custom logLevel for a plugin', async (t) => {
|
|
43
|
+
await t.test('Should set a custom logLevel for a plugin', async (t) => {
|
|
46
44
|
const lines = ['incoming request', 'Hello', 'request completed']
|
|
47
45
|
t.plan(lines.length + 2)
|
|
48
46
|
|
|
@@ -53,7 +51,7 @@ t.test('logger options', (t) => {
|
|
|
53
51
|
const fastify = Fastify({
|
|
54
52
|
loggerInstance
|
|
55
53
|
})
|
|
56
|
-
t.
|
|
54
|
+
t.after(() => fastify.close())
|
|
57
55
|
|
|
58
56
|
fastify.get('/', (req, reply) => {
|
|
59
57
|
req.log.info('Not Exist') // we should not see this log
|
|
@@ -73,22 +71,22 @@ t.test('logger options', (t) => {
|
|
|
73
71
|
{
|
|
74
72
|
const response = await fastify.inject({ method: 'GET', url: '/' })
|
|
75
73
|
const body = await response.json()
|
|
76
|
-
t.
|
|
74
|
+
t.assert.deepEqual(body.hello, 'world')
|
|
77
75
|
}
|
|
78
76
|
|
|
79
77
|
{
|
|
80
78
|
const response = await fastify.inject({ method: 'GET', url: '/plugin' })
|
|
81
79
|
const body = await response.json()
|
|
82
|
-
t.
|
|
80
|
+
t.assert.deepEqual(body.hello, 'world')
|
|
83
81
|
}
|
|
84
82
|
|
|
85
83
|
for await (const [line] of on(stream, 'data')) {
|
|
86
|
-
t.
|
|
84
|
+
t.assert.deepEqual(line.msg, lines.shift())
|
|
87
85
|
if (lines.length === 0) break
|
|
88
86
|
}
|
|
89
87
|
})
|
|
90
88
|
|
|
91
|
-
t.test('Should set a custom logSerializers for a plugin', async (t) => {
|
|
89
|
+
await t.test('Should set a custom logSerializers for a plugin', async (t) => {
|
|
92
90
|
const lines = ['incoming request', 'XHello', 'request completed']
|
|
93
91
|
t.plan(lines.length + 1)
|
|
94
92
|
|
|
@@ -99,7 +97,7 @@ t.test('logger options', (t) => {
|
|
|
99
97
|
const fastify = Fastify({
|
|
100
98
|
loggerInstance
|
|
101
99
|
})
|
|
102
|
-
t.
|
|
100
|
+
t.after(() => fastify.close())
|
|
103
101
|
|
|
104
102
|
fastify.register(function (instance, opts, done) {
|
|
105
103
|
instance.get('/plugin', (req, reply) => {
|
|
@@ -114,17 +112,17 @@ t.test('logger options', (t) => {
|
|
|
114
112
|
{
|
|
115
113
|
const response = await fastify.inject({ method: 'GET', url: '/plugin' })
|
|
116
114
|
const body = await response.json()
|
|
117
|
-
t.
|
|
115
|
+
t.assert.deepEqual(body.hello, 'world')
|
|
118
116
|
}
|
|
119
117
|
|
|
120
118
|
for await (const [line] of on(stream, 'data')) {
|
|
121
119
|
// either test or msg
|
|
122
|
-
t.
|
|
120
|
+
t.assert.deepEqual(line.test || line.msg, lines.shift())
|
|
123
121
|
if (lines.length === 0) break
|
|
124
122
|
}
|
|
125
123
|
})
|
|
126
124
|
|
|
127
|
-
t.test('Should set a custom logLevel for every plugin', async (t) => {
|
|
125
|
+
await t.test('Should set a custom logLevel for every plugin', async (t) => {
|
|
128
126
|
const lines = ['incoming request', 'info', 'request completed', 'incoming request', 'debug', 'request completed']
|
|
129
127
|
t.plan(lines.length * 2 + 3)
|
|
130
128
|
|
|
@@ -135,7 +133,7 @@ t.test('logger options', (t) => {
|
|
|
135
133
|
const fastify = Fastify({
|
|
136
134
|
loggerInstance
|
|
137
135
|
})
|
|
138
|
-
t.
|
|
136
|
+
t.after(() => fastify.close())
|
|
139
137
|
|
|
140
138
|
fastify.get('/', (req, reply) => {
|
|
141
139
|
req.log.warn('Hello') // we should not see this log
|
|
@@ -165,29 +163,29 @@ t.test('logger options', (t) => {
|
|
|
165
163
|
{
|
|
166
164
|
const response = await fastify.inject({ method: 'GET', url: '/' })
|
|
167
165
|
const body = await response.json()
|
|
168
|
-
t.
|
|
166
|
+
t.assert.deepEqual(body, { hello: 'world' })
|
|
169
167
|
}
|
|
170
168
|
|
|
171
169
|
{
|
|
172
170
|
const response = await fastify.inject({ method: 'GET', url: '/info' })
|
|
173
171
|
const body = await response.json()
|
|
174
|
-
t.
|
|
172
|
+
t.assert.deepEqual(body, { hello: 'world' })
|
|
175
173
|
}
|
|
176
174
|
|
|
177
175
|
{
|
|
178
176
|
const response = await fastify.inject({ method: 'GET', url: '/debug' })
|
|
179
177
|
const body = await response.json()
|
|
180
|
-
t.
|
|
178
|
+
t.assert.deepEqual(body, { hello: 'world' })
|
|
181
179
|
}
|
|
182
180
|
|
|
183
181
|
for await (const [line] of on(stream, 'data')) {
|
|
184
|
-
t.ok(line.level === 30 || line.level === 20)
|
|
185
|
-
t.
|
|
182
|
+
t.assert.ok(line.level === 30 || line.level === 20)
|
|
183
|
+
t.assert.deepEqual(line.msg, lines.shift())
|
|
186
184
|
if (lines.length === 0) break
|
|
187
185
|
}
|
|
188
186
|
})
|
|
189
187
|
|
|
190
|
-
t.test('Should set a custom logSerializers for every plugin', async (t) => {
|
|
188
|
+
await t.test('Should set a custom logSerializers for every plugin', async (t) => {
|
|
191
189
|
const lines = ['incoming request', 'Hello', 'request completed', 'incoming request', 'XHello', 'request completed', 'incoming request', 'ZHello', 'request completed']
|
|
192
190
|
t.plan(lines.length + 3)
|
|
193
191
|
|
|
@@ -197,7 +195,7 @@ t.test('logger options', (t) => {
|
|
|
197
195
|
const fastify = Fastify({
|
|
198
196
|
loggerInstance
|
|
199
197
|
})
|
|
200
|
-
t.
|
|
198
|
+
t.after(() => fastify.close())
|
|
201
199
|
|
|
202
200
|
fastify.get('/', (req, reply) => {
|
|
203
201
|
req.log.warn({ test: 'Hello' })
|
|
@@ -225,28 +223,28 @@ t.test('logger options', (t) => {
|
|
|
225
223
|
{
|
|
226
224
|
const response = await fastify.inject({ method: 'GET', url: '/' })
|
|
227
225
|
const body = await response.json()
|
|
228
|
-
t.
|
|
226
|
+
t.assert.deepEqual(body, { hello: 'world' })
|
|
229
227
|
}
|
|
230
228
|
|
|
231
229
|
{
|
|
232
230
|
const response = await fastify.inject({ method: 'GET', url: '/test1' })
|
|
233
231
|
const body = await response.json()
|
|
234
|
-
t.
|
|
232
|
+
t.assert.deepEqual(body, { hello: 'world' })
|
|
235
233
|
}
|
|
236
234
|
|
|
237
235
|
{
|
|
238
236
|
const response = await fastify.inject({ method: 'GET', url: '/test2' })
|
|
239
237
|
const body = await response.json()
|
|
240
|
-
t.
|
|
238
|
+
t.assert.deepEqual(body, { hello: 'world' })
|
|
241
239
|
}
|
|
242
240
|
|
|
243
241
|
for await (const [line] of on(stream, 'data')) {
|
|
244
|
-
t.
|
|
242
|
+
t.assert.deepEqual(line.test || line.msg, lines.shift())
|
|
245
243
|
if (lines.length === 0) break
|
|
246
244
|
}
|
|
247
245
|
})
|
|
248
246
|
|
|
249
|
-
t.test('Should override serializers from route', async (t) => {
|
|
247
|
+
await t.test('Should override serializers from route', async (t) => {
|
|
250
248
|
const lines = ['incoming request', 'ZHello', 'request completed']
|
|
251
249
|
t.plan(lines.length + 1)
|
|
252
250
|
|
|
@@ -256,7 +254,7 @@ t.test('logger options', (t) => {
|
|
|
256
254
|
const fastify = Fastify({
|
|
257
255
|
loggerInstance
|
|
258
256
|
})
|
|
259
|
-
t.
|
|
257
|
+
t.after(() => fastify.close())
|
|
260
258
|
|
|
261
259
|
fastify.register(function (instance, opts, done) {
|
|
262
260
|
instance.get('/', {
|
|
@@ -275,16 +273,16 @@ t.test('logger options', (t) => {
|
|
|
275
273
|
{
|
|
276
274
|
const response = await fastify.inject({ method: 'GET', url: '/' })
|
|
277
275
|
const body = await response.json()
|
|
278
|
-
t.
|
|
276
|
+
t.assert.deepEqual(body, { hello: 'world' })
|
|
279
277
|
}
|
|
280
278
|
|
|
281
279
|
for await (const [line] of on(stream, 'data')) {
|
|
282
|
-
t.
|
|
280
|
+
t.assert.deepEqual(line.test || line.msg, lines.shift())
|
|
283
281
|
if (lines.length === 0) break
|
|
284
282
|
}
|
|
285
283
|
})
|
|
286
284
|
|
|
287
|
-
t.test('Should override serializers from plugin', async (t) => {
|
|
285
|
+
await t.test('Should override serializers from plugin', async (t) => {
|
|
288
286
|
const lines = ['incoming request', 'ZHello', 'request completed']
|
|
289
287
|
t.plan(lines.length + 1)
|
|
290
288
|
|
|
@@ -294,7 +292,7 @@ t.test('logger options', (t) => {
|
|
|
294
292
|
const fastify = Fastify({
|
|
295
293
|
loggerInstance
|
|
296
294
|
})
|
|
297
|
-
t.
|
|
295
|
+
t.after(() => fastify.close())
|
|
298
296
|
|
|
299
297
|
fastify.register(function (instance, opts, done) {
|
|
300
298
|
instance.register(context1, {
|
|
@@ -318,16 +316,16 @@ t.test('logger options', (t) => {
|
|
|
318
316
|
{
|
|
319
317
|
const response = await fastify.inject({ method: 'GET', url: '/' })
|
|
320
318
|
const body = await response.json()
|
|
321
|
-
t.
|
|
319
|
+
t.assert.deepEqual(body, { hello: 'world' })
|
|
322
320
|
}
|
|
323
321
|
|
|
324
322
|
for await (const [line] of on(stream, 'data')) {
|
|
325
|
-
t.
|
|
323
|
+
t.assert.deepEqual(line.test || line.msg, lines.shift())
|
|
326
324
|
if (lines.length === 0) break
|
|
327
325
|
}
|
|
328
326
|
})
|
|
329
327
|
|
|
330
|
-
t.test('Should increase the log level for a specific plugin', async (t) => {
|
|
328
|
+
await t.test('Should increase the log level for a specific plugin', async (t) => {
|
|
331
329
|
const lines = ['Hello']
|
|
332
330
|
t.plan(lines.length * 2 + 1)
|
|
333
331
|
|
|
@@ -338,7 +336,7 @@ t.test('logger options', (t) => {
|
|
|
338
336
|
const fastify = Fastify({
|
|
339
337
|
loggerInstance
|
|
340
338
|
})
|
|
341
|
-
t.
|
|
339
|
+
t.after(() => fastify.close())
|
|
342
340
|
|
|
343
341
|
fastify.register(function (instance, opts, done) {
|
|
344
342
|
instance.get('/', (req, reply) => {
|
|
@@ -353,17 +351,17 @@ t.test('logger options', (t) => {
|
|
|
353
351
|
{
|
|
354
352
|
const response = await fastify.inject({ method: 'GET', url: '/' })
|
|
355
353
|
const body = await response.json()
|
|
356
|
-
t.
|
|
354
|
+
t.assert.deepEqual(body, { hello: 'world' })
|
|
357
355
|
}
|
|
358
356
|
|
|
359
357
|
for await (const [line] of on(stream, 'data')) {
|
|
360
|
-
t.
|
|
361
|
-
t.
|
|
358
|
+
t.assert.deepEqual(line.level, 50)
|
|
359
|
+
t.assert.deepEqual(line.msg, lines.shift())
|
|
362
360
|
if (lines.length === 0) break
|
|
363
361
|
}
|
|
364
362
|
})
|
|
365
363
|
|
|
366
|
-
t.test('Should set the log level for the customized 404 handler', async (t) => {
|
|
364
|
+
await t.test('Should set the log level for the customized 404 handler', async (t) => {
|
|
367
365
|
const lines = ['Hello']
|
|
368
366
|
t.plan(lines.length * 2 + 1)
|
|
369
367
|
|
|
@@ -374,7 +372,7 @@ t.test('logger options', (t) => {
|
|
|
374
372
|
const fastify = Fastify({
|
|
375
373
|
loggerInstance
|
|
376
374
|
})
|
|
377
|
-
t.
|
|
375
|
+
t.after(() => fastify.close())
|
|
378
376
|
|
|
379
377
|
fastify.register(function (instance, opts, done) {
|
|
380
378
|
instance.setNotFoundHandler(function (req, reply) {
|
|
@@ -388,17 +386,17 @@ t.test('logger options', (t) => {
|
|
|
388
386
|
|
|
389
387
|
{
|
|
390
388
|
const response = await fastify.inject({ method: 'GET', url: '/' })
|
|
391
|
-
t.
|
|
389
|
+
t.assert.deepEqual(response.statusCode, 404)
|
|
392
390
|
}
|
|
393
391
|
|
|
394
392
|
for await (const [line] of on(stream, 'data')) {
|
|
395
|
-
t.
|
|
396
|
-
t.
|
|
393
|
+
t.assert.deepEqual(line.level, 50)
|
|
394
|
+
t.assert.deepEqual(line.msg, lines.shift())
|
|
397
395
|
if (lines.length === 0) break
|
|
398
396
|
}
|
|
399
397
|
})
|
|
400
398
|
|
|
401
|
-
t.test('Should set the log level for the customized 500 handler', async (t) => {
|
|
399
|
+
await t.test('Should set the log level for the customized 500 handler', async (t) => {
|
|
402
400
|
const lines = ['Hello']
|
|
403
401
|
t.plan(lines.length * 2 + 1)
|
|
404
402
|
|
|
@@ -409,7 +407,7 @@ t.test('logger options', (t) => {
|
|
|
409
407
|
const fastify = Fastify({
|
|
410
408
|
loggerInstance
|
|
411
409
|
})
|
|
412
|
-
t.
|
|
410
|
+
t.after(() => fastify.close())
|
|
413
411
|
|
|
414
412
|
fastify.register(function (instance, opts, done) {
|
|
415
413
|
instance.get('/', (req, reply) => {
|
|
@@ -428,17 +426,17 @@ t.test('logger options', (t) => {
|
|
|
428
426
|
|
|
429
427
|
{
|
|
430
428
|
const response = await fastify.inject({ method: 'GET', url: '/' })
|
|
431
|
-
t.
|
|
429
|
+
t.assert.deepEqual(response.statusCode, 500)
|
|
432
430
|
}
|
|
433
431
|
|
|
434
432
|
for await (const [line] of on(stream, 'data')) {
|
|
435
|
-
t.
|
|
436
|
-
t.
|
|
433
|
+
t.assert.deepEqual(line.level, 60)
|
|
434
|
+
t.assert.deepEqual(line.msg, lines.shift())
|
|
437
435
|
if (lines.length === 0) break
|
|
438
436
|
}
|
|
439
437
|
})
|
|
440
438
|
|
|
441
|
-
t.test('Should set a custom log level for a specific route', async (t) => {
|
|
439
|
+
await t.test('Should set a custom log level for a specific route', async (t) => {
|
|
442
440
|
const lines = ['incoming request', 'Hello', 'request completed']
|
|
443
441
|
t.plan(lines.length + 2)
|
|
444
442
|
|
|
@@ -449,7 +447,7 @@ t.test('logger options', (t) => {
|
|
|
449
447
|
const fastify = Fastify({
|
|
450
448
|
loggerInstance
|
|
451
449
|
})
|
|
452
|
-
t.
|
|
450
|
+
t.after(() => fastify.close())
|
|
453
451
|
|
|
454
452
|
fastify.get('/log', { logLevel: 'info' }, (req, reply) => {
|
|
455
453
|
req.log.info('Hello')
|
|
@@ -466,39 +464,39 @@ t.test('logger options', (t) => {
|
|
|
466
464
|
{
|
|
467
465
|
const response = await fastify.inject({ method: 'GET', url: '/log' })
|
|
468
466
|
const body = await response.json()
|
|
469
|
-
t.
|
|
467
|
+
t.assert.deepEqual(body, { hello: 'world' })
|
|
470
468
|
}
|
|
471
469
|
|
|
472
470
|
{
|
|
473
471
|
const response = await fastify.inject({ method: 'GET', url: '/no-log' })
|
|
474
472
|
const body = await response.json()
|
|
475
|
-
t.
|
|
473
|
+
t.assert.deepEqual(body, { hello: 'world' })
|
|
476
474
|
}
|
|
477
475
|
|
|
478
476
|
for await (const [line] of on(stream, 'data')) {
|
|
479
|
-
t.
|
|
477
|
+
t.assert.deepEqual(line.msg, lines.shift())
|
|
480
478
|
if (lines.length === 0) break
|
|
481
479
|
}
|
|
482
480
|
})
|
|
483
481
|
|
|
484
|
-
t.test('should pass when using unWritable props in the logger option', (t) => {
|
|
482
|
+
await t.test('should pass when using unWritable props in the logger option', (t) => {
|
|
485
483
|
t.plan(8)
|
|
486
484
|
const fastify = Fastify({
|
|
487
485
|
logger: Object.defineProperty({}, 'level', { value: 'info' })
|
|
488
486
|
})
|
|
489
|
-
t.
|
|
490
|
-
|
|
491
|
-
t.
|
|
492
|
-
t.
|
|
493
|
-
t.
|
|
494
|
-
t.
|
|
495
|
-
t.
|
|
496
|
-
t.
|
|
497
|
-
t.
|
|
498
|
-
t.
|
|
487
|
+
t.after(() => fastify.close())
|
|
488
|
+
|
|
489
|
+
t.assert.deepEqual(typeof fastify.log, 'object')
|
|
490
|
+
t.assert.deepEqual(typeof fastify.log.fatal, 'function')
|
|
491
|
+
t.assert.deepEqual(typeof fastify.log.error, 'function')
|
|
492
|
+
t.assert.deepEqual(typeof fastify.log.warn, 'function')
|
|
493
|
+
t.assert.deepEqual(typeof fastify.log.info, 'function')
|
|
494
|
+
t.assert.deepEqual(typeof fastify.log.debug, 'function')
|
|
495
|
+
t.assert.deepEqual(typeof fastify.log.trace, 'function')
|
|
496
|
+
t.assert.deepEqual(typeof fastify.log.child, 'function')
|
|
499
497
|
})
|
|
500
498
|
|
|
501
|
-
t.test('Should throw an error if logger instance is passed to `logger`', async (t) => {
|
|
499
|
+
await t.test('Should throw an error if logger instance is passed to `logger`', async (t) => {
|
|
502
500
|
t.plan(2)
|
|
503
501
|
const stream = split(JSON.parse)
|
|
504
502
|
|
|
@@ -507,22 +505,22 @@ t.test('logger options', (t) => {
|
|
|
507
505
|
try {
|
|
508
506
|
Fastify({ logger })
|
|
509
507
|
} catch (err) {
|
|
510
|
-
t.ok(err)
|
|
511
|
-
t.
|
|
508
|
+
t.assert.ok(err)
|
|
509
|
+
t.assert.deepEqual(err.code, 'FST_ERR_LOG_INVALID_LOGGER_CONFIG')
|
|
512
510
|
}
|
|
513
511
|
})
|
|
514
512
|
|
|
515
|
-
t.test('Should throw an error if options are passed to `loggerInstance`', async (t) => {
|
|
513
|
+
await t.test('Should throw an error if options are passed to `loggerInstance`', async (t) => {
|
|
516
514
|
t.plan(2)
|
|
517
515
|
try {
|
|
518
516
|
Fastify({ loggerInstance: { level: 'log' } })
|
|
519
517
|
} catch (err) {
|
|
520
|
-
t.ok(err)
|
|
521
|
-
t.
|
|
518
|
+
t.assert.ok(err)
|
|
519
|
+
t.assert.strictEqual(err.code, 'FST_ERR_LOG_INVALID_LOGGER_INSTANCE')
|
|
522
520
|
}
|
|
523
521
|
})
|
|
524
522
|
|
|
525
|
-
t.test('If both `loggerInstance` and `logger` are provided, an error should be thrown', async (t) => {
|
|
523
|
+
await t.test('If both `loggerInstance` and `logger` are provided, an error should be thrown', async (t) => {
|
|
526
524
|
t.plan(2)
|
|
527
525
|
const loggerInstanceStream = split(JSON.parse)
|
|
528
526
|
const loggerInstance = pino({ level: 'error' }, loggerInstanceStream)
|
|
@@ -536,12 +534,12 @@ t.test('logger options', (t) => {
|
|
|
536
534
|
loggerInstance
|
|
537
535
|
})
|
|
538
536
|
} catch (err) {
|
|
539
|
-
t.ok(err)
|
|
540
|
-
t.
|
|
537
|
+
t.assert.ok(err)
|
|
538
|
+
t.assert.deepEqual(err.code, 'FST_ERR_LOG_LOGGER_AND_LOGGER_INSTANCE_PROVIDED')
|
|
541
539
|
}
|
|
542
540
|
})
|
|
543
541
|
|
|
544
|
-
t.test('`logger` should take pino configuration and create a pino logger', async (t) => {
|
|
542
|
+
await t.test('`logger` should take pino configuration and create a pino logger', async (t) => {
|
|
545
543
|
const lines = ['hello', 'world']
|
|
546
544
|
t.plan(2 * lines.length + 2)
|
|
547
545
|
const loggerStream = split(JSON.parse)
|
|
@@ -551,7 +549,7 @@ t.test('logger options', (t) => {
|
|
|
551
549
|
level: 'error'
|
|
552
550
|
}
|
|
553
551
|
})
|
|
554
|
-
t.
|
|
552
|
+
t.after(() => fastify.close())
|
|
555
553
|
fastify.get('/hello', (req, reply) => {
|
|
556
554
|
req.log.error('hello')
|
|
557
555
|
reply.code(404).send()
|
|
@@ -565,16 +563,16 @@ t.test('logger options', (t) => {
|
|
|
565
563
|
await fastify.ready()
|
|
566
564
|
{
|
|
567
565
|
const response = await fastify.inject({ method: 'GET', url: '/hello' })
|
|
568
|
-
t.
|
|
566
|
+
t.assert.deepEqual(response.statusCode, 404)
|
|
569
567
|
}
|
|
570
568
|
{
|
|
571
569
|
const response = await fastify.inject({ method: 'GET', url: '/world' })
|
|
572
|
-
t.
|
|
570
|
+
t.assert.deepEqual(response.statusCode, 201)
|
|
573
571
|
}
|
|
574
572
|
|
|
575
573
|
for await (const [line] of on(loggerStream, 'data')) {
|
|
576
|
-
t.
|
|
577
|
-
t.
|
|
574
|
+
t.assert.deepEqual(line.level, 50)
|
|
575
|
+
t.assert.deepEqual(line.msg, lines.shift())
|
|
578
576
|
if (lines.length === 0) break
|
|
579
577
|
}
|
|
580
578
|
})
|