pgsql-test 2.0.6 → 2.0.7
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.
- package/README.md +38 -16
- package/package.json +28 -3
package/README.md
CHANGED
|
@@ -16,7 +16,6 @@
|
|
|
16
16
|
</a>
|
|
17
17
|
</p>
|
|
18
18
|
|
|
19
|
-
|
|
20
19
|
`pgsql-test` gives you instant, isolated PostgreSQL databases for each test — with automatic transaction rollbacks, context switching, and clean seeding. Forget flaky tests and brittle environments. Write real SQL. Get real coverage. Stay fast.
|
|
21
20
|
|
|
22
21
|
## Install
|
|
@@ -52,6 +51,7 @@ Part of the [LaunchQL](https://github.com/launchql) ecosystem, `pgsql-test` is b
|
|
|
52
51
|
6. [Usage Examples](#usage-examples)
|
|
53
52
|
* [Basic Setup](#-basic-setup)
|
|
54
53
|
* [Role-Based Context](#-role-based-context)
|
|
54
|
+
* [Seeding System](#-seeding-system)
|
|
55
55
|
* [SQL File Seeding](#-sql-file-seeding)
|
|
56
56
|
* [Programmatic Seeding](#-programmatic-seeding)
|
|
57
57
|
* [CSV Seeding](#️-csv-seeding)
|
|
@@ -224,6 +224,27 @@ This approach enables testing various access patterns:
|
|
|
224
224
|
|
|
225
225
|
> **Note:** While this interface helps simulate RBAC for testing, your production server should manage user/role claims via secure authentication tokens, typically by setting values like `current_setting('jwt.claims.user_id')` through proper authentication middleware.
|
|
226
226
|
|
|
227
|
+
### 🌱 Seeding System
|
|
228
|
+
|
|
229
|
+
The second argument to `getConnections()` is an optional array of `SeedAdapter` objects:
|
|
230
|
+
|
|
231
|
+
```ts
|
|
232
|
+
const { db, teardown } = await getConnections(getConnectionOptions, seedAdapters);
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
This array lets you fully customize how your test database is seeded. You can compose multiple strategies:
|
|
236
|
+
|
|
237
|
+
* [`seed.sqlfile()`](#-sql-file-seeding) – Execute raw `.sql` files from disk
|
|
238
|
+
* [`seed.fn()`](#-programmatic-seeding) – Run JavaScript/TypeScript logic to programmatically insert data
|
|
239
|
+
* [`seed.csv()`](#️-csv-seeding) – Load tabular data from CSV files
|
|
240
|
+
* [`seed.json()`](#️-json-seeding) – Use in-memory objects as seed data
|
|
241
|
+
* [`seed.sqitch()`](#️-sqitch-seeding) – Deploy a Sqitch-compatible migration project
|
|
242
|
+
* [`seed.launchql()`](#-launchql-seeding) – Apply a LaunchQL module using `deployFast()` (compatible with sqitch)
|
|
243
|
+
|
|
244
|
+
> ✨ **Default Behavior:** If no `SeedAdapter[]` is passed, LaunchQL seeding is assumed. This makes `pgsql-test` zero-config for LaunchQL-based projects.
|
|
245
|
+
|
|
246
|
+
This composable system allows you to mix-and-match data setup strategies for flexible, realistic, and fast database tests.
|
|
247
|
+
|
|
227
248
|
### 🔌 SQL File Seeding
|
|
228
249
|
|
|
229
250
|
Use `.sql` files to set up your database state before tests:
|
|
@@ -391,19 +412,28 @@ beforeAll(async () => {
|
|
|
391
412
|
seed.sqitch(cwd)
|
|
392
413
|
]));
|
|
393
414
|
});
|
|
394
|
-
|
|
395
|
-
it('runs a schema query', async () => {
|
|
396
|
-
const res = await db.query('SELECT COUNT(*) FROM myapp.users');
|
|
397
|
-
expect(+res.rows[0].count).toBeGreaterThanOrEqual(0);
|
|
398
|
-
});
|
|
399
415
|
```
|
|
400
416
|
|
|
401
417
|
This works for any Sqitch-compatible module, now accelerated by LaunchQL's deployment tooling.
|
|
402
418
|
|
|
403
419
|
## 🚀 LaunchQL Seeding
|
|
404
420
|
|
|
405
|
-
|
|
406
|
-
|
|
421
|
+
If your project uses LaunchQL modules with a precompiled `sqitch.plan`, you can use `pgsql-test` with **zero configuration**. Just call `getConnections()` — and it *just works*:
|
|
422
|
+
|
|
423
|
+
```ts
|
|
424
|
+
import { getConnections } from 'pgsql-test';
|
|
425
|
+
|
|
426
|
+
let db, teardown;
|
|
427
|
+
|
|
428
|
+
beforeAll(async () => {
|
|
429
|
+
({ db, teardown } = await getConnections()); // 🚀 LaunchQL deployFast() is used automatically - up to 10x faster than traditional Sqitch!
|
|
430
|
+
});
|
|
431
|
+
```
|
|
432
|
+
|
|
433
|
+
This works out of the box because `pgsql-test` uses the high-speed `deployFast()` function by default, applying any compiled LaunchQL schema located in the current working directory (`process.cwd()`).
|
|
434
|
+
|
|
435
|
+
If you want to specify a custom path to your LaunchQL module, use `seed.launchql()` explicitly:
|
|
436
|
+
|
|
407
437
|
|
|
408
438
|
```ts
|
|
409
439
|
import path from 'path';
|
|
@@ -416,16 +446,8 @@ beforeAll(async () => {
|
|
|
416
446
|
seed.launchql(cwd) // uses deployFast() - up to 10x faster than traditional Sqitch!
|
|
417
447
|
]));
|
|
418
448
|
});
|
|
419
|
-
|
|
420
|
-
it('creates user records', async () => {
|
|
421
|
-
await db.query(`INSERT INTO myapp.users (username, email) VALUES ('testuser', 'test@example.com')`);
|
|
422
|
-
const res = await db.query(`SELECT COUNT(*) FROM myapp.users`);
|
|
423
|
-
expect(+res.rows[0].count).toBeGreaterThan(0);
|
|
424
|
-
});
|
|
425
449
|
```
|
|
426
450
|
|
|
427
|
-
This is the fastest way to bring up a ready-to-query schema from a compiled LaunchQL module - perfect for both development and CI environments.
|
|
428
|
-
|
|
429
451
|
## Why LaunchQL's Approach?
|
|
430
452
|
|
|
431
453
|
LaunchQL provides the best of both worlds:
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pgsql-test",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.7",
|
|
4
4
|
"author": "Dan Lynch <pyramation@gmail.com>",
|
|
5
|
-
"description": "PostgreSQL
|
|
5
|
+
"description": "pgsql-test offers isolated, role-aware, and rollback-friendly PostgreSQL environments for integration tests — giving developers realistic test coverage without external state pollution",
|
|
6
6
|
"main": "index.js",
|
|
7
7
|
"module": "esm/index.js",
|
|
8
8
|
"types": "index.d.ts",
|
|
@@ -19,6 +19,31 @@
|
|
|
19
19
|
"bugs": {
|
|
20
20
|
"url": "https://github.com/launchql/launchql/issues"
|
|
21
21
|
},
|
|
22
|
+
"keywords": [
|
|
23
|
+
"postgres",
|
|
24
|
+
"postgresql",
|
|
25
|
+
"testing",
|
|
26
|
+
"integration-tests",
|
|
27
|
+
"database-testing",
|
|
28
|
+
"pg",
|
|
29
|
+
"rls",
|
|
30
|
+
"role-based-access",
|
|
31
|
+
"test-database",
|
|
32
|
+
"test-runner",
|
|
33
|
+
"jest",
|
|
34
|
+
"mocha",
|
|
35
|
+
"sqitch",
|
|
36
|
+
"launchql",
|
|
37
|
+
"typeorm",
|
|
38
|
+
"knex",
|
|
39
|
+
"seed",
|
|
40
|
+
"fixtures",
|
|
41
|
+
"transactions",
|
|
42
|
+
"rollback",
|
|
43
|
+
"node-postgres",
|
|
44
|
+
"pg-pool",
|
|
45
|
+
"pg-client"
|
|
46
|
+
],
|
|
22
47
|
"scripts": {
|
|
23
48
|
"copy": "copyfiles -f ../../LICENSE README.md package.json dist",
|
|
24
49
|
"clean": "rimraf dist/**",
|
|
@@ -42,5 +67,5 @@
|
|
|
42
67
|
"pg": "^8.16.0",
|
|
43
68
|
"pg-copy-streams": "^6.0.6"
|
|
44
69
|
},
|
|
45
|
-
"gitHead": "
|
|
70
|
+
"gitHead": "9b9c34caa3b8f21c9996f23495013cfe88612672"
|
|
46
71
|
}
|