2022-01-12 00:20:16 +00:00
|
|
|
import { Hono } from '../src/hono'
|
|
|
|
import { Middleware } from '../src/middleware'
|
2022-01-01 07:22:35 +00:00
|
|
|
|
|
|
|
describe('Builtin Middleware', () => {
|
|
|
|
const app = new Hono()
|
|
|
|
|
2022-01-05 09:41:29 +00:00
|
|
|
app.use('*', Middleware.poweredBy())
|
2022-01-03 22:02:31 +00:00
|
|
|
app.get('/', () => new Response('root'))
|
2022-01-01 07:22:35 +00:00
|
|
|
|
|
|
|
it('Builtin Powered By Middleware', async () => {
|
2022-01-11 17:14:53 +00:00
|
|
|
const req = new Request('http://localhost/')
|
2022-01-06 22:03:54 +00:00
|
|
|
const res = await app.dispatch(req)
|
2022-01-01 07:22:35 +00:00
|
|
|
expect(res).not.toBeNull()
|
|
|
|
expect(res.status).toBe(200)
|
|
|
|
expect(res.headers.get('X-Powered-By')).toBe('Hono')
|
|
|
|
})
|
|
|
|
})
|
2022-01-16 12:52:49 +00:00
|
|
|
|
|
|
|
describe('Default Middleware', () => {
|
|
|
|
const app = new Hono()
|
|
|
|
app.get('/text', (c) => c.text('abcdefg'))
|
|
|
|
app.get('/japanese', (c) => c.text('炎'))
|
|
|
|
|
|
|
|
it('Content-Length', async () => {
|
|
|
|
let req = new Request('http://localhost/text')
|
|
|
|
let res = await app.dispatch(req)
|
|
|
|
expect(res.headers.get('Content-Length')).toBe('7')
|
|
|
|
req = new Request('http://localhost/japanese')
|
|
|
|
res = await app.dispatch(req)
|
|
|
|
expect(res.headers.get('Content-Length')).toBe('3')
|
|
|
|
})
|
|
|
|
})
|