Aktueller Stand

This commit is contained in:
2026-01-22 19:05:45 +01:00
parent 85dee61a4d
commit e280e4eadb
1967 changed files with 397327 additions and 74093 deletions

View File

@@ -2,19 +2,18 @@
const stream = require('node:stream')
const t = require('tap')
const t = require('node:test')
const split = require('split2')
const pino = require('pino')
const Fastify = require('../../fastify')
const { partialDeepStrictEqual } = require('../toolkit')
const { on } = stream
t.test('response serialization', (t) => {
t.setTimeout(60000)
t.test('response serialization', { timeout: 60000 }, async (t) => {
t.plan(4)
t.test('Should use serializers from plugin and route', async (t) => {
await t.test('Should use serializers from plugin and route', async (t) => {
const lines = [
{ msg: 'incoming request' },
{ test: 'XHello', test2: 'ZHello' },
@@ -24,11 +23,11 @@ t.test('response serialization', (t) => {
const stream = split(JSON.parse)
const logger = pino({ level: 'info' }, stream)
const loggerInstance = pino({ level: 'info' }, stream)
const fastify = Fastify({
logger
loggerInstance
})
t.teardown(fastify.close.bind(fastify))
t.after(() => fastify.close())
fastify.register(context1, {
logSerializers: { test: value => 'X' + value }
@@ -51,16 +50,16 @@ t.test('response serialization', (t) => {
{
const response = await fastify.inject({ method: 'GET', url: '/' })
const body = await response.json()
t.same(body, { hello: 'world' })
t.assert.deepStrictEqual(body, { hello: 'world' })
}
for await (const [line] of on(stream, 'data')) {
t.match(line, lines.shift())
t.assert.ok(partialDeepStrictEqual(line, lines.shift()))
if (lines.length === 0) break
}
})
t.test('Should use serializers from instance fastify and route', async (t) => {
await t.test('Should use serializers from instance fastify and route', async (t) => {
const lines = [
{ msg: 'incoming request' },
{ test: 'XHello', test2: 'ZHello' },
@@ -70,7 +69,7 @@ t.test('response serialization', (t) => {
const stream = split(JSON.parse)
const logger = pino({
const loggerInstance = pino({
level: 'info',
serializers: {
test: value => 'X' + value,
@@ -78,9 +77,9 @@ t.test('response serialization', (t) => {
}
}, stream)
const fastify = Fastify({
logger
loggerInstance
})
t.teardown(fastify.close.bind(fastify))
t.after(() => fastify.close())
fastify.get('/', {
logSerializers: {
@@ -96,16 +95,16 @@ t.test('response serialization', (t) => {
{
const response = await fastify.inject({ method: 'GET', url: '/' })
const body = await response.json()
t.same(body, { hello: 'world' })
t.assert.deepStrictEqual(body, { hello: 'world' })
}
for await (const [line] of on(stream, 'data')) {
t.match(line, lines.shift())
t.assert.ok(partialDeepStrictEqual(line, lines.shift()))
if (lines.length === 0) break
}
})
t.test('Should use serializers inherit from contexts', async (t) => {
await t.test('Should use serializers inherit from contexts', async (t) => {
const lines = [
{ msg: 'incoming request' },
{ test: 'XHello', test2: 'YHello', test3: 'ZHello' },
@@ -115,15 +114,15 @@ t.test('response serialization', (t) => {
const stream = split(JSON.parse)
const logger = pino({
const loggerInstance = pino({
level: 'info',
serializers: {
test: value => 'X' + value
}
}, stream)
const fastify = Fastify({ logger })
t.teardown(fastify.close.bind(fastify))
const fastify = Fastify({ loggerInstance })
t.after(() => fastify.close())
fastify.register(context1, { logSerializers: { test2: value => 'Y' + value } })
@@ -144,16 +143,16 @@ t.test('response serialization', (t) => {
{
const response = await fastify.inject({ method: 'GET', url: '/' })
const body = await response.json()
t.same(body, { hello: 'world' })
t.assert.deepStrictEqual(body, { hello: 'world' })
}
for await (const [line] of on(stream, 'data')) {
t.match(line, lines.shift())
t.assert.ok(partialDeepStrictEqual(line, lines.shift()))
if (lines.length === 0) break
}
})
t.test('should serialize request and response', async (t) => {
await t.test('should serialize request and response', async (t) => {
const lines = [
{ req: { method: 'GET', url: '/500' }, msg: 'incoming request' },
{ req: { method: 'GET', url: '/500' }, msg: '500 error' },
@@ -163,7 +162,7 @@ t.test('response serialization', (t) => {
const stream = split(JSON.parse)
const fastify = Fastify({ logger: { level: 'info', stream } })
t.teardown(fastify.close.bind(fastify))
t.after(() => fastify.close())
fastify.get('/500', (req, reply) => {
reply.code(500).send(Error('500 error'))
@@ -173,11 +172,11 @@ t.test('response serialization', (t) => {
{
const response = await fastify.inject({ method: 'GET', url: '/500' })
t.equal(response.statusCode, 500)
t.assert.strictEqual(response.statusCode, 500)
}
for await (const [line] of on(stream, 'data')) {
t.match(line, lines.shift())
t.assert.ok(partialDeepStrictEqual(line, lines.shift()))
if (lines.length === 0) break
}
})