-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
60 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
MY_VAR=development-env |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# deps | ||
node_modules/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"name": "hono-env-testing", | ||
"scripts": { | ||
"dev": "bun run --hot src/index.ts" | ||
}, | ||
"dependencies": { | ||
"hono": "^4.6.2" | ||
}, | ||
"devDependencies": { | ||
"@types/bun": "latest" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { describe, expect, it } from 'bun:test'; | ||
import app, { type Environment } from '.'; | ||
|
||
const MOCK_ENV: Environment = { | ||
MY_VAR: 'mocked-env' | ||
}; | ||
|
||
describe('Environment', () => { | ||
it('Should return environment variables', async () => { | ||
const res = await app.request('/env'); | ||
expect(res.status).toBe(200); | ||
|
||
const env = await res.json(); | ||
expect(env).toHaveProperty('MY_VAR'); | ||
expect(env.MY_VAR).toBe(process.env.MY_VAR); | ||
}); | ||
|
||
it('Should contain overrides from MOCK_ENV', async () => { | ||
const res = await app.request('/env', {}, MOCK_ENV); | ||
expect(res.status).toBe(200); | ||
|
||
const env = await res.json(); | ||
expect(env).toHaveProperty('MY_VAR'); | ||
expect(env.MY_VAR).toBe(MOCK_ENV.MY_VAR); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { Hono } from 'hono'; | ||
import { env } from 'hono/adapter'; | ||
|
||
export interface Environment extends Record<string, string> { | ||
MY_VAR: string; | ||
} | ||
|
||
const app = new Hono(); | ||
|
||
app.get('/env', (c) => c.json(env<Environment>(c))); | ||
|
||
export default app; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"compilerOptions": { | ||
"strict": true, | ||
"jsx": "react-jsx", | ||
"jsxImportSource": "hono/jsx" | ||
} | ||
} |