hono.test.ts
This file
Path
runtime-tests/deno/hono.test.ts
34 lines · 1.0 KiB · TypeScript
Last changed by
chore: let oxfmt sort imports instead of eslint (#5442)Yusuke Wadabefore adoption859e2c2
History of this fileTake it
The walk stopped after 200 commits: lines older than f0b094d point at it.
Merge commit from forkYusuke Wadabefore adoptionf0b094d
lines 1–34why, one step back1import { assertEquals } from '@std/assert'2import { Context } from '../../src/context.ts'3import { env, getRuntimeKey } from '../../src/helper/adapter/index.ts'4import { Hono } from '../../src/hono.ts'56// Test just only minimal patterns.7// Because others are tested well in Cloudflare Workers environment already.89Deno.env.set('NAME', 'Deno')1011Deno.test('Hello World', async () => {12 const app = new Hono()13 app.get('/:foo', (c) => {14 c.header('x-param', c.req.param('foo'))15 c.header('x-query', c.req.query('q') || '')16 return c.text('Hello Deno!')17 })1819 const res = await app.request('/foo?q=bar')20 assertEquals(res.status, 200)21 assertEquals(await res.text(), 'Hello Deno!')22 assertEquals(res.headers.get('x-param'), 'foo')23 assertEquals(res.headers.get('x-query'), 'bar')24})2526Deno.test('runtime', () => {27 assertEquals(getRuntimeKey(), 'deno')28})2930Deno.test('environment variables', () => {31 const c = new Context(new Request('http://localhost/'))32 const { NAME } = env<{ NAME: string }>(c)33 assertEquals(NAME, 'Deno')34})