-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from kimitrii/kimitri
Implement updates and configurations to D1 database to run migrations before end to end tests
- Loading branch information
Showing
12 changed files
with
128 additions
and
33 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
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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 |
---|---|---|
@@ -1,9 +1,20 @@ | ||
import { Hono } from 'hono' | ||
import { drizzle } from 'drizzle-orm/d1'; | ||
import { Env } from './types/drizzleTypes'; | ||
import { users } from './db/schema'; | ||
|
||
const app = new Hono() | ||
const app = new Hono<{ Bindings: Env}>() | ||
|
||
app.get('/', (c) => { | ||
return c.text('Hello Hono!') | ||
app.get('/', async (c) => { | ||
const db = drizzle(c.env.DB) | ||
|
||
await db.insert(users).values({ | ||
name: 'Eric', | ||
}) | ||
|
||
const dbUsers = await db.select().from(users) | ||
|
||
return c.json(dbUsers[0]) | ||
}) | ||
|
||
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
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
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
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,6 @@ | ||
declare module "cloudflare:test" { | ||
interface ProvidedEnv extends Env { | ||
DB: D1Database | ||
TEST_MIGRATIONS: D1Migration[] | ||
} | ||
} |
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 |
---|---|---|
@@ -1,11 +1,15 @@ | ||
import { expect, test } from 'vitest' | ||
import { expect, test, describe, beforeAll } from 'vitest' | ||
import app from '../src' | ||
import { applyD1Migrations, env } from 'cloudflare:test' | ||
|
||
test('Sample E2E test', async () => { | ||
const res = await app.request('/', { | ||
method: 'GET' | ||
describe('Example', () => { | ||
beforeAll(async () => { | ||
await applyD1Migrations(env.DB, env.TEST_MIGRATIONS); | ||
}) | ||
|
||
test('Sample E2E test', async () => { | ||
const res = await app.request('/', {}, env) | ||
|
||
expect(res.status).toBe(200) | ||
}) | ||
|
||
expect(res.status).toBe(200) | ||
expect(await res.text()).toBe('Hello Hono!') | ||
}) |
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 |
---|---|---|
@@ -1,13 +1,23 @@ | ||
import { defineWorkersConfig } from "@cloudflare/vitest-pool-workers/config"; | ||
import { defineWorkersConfig, readD1Migrations } from "@cloudflare/vitest-pool-workers/config"; | ||
|
||
export default defineWorkersConfig({ | ||
|
||
test: { | ||
globals: true, | ||
poolOptions: { | ||
workers: { | ||
wrangler: { configPath: "./wrangler.toml" }, | ||
}, | ||
}, | ||
}, | ||
}); | ||
export default defineWorkersConfig(async () => { | ||
const migrations = await readD1Migrations("./src/migrations") | ||
return { | ||
test: { | ||
globals: true, | ||
poolOptions: { | ||
workers: { | ||
isolatedStorage: true, | ||
miniflare: { | ||
bindings: { | ||
TEST_MIGRATIONS: migrations | ||
} | ||
}, | ||
wrangler: { | ||
configPath: "./wrangler.toml" | ||
} | ||
} | ||
} | ||
} | ||
} | ||
}) |
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