Home / File/ stream.5.test.js — fastify Source File

stream.5.test.js — fastify Source File

Architecture documentation for stream.5.test.js, a javascript file in the fastify codebase.

Entity Profile

Source Code

'use strict'

const { test } = require('node:test')
const proxyquire = require('proxyquire')
const fs = require('node:fs')
const Readable = require('node:stream').Readable
const Fastify = require('..')

test('should destroy stream when response is ended', async (t) => {
  t.plan(3)
  const stream = require('node:stream')
  const fastify = Fastify()

  fastify.get('/error', function (req, reply) {
    const reallyLongStream = new stream.Readable({
      read: function () { },
      destroy: function (err, callback) {
        t.assert.ok('called')
        callback(err)
      }
    })
    reply.code(200).send(reallyLongStream)
    reply.raw.end(Buffer.from('hello\n'))
  })

  const fastifyServer = await fastify.listen({ port: 0 })
  t.after(() => fastify.close())

  const response = await fetch(`${fastifyServer}/error`)
  t.assert.ok(response.ok)
  t.assert.strictEqual(response.status, 200)
})

test('should mark reply as sent before pumping the payload stream into response for async route handler', async (t) => {
  t.plan(2)
  t.after(() => fastify.close())

  const handleRequest = proxyquire('../lib/handle-request', {
    './wrap-thenable': (thenable, reply) => {
      thenable.then(function (payload) {
        t.assert.strictEqual(reply.sent, true)
      })
    }
  })

  const route = proxyquire('../lib/route', {
    './handle-request': handleRequest
  })

  const Fastify = proxyquire('..', {
    './lib/route': route
  })

  const fastify = Fastify()

  fastify.get('/', async function (req, reply) {
    const stream = fs.createReadStream(__filename, 'utf8')
    return reply.code(200).send(stream)
  })

// ... (129 more lines)

Frequently Asked Questions

What does stream.5.test.js do?
stream.5.test.js is a source file in the fastify codebase, written in javascript.
Where is stream.5.test.js in the architecture?
stream.5.test.js is located at test/stream.5.test.js (directory: test).

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free