2023-05-02 12:16:17 +00:00
|
|
|
import { env } from '../../deno_dist/adapter.ts'
|
|
|
|
import { Context } from '../../deno_dist/context.ts'
|
|
|
|
import { Hono } from '../../deno_dist/mod.ts'
|
2022-07-12 22:22:28 +00:00
|
|
|
import { assertEquals } from './deps.ts'
|
|
|
|
|
|
|
|
// Test just only minimal patterns.
|
|
|
|
// Because others are tested well in Cloudflare Workers environment already.
|
|
|
|
|
|
|
|
Deno.test('Hello World', async () => {
|
|
|
|
const app = new Hono()
|
|
|
|
app.get('/:foo', (c) => {
|
|
|
|
c.header('x-param', c.req.param('foo'))
|
2023-02-13 12:40:51 +00:00
|
|
|
c.header('x-query', c.req.query('q') || '')
|
2022-07-12 22:22:28 +00:00
|
|
|
return c.text('Hello Deno!')
|
|
|
|
})
|
2023-05-03 14:05:21 +00:00
|
|
|
|
|
|
|
const res = await app.request('/foo?q=bar')
|
2022-07-12 22:22:28 +00: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 06:35:23 +00:00
|
|
|
|
2023-05-03 14:05:21 +00:00
|
|
|
Deno.test('runtime', () => {
|
2022-11-03 06:53:41 +00:00
|
|
|
const c = new Context(new Request('http://localhost/'))
|
2022-11-03 06:35:23 +00:00
|
|
|
assertEquals(c.runtime, 'deno')
|
|
|
|
})
|
2023-03-06 12:12:22 +00:00
|
|
|
|
2023-05-03 14:05:21 +00:00
|
|
|
Deno.test('environment variables', () => {
|
2023-03-06 12:12:22 +00:00
|
|
|
const c = new Context(new Request('http://localhost/'))
|
|
|
|
const { NAME } = env<{ NAME: string }>(c)
|
|
|
|
assertEquals(NAME, 'Deno')
|
|
|
|
})
|