stream.4.test.js — fastify Source File
Architecture documentation for stream.4.test.js, a javascript file in the fastify codebase.
Entity Profile
Source Code
'use strict'
const { test } = require('node:test')
const errors = require('http-errors')
const JSONStream = require('JSONStream')
const Readable = require('node:stream').Readable
const split = require('split2')
const Fastify = require('..')
const { kDisableRequestLogging } = require('../lib/symbols.js')
test('Destroying streams prematurely should call abort method', (t, testDone) => {
t.plan(7)
let fastify = null
const logStream = split(JSON.parse)
try {
fastify = Fastify({
logger: {
stream: logStream,
level: 'info'
}
})
} catch (e) {
t.assert.fail()
}
const stream = require('node:stream')
const http = require('node:http')
// Test that "premature close" errors are logged with level warn
logStream.on('data', line => {
if (line.res) {
t.assert.strictEqual(line.msg, 'stream closed prematurely')
t.assert.strictEqual(line.level, 30)
testDone()
}
})
fastify.get('/', function (request, reply) {
t.assert.ok('Received request')
let sent = false
const reallyLongStream = new stream.Readable({
read: function () {
if (!sent) {
this.push(Buffer.from('hello\n'))
}
sent = true
}
})
reallyLongStream.destroy = undefined
reallyLongStream.close = undefined
reallyLongStream.abort = () => t.assert.ok('called')
reply.send(reallyLongStream)
})
fastify.listen({ port: 0 }, err => {
t.assert.ifError(err)
t.after(() => { fastify.close() })
const port = fastify.server.address().port
// ... (117 more lines)
Source
Frequently Asked Questions
What does stream.4.test.js do?
stream.4.test.js is a source file in the fastify codebase, written in javascript.
Where is stream.4.test.js in the architecture?
stream.4.test.js is located at test/stream.4.test.js (directory: test).
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free