supabase-test 0.0.13 → 0.0.14
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 +142 -25
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -56,7 +56,6 @@ Part of the [LaunchQL](https://github.com/launchql) ecosystem, `pgsql-test` is b
|
|
|
56
56
|
* [Programmatic Seeding](#-programmatic-seeding)
|
|
57
57
|
* [CSV Seeding](#️-csv-seeding)
|
|
58
58
|
* [JSON Seeding](#️-json-seeding)
|
|
59
|
-
* [Sqitch Seeding](#️-sqitch-seeding)
|
|
60
59
|
* [LaunchQL Seeding](#-launchql-seeding)
|
|
61
60
|
7. [`getConnections() Options` ](#getconnections-options)
|
|
62
61
|
8. [Disclaimer](#disclaimer)
|
|
@@ -238,16 +237,48 @@ This array lets you fully customize how your test database is seeded. You can co
|
|
|
238
237
|
* [`seed.fn()`](#-programmatic-seeding) – Run JavaScript/TypeScript logic to programmatically insert data
|
|
239
238
|
* [`seed.csv()`](#️-csv-seeding) – Load tabular data from CSV files
|
|
240
239
|
* [`seed.json()`](#️-json-seeding) – Use in-memory objects as seed data
|
|
241
|
-
* [`seed.
|
|
242
|
-
* [`seed.launchql()`](#-launchql-seeding) – Apply a LaunchQL module using `deployFast()` (compatible with sqitch)
|
|
240
|
+
* [`seed.launchql()`](#-launchql-seeding) – Apply a LaunchQL project or set of packages (compatible with sqitch)
|
|
243
241
|
|
|
244
242
|
> ✨ **Default Behavior:** If no `SeedAdapter[]` is passed, LaunchQL seeding is assumed. This makes `supabase-test` zero-config for LaunchQL-based projects.
|
|
245
243
|
|
|
246
244
|
This composable system allows you to mix-and-match data setup strategies for flexible, realistic, and fast database tests.
|
|
247
245
|
|
|
246
|
+
#### Two Seeding Patterns
|
|
247
|
+
|
|
248
|
+
You can seed data using either approach:
|
|
249
|
+
|
|
250
|
+
**1. Adapter Pattern** (setup phase via `getConnections`)
|
|
251
|
+
```ts
|
|
252
|
+
const { db, teardown } = await getConnections({}, [
|
|
253
|
+
seed.json({ 'users': [{ id: 1, name: 'Alice' }] })
|
|
254
|
+
]);
|
|
255
|
+
```
|
|
256
|
+
|
|
257
|
+
**2. Direct Load Methods** (runtime via `PgTestClient`)
|
|
258
|
+
```ts
|
|
259
|
+
await db.loadJson({ 'users': [{ id: 1, name: 'Alice' }] });
|
|
260
|
+
await db.loadCsv({ 'users': '/path/to/users.csv' });
|
|
261
|
+
await db.loadSql(['/path/to/schema.sql']);
|
|
262
|
+
```
|
|
263
|
+
|
|
264
|
+
> **Note:** `loadCsv()` and `loadLaunchql()` do not apply RLS context (PostgreSQL limitation). Use `loadJson()` or `loadSql()` for RLS-aware seeding.
|
|
265
|
+
|
|
248
266
|
### 🔌 SQL File Seeding
|
|
249
267
|
|
|
250
|
-
|
|
268
|
+
**Adapter Pattern:**
|
|
269
|
+
```ts
|
|
270
|
+
const { db, teardown } = await getConnections({}, [
|
|
271
|
+
seed.sqlfile(['schema.sql', 'fixtures.sql'])
|
|
272
|
+
]);
|
|
273
|
+
```
|
|
274
|
+
|
|
275
|
+
**Direct Load Method:**
|
|
276
|
+
```ts
|
|
277
|
+
await db.loadSql(['schema.sql', 'fixtures.sql']);
|
|
278
|
+
```
|
|
279
|
+
|
|
280
|
+
<details>
|
|
281
|
+
<summary>Full example</summary>
|
|
251
282
|
|
|
252
283
|
```ts
|
|
253
284
|
import path from 'path';
|
|
@@ -272,9 +303,27 @@ afterAll(async () => {
|
|
|
272
303
|
});
|
|
273
304
|
```
|
|
274
305
|
|
|
306
|
+
</details>
|
|
307
|
+
|
|
275
308
|
### 🧠 Programmatic Seeding
|
|
276
309
|
|
|
277
|
-
|
|
310
|
+
**Adapter Pattern:**
|
|
311
|
+
```ts
|
|
312
|
+
const { db, teardown } = await getConnections({}, [
|
|
313
|
+
seed.fn(async ({ pg }) => {
|
|
314
|
+
await pg.query(`INSERT INTO users (name) VALUES ('Seeded User')`);
|
|
315
|
+
})
|
|
316
|
+
]);
|
|
317
|
+
```
|
|
318
|
+
|
|
319
|
+
**Direct Load Method:**
|
|
320
|
+
```ts
|
|
321
|
+
// Use any PgTestClient method directly
|
|
322
|
+
await db.query(`INSERT INTO users (name) VALUES ('Seeded User')`);
|
|
323
|
+
```
|
|
324
|
+
|
|
325
|
+
<details>
|
|
326
|
+
<summary>Full example</summary>
|
|
278
327
|
|
|
279
328
|
```ts
|
|
280
329
|
import { getConnections, seed } from 'supabase-test';
|
|
@@ -293,8 +342,33 @@ beforeAll(async () => {
|
|
|
293
342
|
});
|
|
294
343
|
```
|
|
295
344
|
|
|
345
|
+
</details>
|
|
346
|
+
|
|
296
347
|
## 🗃️ CSV Seeding
|
|
297
348
|
|
|
349
|
+
**Adapter Pattern:**
|
|
350
|
+
```ts
|
|
351
|
+
const { db, teardown } = await getConnections({}, [
|
|
352
|
+
seed.csv({
|
|
353
|
+
'users': '/path/to/users.csv',
|
|
354
|
+
'posts': '/path/to/posts.csv'
|
|
355
|
+
})
|
|
356
|
+
]);
|
|
357
|
+
```
|
|
358
|
+
|
|
359
|
+
**Direct Load Method:**
|
|
360
|
+
```ts
|
|
361
|
+
await db.loadCsv({
|
|
362
|
+
'users': '/path/to/users.csv',
|
|
363
|
+
'posts': '/path/to/posts.csv'
|
|
364
|
+
});
|
|
365
|
+
```
|
|
366
|
+
|
|
367
|
+
> **Note:** CSV loading uses PostgreSQL COPY which does not support RLS context.
|
|
368
|
+
|
|
369
|
+
<details>
|
|
370
|
+
<summary>Full example</summary>
|
|
371
|
+
|
|
298
372
|
You can load tables from CSV files using `seed.csv({ ... })`. CSV headers must match the table column names exactly. This is useful for loading stable fixture data for integration tests or CI environments.
|
|
299
373
|
|
|
300
374
|
```ts
|
|
@@ -344,8 +418,35 @@ it('has loaded rows', async () => {
|
|
|
344
418
|
});
|
|
345
419
|
```
|
|
346
420
|
|
|
421
|
+
</details>
|
|
422
|
+
|
|
347
423
|
## 🗃️ JSON Seeding
|
|
348
424
|
|
|
425
|
+
**Adapter Pattern:**
|
|
426
|
+
```ts
|
|
427
|
+
const { db, teardown } = await getConnections({}, [
|
|
428
|
+
seed.json({
|
|
429
|
+
'custom.users': [
|
|
430
|
+
{ id: 1, name: 'Alice' },
|
|
431
|
+
{ id: 2, name: 'Bob' }
|
|
432
|
+
]
|
|
433
|
+
})
|
|
434
|
+
]);
|
|
435
|
+
```
|
|
436
|
+
|
|
437
|
+
**Direct Load Method:**
|
|
438
|
+
```ts
|
|
439
|
+
await db.loadJson({
|
|
440
|
+
'custom.users': [
|
|
441
|
+
{ id: 1, name: 'Alice' },
|
|
442
|
+
{ id: 2, name: 'Bob' }
|
|
443
|
+
]
|
|
444
|
+
});
|
|
445
|
+
```
|
|
446
|
+
|
|
447
|
+
<details>
|
|
448
|
+
<summary>Full example</summary>
|
|
449
|
+
|
|
349
450
|
You can seed tables using in-memory JSON objects. This is useful when you want fast, inline fixtures without managing external files.
|
|
350
451
|
|
|
351
452
|
```ts
|
|
@@ -399,28 +500,32 @@ it('has loaded rows', async () => {
|
|
|
399
500
|
});
|
|
400
501
|
```
|
|
401
502
|
|
|
402
|
-
|
|
503
|
+
</details>
|
|
403
504
|
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
You can seed your test database using a Sqitch project but with significantly improved performance by leveraging LaunchQL's TypeScript deployment engine:
|
|
505
|
+
## 🚀 LaunchQL Seeding
|
|
407
506
|
|
|
507
|
+
**Zero Configuration (Default):**
|
|
408
508
|
```ts
|
|
409
|
-
|
|
410
|
-
|
|
509
|
+
// LaunchQL migrate is used automatically
|
|
510
|
+
const { db, teardown } = await getConnections();
|
|
511
|
+
```
|
|
411
512
|
|
|
412
|
-
|
|
513
|
+
**Adapter Pattern (Custom Path):**
|
|
514
|
+
```ts
|
|
515
|
+
const { db, teardown } = await getConnections({}, [
|
|
516
|
+
seed.launchql('/path/to/launchql', true) // with cache
|
|
517
|
+
]);
|
|
518
|
+
```
|
|
413
519
|
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
]));
|
|
418
|
-
});
|
|
520
|
+
**Direct Load Method:**
|
|
521
|
+
```ts
|
|
522
|
+
await db.loadLaunchql('/path/to/launchql', true); // with cache
|
|
419
523
|
```
|
|
420
524
|
|
|
421
|
-
|
|
525
|
+
> **Note:** LaunchQL deployment has its own client handling and does not apply RLS context.
|
|
422
526
|
|
|
423
|
-
|
|
527
|
+
<details>
|
|
528
|
+
<summary>Full example</summary>
|
|
424
529
|
|
|
425
530
|
If your project uses LaunchQL modules with a precompiled `launchql.plan`, you can use `supabase-test` with **zero configuration**. Just call `getConnections()` — and it *just works*:
|
|
426
531
|
|
|
@@ -430,14 +535,13 @@ import { getConnections } from 'supabase-test';
|
|
|
430
535
|
let db, teardown;
|
|
431
536
|
|
|
432
537
|
beforeAll(async () => {
|
|
433
|
-
({ db, teardown } = await getConnections()); //
|
|
538
|
+
({ db, teardown } = await getConnections()); // LaunchQL module is deployed automatically
|
|
434
539
|
});
|
|
435
540
|
```
|
|
436
541
|
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
If you want to specify a custom path to your LaunchQL module, use `seed.launchql()` explicitly:
|
|
542
|
+
LaunchQL uses Sqitch-compatible syntax with a TypeScript-based migration engine. By default, `supabase-test` automatically deploys any LaunchQL module found in the current working directory (`process.cwd()`).
|
|
440
543
|
|
|
544
|
+
To specify a custom path to your LaunchQL module, use `seed.launchql()` explicitly:
|
|
441
545
|
|
|
442
546
|
```ts
|
|
443
547
|
import path from 'path';
|
|
@@ -447,11 +551,24 @@ const cwd = path.resolve(__dirname, '../path/to/launchql');
|
|
|
447
551
|
|
|
448
552
|
beforeAll(async () => {
|
|
449
553
|
({ db, teardown } = await getConnections({}, [
|
|
450
|
-
seed.launchql(cwd)
|
|
554
|
+
seed.launchql(cwd)
|
|
451
555
|
]));
|
|
452
556
|
});
|
|
453
557
|
```
|
|
454
558
|
|
|
559
|
+
</details>
|
|
560
|
+
|
|
561
|
+
## Why LaunchQL's Approach?
|
|
562
|
+
|
|
563
|
+
LaunchQL provides the best of both worlds:
|
|
564
|
+
|
|
565
|
+
1. **Sqitch Compatibility**: Keep your familiar Sqitch syntax and migration approach
|
|
566
|
+
2. **TypeScript Performance**: Our TS-rewritten deployment engine delivers up to 10x faster schema deployments
|
|
567
|
+
3. **Developer Experience**: Tight feedback loops with near-instant schema setup for tests
|
|
568
|
+
4. **CI Optimization**: Dramatically reduced test suite run times with optimized deployment
|
|
569
|
+
|
|
570
|
+
By maintaining Sqitch compatibility while supercharging performance, LaunchQL enables you to keep your existing migration patterns while enjoying the speed benefits of our TypeScript engine.
|
|
571
|
+
|
|
455
572
|
## Why LaunchQL's Approach?
|
|
456
573
|
|
|
457
574
|
LaunchQL provides the best of both worlds:
|
|
@@ -472,7 +589,7 @@ This table documents the available options for the `getConnections` function. Th
|
|
|
472
589
|
| Option | Type | Default | Description |
|
|
473
590
|
| ------------------------ | ---------- | ---------------- | --------------------------------------------------------------------------- |
|
|
474
591
|
| `db.extensions` | `string[]` | `[]` | Array of PostgreSQL extensions to include in the test database |
|
|
475
|
-
| `db.cwd` | `string` | `process.cwd()` | Working directory used for LaunchQL
|
|
592
|
+
| `db.cwd` | `string` | `process.cwd()` | Working directory used for LaunchQL or Sqitch projects |
|
|
476
593
|
| `db.connection.user` | `string` | `'app_user'` | User for simulating RLS via `setContext()` |
|
|
477
594
|
| `db.connection.password` | `string` | `'app_password'` | Password for RLS test user |
|
|
478
595
|
| `db.connection.role` | `string` | `'anonymous'` | Default role used during `setContext()` |
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "supabase-test",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.14",
|
|
4
4
|
"author": "Interweb <developers@interweb.io>",
|
|
5
5
|
"description": "supabase-test offers isolated, role-aware, and rollback-friendly PostgreSQL environments for integration tests with Supabase defaults baked in",
|
|
6
6
|
"main": "index.js",
|
|
@@ -52,9 +52,9 @@
|
|
|
52
52
|
"test:watch": "jest --watch"
|
|
53
53
|
},
|
|
54
54
|
"dependencies": {
|
|
55
|
-
"@launchql/types": "^2.
|
|
55
|
+
"@launchql/types": "^2.7.0",
|
|
56
56
|
"pg-env": "^1.1.1",
|
|
57
|
-
"pgsql-test": "^2.
|
|
57
|
+
"pgsql-test": "^2.12.0"
|
|
58
58
|
},
|
|
59
|
-
"gitHead": "
|
|
59
|
+
"gitHead": "7a71d63b0ac5b0ea13f2c55cbb09d5fc0957a4f5"
|
|
60
60
|
}
|