Home / File/ plugin.2.test.js — fastify Source File

plugin.2.test.js — fastify Source File

Architecture documentation for plugin.2.test.js, a javascript file in the fastify codebase.

Entity Profile

Source Code

'use strict'

const { test } = require('node:test')
const Fastify = require('../fastify')
const fp = require('fastify-plugin')

test('check dependencies - should not throw', async t => {
  t.plan(11)
  const fastify = Fastify()

  fastify.register((instance, opts, done) => {
    instance.register(fp((i, o, n) => {
      i.decorate('test', () => {})
      t.assert.ok(i.test)
      n()
    }))

    instance.register(fp((i, o, n) => {
      try {
        i.decorate('otherTest', () => {}, ['test'])
        t.assert.ok(i.test)
        t.assert.ok(i.otherTest)
        n()
      } catch (e) {
        t.assert.fail()
      }
    }))

    instance.get('/', (req, reply) => {
      t.assert.ok(instance.test)
      t.assert.ok(instance.otherTest)
      reply.send({ hello: 'world' })
    })

    done()
  })

  fastify.ready(() => {
    t.assert.ok(!fastify.test)
    t.assert.ok(!fastify.otherTest)
  })

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

  const result = await fetch(fastifyServer)
  t.assert.ok(result.ok)
  t.assert.strictEqual(result.status, 200)
  const body = await result.text()
  t.assert.strictEqual(result.headers.get('content-length'), '' + body.length)
  t.assert.deepStrictEqual(JSON.parse(body), { hello: 'world' })
})

test('check dependencies - should throw', async t => {
  t.plan(11)
  const fastify = Fastify()

  fastify.register((instance, opts, done) => {
    instance.register(fp((i, o, n) => {
      try {
// ... (255 more lines)

Frequently Asked Questions

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

Analyze Your Own Codebase

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

Try Supermodel Free