2024-09-12 05:05:41 +02:00
|
|
|
import { assertEquals } from '@std/assert'
|
2024-05-24 10:47:28 +02:00
|
|
|
import { Context } from '../../src/context.ts'
|
|
|
|
import { env, getRuntimeKey } from '../../src/helper/adapter/index.ts'
|
|
|
|
import { Hono } from '../../src/hono.ts'
|
2022-07-13 00:22:28 +02:00
|
|
|
|
|
|
|
// Test just only minimal patterns.
|
|
|
|
// Because others are tested well in Cloudflare Workers environment already.
|
|
|
|
|
2024-01-23 09:07:31 +01:00
|
|
|
Deno.env.set('NAME', 'Deno')
|
|
|
|
|
2022-07-13 00:22:28 +02:00
|
|
|
Deno.test('Hello World', async () => {
|
|
|
|
const app = new Hono()
|
|
|
|
app.get('/:foo', (c) => {
|
|
|
|
c.header('x-param', c.req.param('foo'))
|
2023-02-13 13:40:51 +01:00
|
|
|
c.header('x-query', c.req.query('q') || '')
|
2022-07-13 00:22:28 +02:00
|
|
|
return c.text('Hello Deno!')
|
|
|
|
})
|
2023-05-03 16:05:21 +02:00
|
|
|
|
|
|
|
const res = await app.request('/foo?q=bar')
|
2022-07-13 00:22:28 +02:00
|
|
|
assertEquals(res.status, 200)
|
|
|
|
assertEquals(await res.text(), 'Hello Deno!')
|
|
|
|
assertEquals(res.headers.get('x-param'), 'foo')
|
|
|
|
assertEquals(res.headers.get('x-query'), 'bar')
|
|
|
|
})
|
2022-11-03 07:35:23 +01:00
|
|
|
|
2023-05-03 16:05:21 +02:00
|
|
|
Deno.test('runtime', () => {
|
2023-08-21 08:22:37 +02:00
|
|
|
assertEquals(getRuntimeKey(), 'deno')
|
2022-11-03 07:35:23 +01:00
|
|
|
})
|
2023-03-06 13:12:22 +01:00
|
|
|
|
2023-05-03 16:05:21 +02:00
|
|
|
Deno.test('environment variables', () => {
|
2024-06-27 03:44:37 +02:00
|
|
|
const c = new Context(new Request('http://localhost/'))
|
2023-03-06 13:12:22 +01:00
|
|
|
const { NAME } = env<{ NAME: string }>(c)
|
|
|
|
assertEquals(NAME, 'Deno')
|
|
|
|
})
|