Home / File/ custom-querystring-parser.test.js — fastify Source File

custom-querystring-parser.test.js — fastify Source File

Architecture documentation for custom-querystring-parser.test.js, a javascript file in the fastify codebase.

Entity Profile

Source Code

'use strict'

const { test } = require('node:test')
const querystring = require('node:querystring')
const Fastify = require('..')

test('Custom querystring parser', async t => {
  t.plan(7)

  const fastify = Fastify({
    querystringParser: function (str) {
      t.assert.strictEqual(str, 'foo=bar&baz=faz')
      return querystring.parse(str)
    }
  })

  fastify.get('/', (req, reply) => {
    t.assert.deepEqual(req.query, {
      foo: 'bar',
      baz: 'faz'
    })
    reply.send({ hello: 'world' })
  })

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

  const result = await fetch(`${fastifyServer}?foo=bar&baz=faz`)
  t.assert.ok(result.ok)
  t.assert.strictEqual(result.status, 200)

  const injectResponse = await fastify.inject({
    method: 'GET',
    url: `${fastifyServer}?foo=bar&baz=faz`
  })
  t.assert.strictEqual(injectResponse.statusCode, 200)
})

test('Custom querystring parser should be called also if there is nothing to parse', async t => {
  t.plan(7)

  const fastify = Fastify({
    querystringParser: function (str) {
      t.assert.strictEqual(str, '')
      return querystring.parse(str)
    }
  })

  fastify.get('/', (req, reply) => {
    t.assert.deepEqual(req.query, {})
    reply.send({ hello: 'world' })
  })

  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)

// ... (70 more lines)

Frequently Asked Questions

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

Analyze Your Own Codebase

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

Try Supermodel Free