0
0
mirror of https://github.com/honojs/hono.git synced 2024-11-29 01:32:12 +01:00
hono/runtime_tests/deno/hono.test.ts
Yusuke Wada 1b2a4c0800
feat(jsr): support JSR (#2662)
* feat(jsr): reduce slow types (#2369)

* feat(jsr): reduce slow types

* fix: use allow function

* chore: format code

* chore: denoify

* add `deno.json`

* add `jsr-dry-run` command for CI

* don't put `JSX` on `global`

* fix test settings for deno

* don't use `dynamicClass`

* don't declare `ExecutionContext` in `global`

* goodbye denoify

* exports `./middleware`

* exports `./helper`

* exports each helper and middleware

* remove the `awslambda` implementation which is not enough

* feat(jsr): remove helper.ts and middleware.ts (#2667)

* feat(jsr): remove helper.ts and middleware.ts

* fix: fix test

* dont' use `SuperClass`

Co-authored-by: Taku Amano <taku@taaas.jp>

* feat(jsr): delete `mod.ts` (#2669)

* rename `deno.json` to `jsr.json`

* lint

* remove slow type in lambda adapter

* fixed runtime test for deno

* export all utils

* add a GitHub action to publish the package to JSR

* fixed declaring `ContextVariableMap`

* fixed the type error

* include `jsr.json` in `jsr.json`

* update `jsr.json`

---------

Co-authored-by: Shotaro Nakamura <79000684+nakasyou@users.noreply.github.com>
Co-authored-by: Taku Amano <taku@taaas.jp>
2024-05-24 17:47:28 +09:00

36 lines
1.1 KiB
TypeScript

import { Context } from '../../src/context.ts'
import { env, getRuntimeKey } from '../../src/helper/adapter/index.ts'
import { Hono } from '../../src/hono.ts'
import { HonoRequest } from '../../src/request.ts'
import { assertEquals } from './deps.ts'
// Test just only minimal patterns.
// Because others are tested well in Cloudflare Workers environment already.
Deno.env.set('NAME', 'Deno')
Deno.test('Hello World', async () => {
const app = new Hono()
app.get('/:foo', (c) => {
c.header('x-param', c.req.param('foo'))
c.header('x-query', c.req.query('q') || '')
return c.text('Hello Deno!')
})
const res = await app.request('/foo?q=bar')
assertEquals(res.status, 200)
assertEquals(await res.text(), 'Hello Deno!')
assertEquals(res.headers.get('x-param'), 'foo')
assertEquals(res.headers.get('x-query'), 'bar')
})
Deno.test('runtime', () => {
assertEquals(getRuntimeKey(), 'deno')
})
Deno.test('environment variables', () => {
const c = new Context(new HonoRequest(new Request('http://localhost/')))
const { NAME } = env<{ NAME: string }>(c)
assertEquals(NAME, 'Deno')
})