pglite-test 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +63 -30
  2. package/package.json +7 -7
package/README.md CHANGED
@@ -1,18 +1,52 @@
1
1
  # pglite-test
2
2
 
3
- A drop-in [`pgsql-test`](../pgsql-test) `getConnections()` backed by an in-process
4
- [**PGlite**](https://github.com/electric-sql/pglite) instance (WASM Postgres) —
5
- **no Postgres server, no `createdb`, no `psql`, no TCP.**
3
+ <p align="center" width="100%">
4
+ <img height="250" src="https://raw.githubusercontent.com/constructive-io/constructive/refs/heads/main/assets/outline-logo.svg" />
5
+ </p>
6
+
7
+ <p align="center" width="100%">
8
+ <a href="https://github.com/constructive-io/constructive/actions/workflows/run-tests.yaml">
9
+ <img height="20" src="https://github.com/constructive-io/constructive/actions/workflows/run-tests.yaml/badge.svg" />
10
+ </a>
11
+ <a href="https://github.com/constructive-io/constructive/blob/main/LICENSE">
12
+ <img height="20" src="https://img.shields.io/badge/license-MIT-blue.svg"/>
13
+ </a>
14
+ <a href="https://www.npmjs.com/package/pglite-test">
15
+ <img height="20" src="https://img.shields.io/github/package-json/v/constructive-io/constructive?filename=postgres%2Fpglite-test%2Fpackage.json"/>
16
+ </a>
17
+ </p>
18
+
19
+ `pglite-test` is a [**PGlite**](https://github.com/electric-sql/pglite)-optimized version of [`pgsql-test`](https://www.npmjs.com/package/pgsql-test) that runs entirely **in-process** — no Postgres server, no `createdb`, no `psql`, no TCP. It provides instant, isolated PostgreSQL databases for testing with automatic transaction rollbacks, context switching, and clean seeding, all backed by ElectricSQL's WASM build of Postgres. It's ideal for local-first development and especially great for GitHub Actions and CI/CD — **no service container required**.
20
+
21
+ Like [`supabase-test`](https://www.npmjs.com/package/supabase-test) and [`drizzle-orm-test`](https://www.npmjs.com/package/drizzle-orm-test), it's a thin `getConnections()` wrapper that composes the existing `pg-cache` / `pgsql-client` seams, so your tests read exactly like `pgsql-test`.
22
+
23
+ ## Install
24
+
25
+ ```sh
26
+ npm install pglite-test
27
+ ```
28
+
29
+ You also install PGlite yourself (it's a peer dependency, so you pin the version):
30
+
31
+ ```sh
32
+ npm install @electric-sql/pglite
33
+ ```
34
+
35
+ ## Features
6
36
 
7
- It follows the same pattern as `drizzle-orm-test` / `supabase-test`: a thin
8
- `getConnections()` wrapper that composes the existing `pg-cache` / `pgsql-client`
9
- seams.
37
+ * 🚀 **Zero infrastructure** — pure WASM, no Postgres server, no Docker, no service container in CI
38
+ * ⚡ **Instant test DBs** — spin up an isolated in-process instance per suite
39
+ * 🔄 **Per-test rollback** — every test runs in its own transaction/savepoint (ref-counted for the single session)
40
+ * 🛡️ **RLS-friendly** — role-based auth via `.setContext()` (full GUC support)
41
+ * 🌱 **pgpm-native seeding** — deploy your real modules with the unmodified pgpm engine via `seed.pgpm()`
42
+ * 🧠 **pgvector & friends** — register WASM extensions (`vector`, `pg_trgm`, …) at construction
43
+ * 🧪 **Compatible with any async runner** — works with `Jest`, `Mocha`, etc.
44
+ * 🧹 **Auto teardown** — no residue, no reboots, just clean exits
10
45
 
11
- - [`@pgpmjs/pglite-adapter`](../pglite-adapter)'s `registerPglite()` routes
12
- `pg-cache`'s `getPgPool()` at PGlite, so `seed.pgpm()` deploys your module into
13
- it with the unmodified pgpm engine.
14
- - `pgsql-client`'s client-factory seam routes `PgTestClient`'s underlying
15
- `pg.Client` at the same PGlite session.
46
+ ## How it works
47
+
48
+ - [`@pgpmjs/pglite-adapter`](https://www.npmjs.com/package/@pgpmjs/pglite-adapter)'s `registerPglite()` routes `pg-cache`'s `getPgPool()` at an in-process PGlite instance, so `seed.pgpm()` deploys your module into it with the **unmodified pgpm engine**.
49
+ - `pgsql-client`'s client-factory seam routes `PgTestClient`'s underlying `pg.Client` at the same PGlite session.
16
50
 
17
51
  ## Usage
18
52
 
@@ -47,32 +81,17 @@ it('queries the pgpm-deployed schema', async () => {
47
81
  });
48
82
  ```
49
83
 
50
- Jest must run with `NODE_OPTIONS=--experimental-vm-modules` (PGlite loads a WASM
51
- module); the package's `test` script sets this.
52
-
53
- ## Single-session model
54
-
55
- PGlite is one in-process session, so `pg` and `db` share it. That differs from
56
- `pgsql-test` (two authenticated connections on a real server):
57
-
58
- - Transaction control is **ref-counted** (`SharedTxn`) so the standard
59
- two-client `beforeEach`/`afterEach` harness emits exactly one
60
- `BEGIN`/`SAVEPOINT`/`ROLLBACK`/`COMMIT` per test. The single-client (`db` only)
61
- pattern also works.
62
- - Role-based RLS uses `setContext({ role })` (i.e. `SET LOCAL role`) on the shared
63
- session rather than separate authenticated connections. Any role you switch to
64
- must exist — create it via `pglite.extensionSql` (e.g.
65
- `['CREATE ROLE authenticated;']`).
66
- - `publish()` (commit-and-continue) is not supported under the shared-session
67
- coordinator.
84
+ Jest must run with `NODE_OPTIONS=--experimental-vm-modules` (PGlite loads a WASM module); the package's `test` script sets this.
68
85
 
69
86
  ## Options
70
87
 
71
88
  ```typescript
89
+ import { vector } from '@electric-sql/pglite-pgvector';
90
+
72
91
  await getConnections(
73
92
  {
74
93
  pglite: {
75
- dataDir: undefined, // in-memory by default
94
+ dataDir: undefined, // in-memory by default
76
95
  extensions: { vector }, // WASM extensions (e.g. pglite-pgvector)
77
96
  extensionSql: [ // run once after ready
78
97
  'CREATE EXTENSION IF NOT EXISTS vector;',
@@ -84,6 +103,20 @@ await getConnections(
84
103
  );
85
104
  ```
86
105
 
106
+ ## Single-session model
107
+
108
+ PGlite is one in-process session, so `pg` and `db` share it. That differs from `pgsql-test` (two authenticated connections on a real server):
109
+
110
+ - Transaction control is **ref-counted** (`SharedTxn`) so the standard two-client `beforeEach`/`afterEach` harness emits exactly one `BEGIN`/`SAVEPOINT`/`ROLLBACK`/`COMMIT` per test. The single-client (`db` only) pattern also works.
111
+ - Role-based RLS uses `setContext({ role })` (i.e. `SET LOCAL role`) on the shared session rather than separate authenticated connections. Any role you switch to must exist — create it via `pglite.extensionSql` (e.g. `['CREATE ROLE authenticated;']`).
112
+ - `publish()` (commit-and-continue) is not supported under the shared-session coordinator.
113
+
114
+ ## Related
115
+
116
+ - [`@pgpmjs/pglite-adapter`](https://www.npmjs.com/package/@pgpmjs/pglite-adapter) — the in-process PGlite driver that both this package and the pgpm engine ride on.
117
+ - [`pgsql-test`](https://www.npmjs.com/package/pgsql-test) — the server-backed original this mirrors.
118
+ - [`supabase-test`](https://www.npmjs.com/package/supabase-test) · [`drizzle-orm-test`](https://www.npmjs.com/package/drizzle-orm-test) — sibling `getConnections()` wrappers.
119
+
87
120
  ---
88
121
 
89
122
  ## Education and Tutorials
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pglite-test",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "author": "Constructive <developers@constructive.io>",
5
5
  "description": "Drop-in pgsql-test getConnections backed by an in-process PGlite instance — no Postgres server, instance-per-suite isolation",
6
6
  "main": "index.js",
@@ -46,15 +46,15 @@
46
46
  "makage": "^0.3.0"
47
47
  },
48
48
  "dependencies": {
49
- "@pgpmjs/env": "^2.26.1",
50
- "@pgpmjs/pglite-adapter": "^0.1.0",
51
- "pg-cache": "^3.14.0",
49
+ "@pgpmjs/env": "^2.26.2",
50
+ "@pgpmjs/pglite-adapter": "^0.1.1",
51
+ "pg-cache": "^3.14.1",
52
52
  "pg-env": "^1.17.0",
53
- "pgsql-client": "^3.20.0",
54
- "pgsql-test": "^4.18.3"
53
+ "pgsql-client": "^3.20.1",
54
+ "pgsql-test": "^4.18.4"
55
55
  },
56
56
  "peerDependencies": {
57
57
  "@electric-sql/pglite": ">=0.5.0"
58
58
  },
59
- "gitHead": "7cbe15fac21a9345b169203ba9542ba9a50c866c"
59
+ "gitHead": "87e65cd31d4e23c367ca4d398416b19ac863c7de"
60
60
  }