Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add cloudflare workers test. #574

Merged
merged 13 commits into from
Jul 13, 2023
3 changes: 3 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,6 @@ jobs:

- name: Run esbuild test
run: npm run test:esbuild

- name: Run cloudflare workers test
run: npm run test:cloudflare-workers
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"test:browser:build": "rm -rf test/browser/bundle.js && esbuild test/browser/main.ts --bundle --outfile=test/browser/bundle.js",
"test:browser": "npm run build && npm run test:browser:build && node test/browser/test.js",
"test:bun": "npm run build && cd test/bun && bun install && bun run test",
"test:cloudflare-workers": "npm run build && cd test/cloudflare-workers && npm ci && npm test",
"test:deno": "npm run build && deno run --allow-env --allow-read --allow-net test/deno/local.test.ts && deno run --allow-env --allow-read --allow-net test/deno/cdn.test.ts",
"test:typings": "tsd test/typings",
"test:esmimports": "node scripts/check-esm-imports.js",
Expand Down
Empty file.
43 changes: 43 additions & 0 deletions test/cloudflare-workers/api.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { Pool } from 'pg'
import { Hono } from 'hono'
import { Generated, Kysely, PostgresDialect, sql } from '../../'

interface Person {
id: Generated<number>
first_name: string
last_name: string | null
}

interface Database {
person: Person
}

const db = new Kysely<Database>({
dialect: new PostgresDialect({
pool: new Pool({
database: 'kysely_test',
host: 'localhost',
user: 'kysely',
port: 5434,
}),
}),
})

const app = new Hono()

app.get('/', async (c) => {
if (
db.selectFrom('person').selectAll().compile().sql !==
'select * from "person"'
) {
throw new Error('Unexpected SQL')
}

const {
rows: [row],
} = await sql`select 1 as ok`.execute(db)

return c.json(row)
})

export default app
Loading