Home / File/ reply-web-stream-locked.test.js — fastify Source File

reply-web-stream-locked.test.js — fastify Source File

Architecture documentation for reply-web-stream-locked.test.js, a javascript file in the fastify codebase.

Entity Profile

Source Code

'use strict'

const { ReadableStream } = require('node:stream/web')
const { test, after } = require('node:test')
const Fastify = require('..')

test('reply.send(web ReadableStream) throws if locked', async t => {
  t.plan(3)

  const app = Fastify()
  after(() => app.close())

  app.get('/', (req, reply) => {
    const rs = new ReadableStream({
      start (controller) { controller.enqueue(new TextEncoder().encode('hi')); controller.close() }
    })
    // lock the stream
    const reader = rs.getReader()
    t.assert.strictEqual(rs.locked, true, 'stream is locked')

    // sending a locked stream should trigger the Fastify error
    reply.send(rs)
    reader.releaseLock()
  })

  const res = await app.inject({ method: 'GET', url: '/' })
  t.assert.strictEqual(res.statusCode, 500)
  t.assert.deepStrictEqual(
    JSON.parse(res.body),
    {
      statusCode: 500,
      code: 'FST_ERR_REP_READABLE_STREAM_LOCKED',
      error: 'Internal Server Error',
      message: 'ReadableStream was locked. You should call releaseLock() method on reader before sending.'
    }
  )
})

Frequently Asked Questions

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

Analyze Your Own Codebase

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

Try Supermodel Free