🃏 prisma-test-utils
⚠️ This project is temporarily unmaintained. Please reach out in the
#prisma2-preview
channel on the Prisma Slack if you're interested in collaborating on it. We're planning to pick up development soon again (see this issue).
In testing workflows, generating seed data usually includes a lot of boilerplate. We rely on hardcoded fixtures that need to be migrated with changing code.
prisma-test-utils
solve that by generating test util functions based on your Prisma schema. As your application evolves, the generated data also evolves deterministically.
Features
- 🙈 Data model agnostic: Optimised for you datamodel.
- 🦑 Flexible: Cherry picked default settings.
- 🐶 Out-of-the-box usage: Plug-in generator for your Prisma schema.
- 🐠 Seeds mock data: Populates your database with mock data.
- 🦋 Per-test database: Creates an isolated database for each test.
Installation
No installation! Comes preinstalled with prisma2
! 🎉
Configuration
generator test-utils { provider = "prisma-test-utils" output = "node*modules/@generated/test-utils"}
Usage
prisma-test-utils
pack two incredibly useful functions. The first one, pool
, can be used to create a pool of databases that you can use during testing, and are wiped after you've finished. The second one, seed
, helps you populate your data with vast amount of data.
Database Pools
We can configure our pool requirements before running any test cases.
let pool: Pool
This allows us to request an isolated database per test case
test'one of my parallel tests',
API
/* All pool instances. */ /* PostgreSQL */ /* MySQL */ /* SQLite */
Seeding
test'test with seed data',
Options
It is possible to selectively override the seed generation making the seeding workflow very flexible.
All options are autogenerated and checked at compile time. You'll be warned about any relation constraints that your datamodel presents.
beforeAll
LICENSE
MIT @ Prisma