Home / File/ listen.1.test.js — fastify Source File

listen.1.test.js — fastify Source File

Architecture documentation for listen.1.test.js, a javascript file in the fastify codebase.

Entity Profile

Source Code

'use strict'

const { networkInterfaces } = require('node:os')
const { test, before } = require('node:test')
const Fastify = require('..')
const helper = require('./helper')

let localhost
let localhostForURL

before(async function () {
  [localhost, localhostForURL] = await helper.getLoopbackHost()
})

test('listen works without arguments', async t => {
  const doNotWarn = () => {
    t.assert.fail('should not be deprecated')
  }
  process.on('warning', doNotWarn)

  const fastify = Fastify()
  t.after(() => {
    fastify.close()
    process.removeListener('warning', doNotWarn)
  })
  await fastify.listen()
  const address = fastify.server.address()
  t.assert.strictEqual(address.address, localhost)
  t.assert.ok(address.port > 0)
})

test('Async/await listen with arguments', async t => {
  const doNotWarn = () => {
    t.assert.fail('should not be deprecated')
  }
  process.on('warning', doNotWarn)

  const fastify = Fastify()
  t.after(() => {
    fastify.close()
    process.removeListener('warning', doNotWarn)
  })
  const addr = await fastify.listen({ port: 0, host: '0.0.0.0' })
  const address = fastify.server.address()
  const { protocol, hostname, port, pathname } = new URL(addr)
  t.assert.strictEqual(protocol, 'http:')
  t.assert.ok(Object.values(networkInterfaces())
    .flat()
    .filter(({ internal }) => internal)
    .some(({ address }) => address === hostname))
  t.assert.strictEqual(pathname, '/')
  t.assert.strictEqual(Number(port), address.port)
  t.assert.deepEqual(address, {
    address: '0.0.0.0',
    family: 'IPv4',
    port: address.port
  })
})

test('listen accepts a callback', (t, done) => {
// ... (95 more lines)

Frequently Asked Questions

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

Analyze Your Own Codebase

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

Try Supermodel Free