Closed as not planned
Closed as not planned
Description
Which Cloudflare product(s) does this pertain to?
Workers Vitest Integration
What versions & operating system are you using?
@cloudflare/[email protected], [email protected], [email protected], macOS 14.5
Please provide a link to a minimal reproduction
https://github.com/tmm/pg-cloudflare-issue
Describe the Bug
Using pg
in simple test:
import { Pool } from "pg";
import { test } from "vitest";
test("default", async () => {
const pool = new Pool({
connectionString: "postgresql://postgres:postgres@localhost",
});
const result = await pool.query("SELECT $1::text as name", ["cloudflare"]);
console.log(result.rows[0].name);
});
Test passes with the following config vitest.pass.config.mts
:
export default {
test: {
poolOptions: {
workers: {
wrangler: { configPath: "./wrangler.jsonc" },
},
},
},
};
Test fails with the following config vitest.fail.config.mts
:
import { defineWorkersConfig } from "@cloudflare/vitest-pool-workers/config";
export default defineWorkersConfig({
test: {
poolOptions: {
workers: {
wrangler: { configPath: "./wrangler.jsonc" },
},
},
},
});
Possible upstream fix: brianc/node-postgres#3407
Please provide any relevant error logs
❯ pnpm test:pass
> @ test:pass /Users/user/Desktop/worker
> vitest -c vitest.pass.config.mts
DEV v3.0.9 /Users/user/Desktop/worker
stdout | test/index.spec.ts > default
cloudflare
✓ test/index.spec.ts (1 test) 16ms
✓ default
Test Files 1 passed (1)
Tests 1 passed (1)
Start at 23:21:49
Duration 184ms (transform 16ms, setup 0ms, collect 23ms, tests 16ms, environment 0ms, prepare 32ms)
PASS Waiting for file changes...
press h to show help, press q to quit
❯ pnpm test:fail
> @ test:fail /Users/user/Desktop/worker
> vitest -c vitest.fail.config.mts
DEV v3.0.9 /Users/user/Desktop/worker
[vpw:inf] Starting isolated runtimes for vitest.fail.config.mts...
[mf:wrn] The latest compatibility date supported by the installed Cloudflare Workers Runtime is "2025-04-05",
but you've requested "2025-04-07". Falling back to "2025-04-05"...
workerd/server/server.c++:3250: error: Fallback service failed to fetch module; exception = (unknown):-1: failed: std::exception: Uncaught JsExceptionThrown
stack: 1053983a7 1048b010f 104887c3b 1053a0c53 104b26913 104b26bef 1053966db 104b187a3 1055faf17 1055f93eb 1055f93eb 1055f9c4b 1057868f3 1055f93eb 1055f9c4b; spec = /?specifier=%2FUsers%2Fuser%2FDesktop%2Fworker%2Fnode_modules%2F.pnpm%2Fpg-cloudflare%401.1.1%2Fnode_modules%2Fpg-cloudflare%2Fdist%2Findex.js%3Fmf_vitest_no_cjs_esm_shim&referrer=%2FUsers%2Fuser%2FDesktop%2Fworker%2Fnode_modules%2F.pnpm%2Fpg%408.14.1%2Fnode_modules%2Fpg%2Flib%2Fstream.js%3Fmf_vitest_no_cjs_esm_shim&rawSpecifier=pg-cloudflare
❯ test/index.spec.ts (1 test | 1 failed) 8ms
× default 4ms
→ No such module "Users/user/Desktop/worker/node_modules/.pnpm/[email protected]/node_modules/pg/lib/pg-cloudflare".
⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ Failed Tests 1 ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯
FAIL test/index.spec.ts > default
Error: No such module "Users/user/Desktop/worker/node_modules/.pnpm/[email protected]/node_modules/pg/lib/pg-cloudflare".
❯ getStream Users/user/Desktop/worker/node_modules/.pnpm/[email protected]/node_modules/pg/lib/stream.js?mf_vitest_no_cjs_esm_shim:41:34
❯ new Connection Users/user/Desktop/worker/node_modules/.pnpm/[email protected]/node_modules/pg/lib/connection.js?mf_vitest_no_cjs_esm_shim:18:36
❯ new Client Users/user/Desktop/worker/node_modules/.pnpm/[email protected]/node_modules/pg/lib/client.js?mf_vitest_no_cjs_esm_shim:49:7
❯ BoundPool.newClient Users/user/Desktop/worker/node_modules/.pnpm/[email protected][email protected]/node_modules/pg-pool/index.js?mf_vitest_no_cjs_esm_shim:222:20
❯ BoundPool.connect Users/user/Desktop/worker/node_modules/.pnpm/[email protected][email protected]/node_modules/pg-pool/index.js?mf_vitest_no_cjs_esm_shim:216:10
❯ BoundPool.query Users/user/Desktop/worker/node_modules/.pnpm/[email protected][email protected]/node_modules/pg-pool/index.js?mf_vitest_no_cjs_esm_shim:403:10
❯ test/index.spec.ts:8:28
6| connectionString: "postgresql://postgres:postgres@localhost",
7| });
8| const result = await pool.query("SELECT $1::text as name", ["cloudflare"]);
| ^
9| console.log(result.rows[0].name);
10| });
⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯[1/1]⎯
Test Files 1 failed (1)
Tests 1 failed (1)
Start at 23:22:42
Duration 555ms (transform 12ms, setup 0ms, collect 51ms, tests 8ms, environment 0ms, prepare 113ms)
FAIL Tests failed. Watching for file changes...
press h to show help, press q to quit
Metadata
Metadata
Assignees
Type
Projects
Status
Done