mirror of
https://github.com/brianc/node-postgres.git
synced 2026-01-18 15:55:05 +00:00
Add more cf compat and update tests
This commit is contained in:
parent
306fa83d84
commit
9e7a1f7a21
@ -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
|
||||
|
||||
@ -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 {
|
||||
|
||||
@ -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())
|
||||
|
||||
@ -4,8 +4,8 @@
|
||||
"lib": [
|
||||
"es2021"
|
||||
],
|
||||
"module": "es2022",
|
||||
"moduleResolution": "node",
|
||||
"module": "node16",
|
||||
"moduleResolution": "node16",
|
||||
"types": [
|
||||
"@cloudflare/workers-types"
|
||||
],
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user