@flefebvre/prisma-test-helper 0.1.0 → 0.2.0

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 +37 -13
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -23,7 +23,9 @@ back.
23
23
 
24
24
  ## Requirements
25
25
 
26
- - Node >= 20, ESM project
26
+ - Node >= 20. The package ships ESM only, but your project need not be — the wiring runs
27
+ under Vitest, which transforms modules through Vite, so a CommonJS project (a stock
28
+ Next.js app, say) works too.
27
29
  - Docker (or another container runtime Testcontainers can reach)
28
30
  - Peer dependencies: `vitest` ^4 and `prisma` ^7, with your migrations committed
29
31
  (`prisma migrate deploy` is what the harness runs)
@@ -116,7 +118,8 @@ vi.mock("../src/db/client.js", async (importOriginal) => {
116
118
 
117
119
  The factory returns `{ db }` because the client module above exports only `db`. If yours
118
120
  exports anything else — types, a re-exported `Prisma` namespace, helpers — spread the
119
- original too, or those exports become `undefined` at every call site:
121
+ original too, or every call site touching one of them fails with Vitest's
122
+ `No "Prisma" export is defined on the "../src/db/client.js" mock`:
120
123
 
121
124
  ```ts
122
125
  return { ...actual, db: installTestTransaction(actual.db, databaseUrl, databaseName) };
@@ -220,9 +223,9 @@ Opts a test file into the database. Wraps every test in its own transaction: a
220
223
 
221
224
  ### `isDatabaseSetUp(): boolean`
222
225
 
223
- Whether `setupDatabase()` has run in this file. Factories read it to fail loudly when a
224
- file forgot to opt in, rather than run outside any transaction — where their writes would
225
- commit.
226
+ Whether `setupDatabase()` has run in this file. Useful in your own fixture helpers read
227
+ it to fail loudly when a file forgot to opt in, rather than let them run outside any
228
+ transaction, where their writes would commit.
226
229
 
227
230
  ```ts
228
231
  if (!isDatabaseSetUp()) {
@@ -233,16 +236,18 @@ if (!isDatabaseSetUp()) {
233
236
  ### `registerResetHook(hook): void`
234
237
 
235
238
  Register a callback to run in every `beforeEach`, after the transaction opens. This is the
236
- seam factories plug into. Hooks receive `{ testName, seed }`, where `seed` is a
237
- deterministic 32-bit hash (FNV-1a) of the test name alone never the worker id, the file,
238
- or the run order. Rerunning one test with `-t` therefore hands it the same seed a
239
- full-suite run did.
239
+ seam for wiring your own fixture and test-data libraries into the per-test lifecycle
240
+ reseeding a random generator, resetting a counter, priming a fixture registry. Hooks
241
+ receive `{ testName, seed }`, where `seed` is a deterministic 32-bit hash (FNV-1a) of the
242
+ test name alone — never the worker id, the file, or the run order. Rerunning one test with
243
+ `-t` therefore hands it the same seed a full-suite run did.
240
244
 
241
- Faker is deliberately **not** a dependency of this package; the harness only hands you the
242
- seed.
245
+ No data-generation library is a dependency of this package; the harness only hands you the
246
+ seed, and you decide what to do with it. Below, Faker — but anything that takes a numeric
247
+ seed works the same way.
243
248
 
244
249
  ```ts
245
- // tests/factories.ts
250
+ // tests/fixtures.ts
246
251
  import { faker } from "@faker-js/faker";
247
252
 
248
253
  import { registerResetHook } from "@flefebvre/prisma-test-helper";
@@ -252,7 +257,7 @@ registerResetHook(({ seed }) => {
252
257
  faker.seed(seed);
253
258
  });
254
259
 
255
- export function buildAuthor() {
260
+ export function createAuthor() {
256
261
  return db.author.create({ data: { name: faker.person.fullName() } });
257
262
  }
258
263
  ```
@@ -292,6 +297,25 @@ Every error below comes from this package. Find the one you got.
292
297
  | `a test transaction is already live —` | `setupDatabase()` was called twice in one file. |
293
298
  | `the database was touched with no test transaction live —` | The file never called `setupDatabase()`, or data was built in `beforeAll` instead of inside a test. |
294
299
 
300
+ ## Agent skills
301
+
302
+ If you use an AI coding agent (Claude Code, Cursor, Codex, …), this repo ships two installable skills that teach it this harness — split so you keep only what you still need:
303
+
304
+ | Skill | What it does | Keep it? |
305
+ | ---------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------- |
306
+ | [`prisma-test-helper-setup`](skills/prisma-test-helper-setup/SKILL.md) | Wires the harness into a project: installs the package, finds your Prisma client module, scaffolds the five files above (merging existing configs rather than clobbering them), pins the Postgres image from your `docker-compose.yml`, and verifies with a smoke test. | Remove once wired |
307
+ | [`prisma-test-helper`](skills/prisma-test-helper/SKILL.md) | The rules for writing tests in a wired project: the per-file `setupDatabase()` opt-in, where test data belongs, the Reset Hook seam, and every guard error above with its fix. | Keep installed |
308
+
309
+ ```sh
310
+ # wiring a project for the first time
311
+ npx skills add flolefebvre/prisma-test-helper --skill prisma-test-helper-setup
312
+
313
+ # writing tests in a project that is already wired
314
+ npx skills add flolefebvre/prisma-test-helper --skill prisma-test-helper
315
+ ```
316
+
317
+ (Uses the [skills CLI](https://github.com/vercel-labs/skills); or just copy the skill directory into your agent's skills directory, e.g. `.claude/skills/`.)
318
+
295
319
  ## License
296
320
 
297
321
  MIT
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flefebvre/prisma-test-helper",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "description": "Throwaway-Postgres test harness for Prisma + Vitest: one container per run, one database per worker. Postgres-only.",
5
5
  "type": "module",
6
6
  "license": "MIT",