- PGlite (in-memory WASM Postgres) hosted in a child process, exposed via TCP socket; real migrations applied with prisma migrate deploy - Vitest harness (vitest.integration.config.ts, global-setup spawns PGlite + built Nuxt server, per-test TRUNCATE, factories, cookie-jar API client); no mocks, zero production code changes - 50 tests across auth, hunt, team, submit, review, showcase, diashow incl. SuperJSON envelope check; *.itest.ts keeps bun test untouched - CI: parallel unit + integration jobs in .github/workflows/test.yml - tests/ covered by nuxt typecheck via tests/tsconfig.json reference
27 lines
949 B
JavaScript
27 lines
949 B
JavaScript
// Hosts an in-memory PGlite database behind a TCP socket speaking the
|
|
// Postgres wire protocol. Spawned by global-setup.ts as a child process.
|
|
//
|
|
// Deliberately plain .mjs so it can run under a bare `node` with no
|
|
// TS loader, and deliberately never calls db.close()/server.stop():
|
|
// under Bun, PGlite teardown triggers an Emscripten exit(99) which would
|
|
// kill the process with a non-zero code. Cleanup happens via SIGTERM/SIGKILL.
|
|
import { PGlite } from '@electric-sql/pglite';
|
|
import { PGLiteSocketServer } from '@electric-sql/pglite-socket';
|
|
|
|
const db = new PGlite();
|
|
await db.waitReady;
|
|
|
|
const server = new PGLiteSocketServer({
|
|
db,
|
|
port: 0,
|
|
host: '127.0.0.1',
|
|
maxConnections: 20
|
|
});
|
|
await server.start();
|
|
|
|
const [host, port] = server.getServerConn().split(':');
|
|
console.log(`PGLITE_READY postgresql://postgres@${host}:${port}/postgres`);
|
|
|
|
process.on('SIGTERM', () => process.exit(0));
|
|
process.on('SIGINT', () => process.exit(0));
|