Prisma Test Utils
raw JSON → 0.4.1 verified Fri May 01 auth: no javascript deprecated
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+).
Common errors
error Cannot find module '@generated/prisma-test-utils' or '@generated/prisma-test-utils/seed' ↓
cause 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.
error TypeError: seed is not a function ↓
cause Incorrect import (named instead of default) or missing generated module
fix
Use default import: import seed from '@generated/prisma-test-utils/seed'
error Error: Cannot find module '@prisma/lift' ↓
cause Missing peer dependency @prisma/lift
fix
Install all peer deps: npm install @prisma/client @prisma/lift prisma2
Warnings
deprecated This 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.
breaking Peer 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.
gotcha Generated 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.
gotcha The 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.
deprecated Pool 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.
Install
npm install prisma-test-utils yarn add prisma-test-utils pnpm add prisma-test-utils Imports
- seed wrong
import { seed } from 'prisma-test-utils'correctimport seed from '@generated/prisma-test-utils/seed' - SQLitePool wrong
const { SQLitePool } = require('prisma-test-utils')correctimport SQLitePool from '@generated/prisma-test-utils' - Pool wrong
const Pool = require('prisma-test-utils')correctimport { Pool } from '@generated/prisma-test-utils'
Quickstart
// 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)