You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
What runtime/platform is your app running on? (with version if possible)
Node.js/23
What steps can reproduce the bug?
I'm developing a program that needs to run on both Cloudflare Workers and Node.js (on-prem). To handle this, I'm using the env() helper from hono/adapter. However, this interact poorly with testing using app.request, as it mocks c.env, but that does not affect env(c) on the NodeJS runtime.
To reproduce, create the following file under the path test/index.js:
import 'mocha'
import { assert, expect } from 'chai'
import { env } from 'hono/adapter'
import { Hono } from 'hono'
const app = new Hono()
app.get('/', (c) => {
return c.text(`Var is ${env(c).VAR}`)
})
describe('Example', () => {
it('GET /', async () => {
const res = await app.request('/', {}, {VAR: "abc"})
expect(res.status).to.equal(200)
expect(await res.text()).to.equal('Var is abc')
})
})
run the following command, which will both build and test the project:
npm run test
What is the expected behavior?
> test
> tsc && mocha
Example
✔ GET /
1 passing (18ms)
What do you see instead?
> test
> tsc && mocha
Example
1) GET /
0 passing (17ms)
1 failing
1) Example
GET /:
AssertionError: expected 'Var is undefined' to equal 'Var is abc'
+ expected - actual
-Var is undefined
+Var is abc
Additional information
The global environment passes through unmocked, so you can see the expected output by running:
VAR=abc npm run test
The text was updated successfully, but these errors were encountered:
What version of Hono are you using?
4.6.20
What runtime/platform is your app running on? (with version if possible)
Node.js/23
What steps can reproduce the bug?
I'm developing a program that needs to run on both Cloudflare Workers and Node.js (on-prem). To handle this, I'm using the
env()
helper fromhono/adapter
. However, this interact poorly with testing usingapp.request
, as it mocksc.env
, but that does not affectenv(c)
on the NodeJS runtime.To reproduce, create the following file under the path
test/index.js
:use the following package.json:
run the following command, which will both build and test the project:
npm run test
What is the expected behavior?
What do you see instead?
Additional information
The global environment passes through unmocked, so you can see the expected output by running:
VAR=abc npm run test
The text was updated successfully, but these errors were encountered: