Add more cf compat and update tests

This commit is contained in:
Brian Carlson 2025-04-21 16:32:07 -05:00
parent 306fa83d84
commit 9e7a1f7a21
4 changed files with 12 additions and 4 deletions

View File

@ -55,4 +55,4 @@ test-pool:
test-worker:
@echo "***Testing Cloudflare Worker support***"
@node test/worker/src/index.test.js
yarn vitest -c test/vitest.config.mts test/cloudflare/ --no-watch

View File

@ -22,9 +22,13 @@ async function test() {
},
logLevel: 'ERROR',
})
console.log('worker made')
try {
const resp = await worker.fetch('/')
console.log('requesting from worker')
const resp = await worker.fetch('http://example.com/')
console.log('got resp')
const res = await resp.json()
console.log('get response', res)
const { rows } = res
assert.same(rows[0].text, 'Hello, World!')
} finally {

View File

@ -8,18 +8,22 @@ export interface Env {
export default {
async fetch(request: Request, env: Env, ctx: ExecutionContext): Promise<Response> {
console.log('worker received request')
const url = new URL(request.url)
if (url.pathname === '/favicon.ico') return new Response(null, { status: 404 })
const params = url.searchParams
const ssl = params.has('ssl')
console.log('making client')
var client = new Client({
user: env.PGUSER || env.USER,
password: env.PGPASSWORD,
ssl,
})
console.log('connecting')
await client.connect()
console.log('doing query')
const resp = Response.json(await client.query('SELECT $1::text', ['Hello, World!']))
// Clean up the client, ensuring we don't kill the worker before that is completed.
ctx.waitUntil(client.end())

View File

@ -4,8 +4,8 @@
"lib": [
"es2021"
],
"module": "es2022",
"moduleResolution": "node",
"module": "node16",
"moduleResolution": "node16",
"types": [
"@cloudflare/workers-types"
],