/
erioxis
/
web-nodejs
Обзор
Документация
Войти
/
erioxis
/
web-nodejs
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
backend/node_modules/fastify/test/case-insensitive.test.js
102 строки
2 KB
erioxis
lab11fix
15 дек 2025, 23:21
15 дек 2025, 23:21
70dc7ba
Код
Авторство
О чём код?
'use strict' const { test } = require('node:test') const Fastify = require('..') test('case insensitive', async (t) => { t.plan(3) const fastify = Fastify({ caseSensitive: false }) t.after(() => fastify.close()) fastify.get('/foo', (req, reply) => { reply.send({ hello: 'world' }) }) const fastifyServer = await fastify.listen({ port: 0 }) const result = await fetch(`${fastifyServer}/FOO`) t.assert.ok(result.ok) t.assert.strictEqual(result.status, 200) t.assert.deepStrictEqual(await result.json(), { hello: 'world' }) }) test('case insensitive inject', async t => { t.plan(2) const fastify = Fastify({ caseSensitive: false }) t.after(() => fastify.close()) fastify.get('/foo', (req, reply) => { reply.send({ hello: 'world' }) }) const fastifyServer = await fastify.listen({ port: 0 }) const result = await fastify.inject({ method: 'GET', url: fastifyServer + '/FOO' }) t.assert.strictEqual(result.statusCode, 200) t.assert.deepStrictEqual(result.json(), { hello: 'world' }) }) test('case insensitive (parametric)', async (t) => { t.plan(4) const fastify = Fastify({ caseSensitive: false }) t.after(() => fastify.close()) fastify.get('/foo/:param', (req, reply) => { t.assert.strictEqual(req.params.param, 'bAr') reply.send({ hello: 'world' }) }) const fastifyServer = await fastify.listen({ port: 0 }) const result = await fetch(`${fastifyServer}/FoO/bAr`, { method: 'GET' }) t.assert.ok(result.ok) t.assert.strictEqual(result.status, 200) t.assert.deepStrictEqual(await result.json(), { hello: 'world' }) }) test('case insensitive (wildcard)', async (t) => { t.plan(4) const fastify = Fastify({ caseSensitive: false }) t.after(() => fastify.close()) fastify.get('/foo/*', (req, reply) => { t.assert.strictEqual(req.params['*'], 'bAr/baZ') reply.send({ hello: 'world' }) }) const fastifyServer = await fastify.listen({ port: 0 }) const result = await fetch(`${fastifyServer}/FoO/bAr/baZ`) t.assert.ok(result.ok) t.assert.strictEqual(result.status, 200) t.assert.deepStrictEqual(await result.json(), { hello: 'world' }) })