Skip to content

Commit

Permalink
Provide tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nawok committed Sep 24, 2024
1 parent da6f782 commit 95c4139
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 0 deletions.
1 change: 1 addition & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
MY_VAR=development-env
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# deps
node_modules/
Binary file added bun.lockb
Binary file not shown.
12 changes: 12 additions & 0 deletions package.json
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"
}
}
26 changes: 26 additions & 0 deletions src/index.test.ts
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);
});
});
12 changes: 12 additions & 0 deletions src/index.ts
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;
7 changes: 7 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"compilerOptions": {
"strict": true,
"jsx": "react-jsx",
"jsxImportSource": "hono/jsx"
}
}

0 comments on commit 95c4139

Please sign in to comment.