Registry / testing / prisma-test-utils

prisma-test-utils

JSON →
library0.4.1jsnpmunverified

A testing utility library for Prisma (formerly Prisma 2) that generates seed data and database pool management based on your Prisma schema. Version 0.4.1 (latest) is the current stable release, with sparse updates since 2020. The project is temporarily unmaintained as noted in the README. Key features include automatic seed data generation with customizable factories, isolated per-test databases via connection pooling, and full TypeScript type safety. Differentiates from manual seeding by being data-model agnostic and automatically adapting to schema changes. Requires peer dependencies @prisma/client, @prisma/lift, and prisma2, though these are now outdated as Prisma has evolved significantly (Prisma 4+).

npm install prisma-test-utils
INSTALL
IMPORT
SIG · PRISMA-TEST-UTILS
P
prisma-test-utils
testingjavascriptv0.4.1
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

seed
import seed from '@generated/prisma-test-utils/seed'
import { seed } from 'prisma-test-utils'
Default import from generated path, not from the npm package directly. Path depends on generator output configuration.
SQLitePool
import SQLitePool from '@generated/prisma-test-utils'
const { SQLitePool } = require('prisma-test-utils')
Default import of pool class, also available as named export Pool. Path is generated, typically under node_modules/@generated.
Pool
import { Pool } from '@generated/prisma-test-utils'
const Pool = require('prisma-test-utils')
Named export for the base Pool class. Available as both default and named export.

Configures the generator, seeds 10 Post records with faker-generated titles, and queries them using the Prisma client.

// schema.prisma generator testutils { provider = "prisma-test-utils" output = "node_modules/@generated/prisma-test-utils" } // test.ts import Photon from '@generated/photon' import seed from '@generated/prisma-test-utils/seed' async function run() { const client = new Photon({ datasources: { db: { url: 'file:./dev.db' } } }) await seed(client, bag => ({ Post: { amount: 10, factory: { title: bag.faker.sentence, published: true, }, }, })) const posts = await client.posts.findMany() console.log(posts.length) // 10 await client.$disconnect() } run().catch(console.error)
Debug
Known issues
deprecatedThis project is temporarily unmaintained and uses outdated Prisma v2 APIs
fix
Consider using prisma/seed or custom seed scripts with Prisma 4+. Also explore alternatives like jest-prisma or prisma-seed.
affects: >=0.0.0
breakingPeer dependency requirements include prisma2, @prisma/lift, and @prisma/client, all of which are outdated
fix
Use Prisma 2.x (prisma2) for compatibility. Cannot be used with Prisma 3+ without modifications.
affects: >=0.0.0
gotchaGenerated imports rely on specific output path (e.g., node_modules/@generated/prisma-test-utils) and won't work if generator config changes
fix
Ensure generator output path matches your import path exactly. Use tsconfig paths or jest moduleNameMapper as needed.
affects: >=0.0.0
gotchaThe seed factory function uses kit (bag) parameter that provides faker.js and must be typed as any or manually typed
fix
Type the bag parameter explicitly: (bag: any) => ({...}) or use generated types if available.
affects: >=0.0.0
deprecatedPool classes (SQLitePool, etc.) are no longer necessary with modern Prisma testing strategies
fix
Use transaction rollback or isolated Prisma datamodels per test instead of database pooling.
affects: >=0.0.0
Errors
Common errors & fixes
Cannot find module '@generated/prisma-test-utils' or '@generated/prisma-test-utils/seed'
Missing prisma generate step or incorrect generator output path
fix
Run 'prisma generate' after adding generator testutils to schema.prisma. Verify output path matches your imports.
TypeError: seed is not a function
Incorrect import (named instead of default) or missing generated module
fix
Use default import: import seed from '@generated/prisma-test-utils/seed'
Error: Cannot find module '@prisma/lift'
Missing peer dependency @prisma/lift
fix
Install all peer deps: npm install @prisma/client @prisma/lift prisma2
Upgrade
Version history
0.4.1latest on npm
Audit
Dependencies
@prisma/clientrequiredRuntime peer dependency for database client operations
@prisma/liftrequiredPeer dependency for database migrations (outdated, replaced by @prisma/migrate in newer Prisma)
prisma2requiredPeer dependency for Prisma CLI (outdated, replaced by prisma in newer versions)
@prisma/generator-helperrequiredAdded as regular dependency in v0.4.1 for generator functionality
Agent activity
4 hits · last 30 days
node
4
Resources
prisma-test-utils — npm install prisma-test-utils · libregistry