content-parser.test.js — fastify Source File
Architecture documentation for content-parser.test.js, a javascript file in the fastify codebase.
Entity Profile
Relationship Graph
Source Code
'use strict'
const { test } = require('node:test')
const Fastify = require('..')
const keys = require('../lib/symbols')
const { FST_ERR_CTP_ALREADY_PRESENT, FST_ERR_CTP_INVALID_TYPE, FST_ERR_CTP_INVALID_MEDIA_TYPE } = require('../lib/errors')
const first = function (req, payload, done) {}
const second = function (req, payload, done) {}
const third = function (req, payload, done) {}
test('hasContentTypeParser', async t => {
await t.test('should know about internal parsers', (t, done) => {
t.plan(5)
const fastify = Fastify()
fastify.ready(err => {
t.assert.ifError(err)
t.assert.ok(fastify.hasContentTypeParser('application/json'))
t.assert.ok(fastify.hasContentTypeParser('text/plain'))
t.assert.ok(fastify.hasContentTypeParser(' text/plain '))
t.assert.ok(!fastify.hasContentTypeParser('application/jsoff'))
done()
})
})
await t.test('should only work with string and RegExp', t => {
t.plan(8)
const fastify = Fastify()
fastify.addContentTypeParser(/^image\/.*/, first)
fastify.addContentTypeParser(/^application\/.+\+xml/, first)
fastify.addContentTypeParser('image/gif', first)
t.assert.ok(fastify.hasContentTypeParser('application/json'))
t.assert.ok(fastify.hasContentTypeParser(/^image\/.*/))
t.assert.ok(fastify.hasContentTypeParser(/^application\/.+\+xml/))
t.assert.ok(fastify.hasContentTypeParser('image/gif'))
t.assert.ok(!fastify.hasContentTypeParser(/^image\/.+\+xml/))
t.assert.ok(!fastify.hasContentTypeParser('image/png'))
t.assert.ok(!fastify.hasContentTypeParser('*'))
t.assert.throws(
() => fastify.hasContentTypeParser(123),
FST_ERR_CTP_INVALID_TYPE
)
})
})
test('getParser', async t => {
await t.test('should return matching parser', t => {
t.plan(7)
const fastify = Fastify()
fastify.addContentTypeParser(/^image\/.*/, first)
fastify.addContentTypeParser(/^application\/.+\+xml/, second)
fastify.addContentTypeParser('text/html', third)
fastify.addContentTypeParser('text/html; charset=utf-8', third)
t.assert.strictEqual(fastify[keys.kContentTypeParser].getParser('application/t+xml').fn, second)
// ... (656 more lines)
Domain
Subdomains
Source
Frequently Asked Questions
What does content-parser.test.js do?
content-parser.test.js is a source file in the fastify codebase, written in javascript. It belongs to the CoreKernel domain, InstanceFactory subdomain.
What functions are defined in content-parser.test.js?
content-parser.test.js defines 3 function(s): first, second, third.
Where is content-parser.test.js in the architecture?
content-parser.test.js is located at test/content-parser.test.js (domain: CoreKernel, subdomain: InstanceFactory, directory: test).
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free