Installations
npm install prisma-test-utils
Developer Guide
Typescript
Yes
Module System
CommonJS
Score
30.3
Supply Chain
59.2
Quality
71.8
Maintenance
30
Vulnerability
91.4
License
Releases
Contributors
Unable to fetch Contributors
Languages
TypeScript (96.52%)
JavaScript (3.48%)
Love this project? Help keep it running — sponsor us today! 🚀
Developer
prisma
Download Statistics
Total Downloads
15,137
Last Day
18
Last Week
28
Last Month
105
Last Year
2,009
GitHub Statistics
114 Stars
163 Commits
11 Forks
24 Watchers
32 Branches
44 Contributors
Updated on Nov 18, 2024
Bundle Size
56.60 kB
Minified
18.24 kB
Minified + Gzipped
Package Meta Information
Latest Version
0.4.1
Package Id
prisma-test-utils@0.4.1
Unpacked Size
908.85 kB
Size
262.67 kB
File Count
75
Total Downloads
Cumulative downloads
Total Downloads
15,137
Last Day
500%
18
Compared to previous day
Last Week
21.7%
28
Compared to previous week
Last Month
7.1%
105
Compared to previous month
Last Year
-48.9%
2,009
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Peer Dependencies
3
🃏 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 and hardcoded fixtures that need to be migrated with changing code.
prisma-test-utils
solves this 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
TBD
Configuration
1generator testutils { 2 provider = "prisma-test-utils" 3 output = "node_modules/@generated/prisma-test-utils" 4}
Usage
prisma-test-utils
packs two incredibly useful functions. The first one, seed
, helps you populate your data with vast amount of data. The second one, pool
, can be used to create a pool of databases that you can use during testing, and are wiped after you've finished.
Seeding
1import Photon from '@generated/photon' 2import seed from '@generated/test-utils/seed' 3 4test('test with seed data', async () => { 5 await seed({ 6 client, 7 models: kit => ({ 8 _: { 9 /* Default number of instances. */ 10 amount: 500, 11 }, 12 Blog: { 13 factory: { 14 /* Use functions from the kit. */ 15 name: kit.faker.sentence, 16 /* Define custom mocks. */ 17 description: 'My custom blog description', 18 /* Define custom mock functions. */ 19 entry: () => { 20 return `A generated entry from the function.` 21 }, 22 /* Manage relations. */ 23 posts: { 24 max: 100, 25 }, 26 }, 27 }, 28 }), 29 }) 30 31 const blogs = await client.blogs() 32})
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.
1beforeAll(async () => { 2 const data = await seed( 3 photon, 4 bag => ({ 5 Post: { 6 amount: 5, 7 factory: { 8 published: 'false', 9 }, 10 }, 11 }), 12 { 13 seed: 42, 14 silent: false, 15 instances: 5, 16 }, 17 ) 18})
Database Pools
We can configure our pool requirements before running any test cases.
1import SQLitePool, { Pool } from '@generated/prisma-test-utils'
2
3let pool: Pool
4
5beforeAll(async () => {
6 pool = new SQLitePool({
7 pool: {
8 min: 3,
9 max: 5,
10 },
11 })
12})
This allows us to request an isolated database per test case
1test('one of my parallel tests', async () => {
2 /* Acquire new db instance. */
3 const db = await pool.getDBInstance()
4
5 // Write the test case logic
6 const client = new Photon({
7 datasources: {
8 db: db.url,
9 },
10 })
11
12 /* Release the instance. */
13 client.disconnect()
14 pool.releaseDBInstance(db)
15})
API
1/* All pool instances. */ 2 3class Pool { 4 async getDBInstance(): Promise<DBInstance> 5 async releaseDBInstance(db: DBInstance): Promise<void> 6 async run<T>(fn: (db: DBInstance) => Promise<T>): Promise<T> 7 async drain(): Promise<void> 8} 9 10/* PostgreSQL */ 11 12interface PostgreSQLConnection { 13 host: string 14 port: number 15 user: string 16 password?: string 17 database: string 18 schema: string 19} 20 21interface PostgreSQLPoolOptions { 22 connection: (id: string) => PostgreSQLConnection 23 pool?: { 24 max?: number 25 } 26} 27 28/* MySQL */ 29 30interface MySQLConnection { 31 host: string 32 port: string 33 user: string 34 password?: string 35 database: string 36} 37 38interface MySQLPoolOptions { 39 connection: (id string) => MySQLConnection 40 pool?: { 41 max?: number 42 } 43} 44 45/* SQLite */ 46 47interface SQLitePoolOptions { 48 databasePath: (id: string) => string 49 pool?: { 50 max?: number 51 } 52}
Local development
:construction: NOTE: Please comment your work and read the comments that are already in there.
I didn't want to remove half the files of this library - the pool part - and that's why there's more files than you'll usually need for developing seed utils. Please don't remove the extra files as this work very nicely the way it is.
The most important file for seeding is src/static/seed.ts
and src/intellisense/seed.ts
. The first one is the logic and the second one provides customized types.
Furthermore:
-
To create a new DB instance: Spin up the
docker-compose up -d
and use TablePlus or alternative to import the sql. -
To examine the behaviour of the library: Uncomment
src/__test
file and start the debugger.src/__test
file references files in thetests/seed
folder. Read on about that! -
To setup
tests/seed
folder: Navigate to that directory and useyarn prisma2 <cmd>
to setup everything that you need. I usually use one of these functions:yarn prisma2 introspect yarn prisma2 introspect --url="postgresql://prisma:prisma@127.0.0.1/ruma"
yarn prisma2 migrate up --experimental
yarn prisma2 migrate save --name "init" --experimental
yarn prisma2 generate
. I have also added theREADME.md
file in there with missing generator definitions from introspection. Copy and paste them to the top.
-
To push changes: Preferablly do a PR, and don't forget to comment out
src/__test
file. -
To publish a new version: I use
npx np --no-tests
. -
To apply changes in the
intellisense
: Runyarn build
. -
To test the utils outside debugger: Run
yarn build:runtime
. -
To get new VSCode type definitions after changing the schema: Reload VSCode :slightly_smiling_face:
LICENSE
MIT @ Prisma

No vulnerabilities found.
Reason
no binaries found in the repo
Reason
security policy file detected
Details
- Info: security policy file detected: github.com/prisma/.github/SECURITY.md:1
- Info: Found linked content: github.com/prisma/.github/SECURITY.md:1
- Warn: One or no descriptive hints of disclosure, vulnerability, and/or timelines in security policy
- Info: Found text in security policy: github.com/prisma/.github/SECURITY.md:1
Reason
project is archived
Details
- Warn: Repository is archived.
Reason
Found 2/29 approved changesets -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
license file not detected
Details
- Warn: project does not have a license file
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'main'
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
- Warn: 0 commits out of 4 are checked with a SAST tool
Reason
92 existing vulnerabilities detected
Details
- Warn: Project is vulnerable to: GHSA-67hx-6x53-jw92
- Warn: Project is vulnerable to: GHSA-h5c3-5r3r-rr8q
- Warn: Project is vulnerable to: GHSA-rmvr-2pp2-xj38
- Warn: Project is vulnerable to: GHSA-xx4v-prfh-6cgc
- Warn: Project is vulnerable to: GHSA-pxcc-hj8w-fmm7
- Warn: Project is vulnerable to: GHSA-593m-55hh-j8gv
- Warn: Project is vulnerable to: GHSA-6chw-6frg-f759
- Warn: Project is vulnerable to: GHSA-v88g-cgmw-v5xw
- Warn: Project is vulnerable to: GHSA-93q8-gq69-wqmw
- Warn: Project is vulnerable to: GHSA-fwr7-v2mv-hh25
- Warn: Project is vulnerable to: GHSA-pp7h-53gx-mx7r
- Warn: Project is vulnerable to: GHSA-qwcr-r2fm-qrc7
- Warn: Project is vulnerable to: GHSA-grv7-fg5c-xmjg
- Warn: Project is vulnerable to: GHSA-4jwp-vfvf-657p
- Warn: Project is vulnerable to: GHSA-v8w9-2789-6hhr
- Warn: Project is vulnerable to: GHSA-xp63-6vf5-xf3v
- Warn: Project is vulnerable to: GHSA-pxg6-pf52-xh8x
- Warn: Project is vulnerable to: GHSA-7gc6-qh9x-w6h8
- Warn: Project is vulnerable to: GHSA-3xgq-45jj-v275
- Warn: Project is vulnerable to: GHSA-gxpj-cx7g-858c
- Warn: Project is vulnerable to: GHSA-w573-4hg7-7wgq
- Warn: Project is vulnerable to: GHSA-ff7x-qrg7-qggm
- Warn: Project is vulnerable to: GHSA-rv95-896h-c2vc
- Warn: Project is vulnerable to: GHSA-qw6h-vgh9-j6wx
- Warn: Project is vulnerable to: GHSA-ww39-953v-wcq6
- Warn: Project is vulnerable to: GHSA-pfrx-2q88-qq97
- Warn: Project is vulnerable to: GHSA-765h-qjxv-5f44
- Warn: Project is vulnerable to: GHSA-f2jv-r9rf-7988
- Warn: Project is vulnerable to: GHSA-43f8-2h32-f4cj
- Warn: Project is vulnerable to: GHSA-rc47-6667-2j5j
- Warn: Project is vulnerable to: GHSA-qqgx-2p2h-9c37
- Warn: Project is vulnerable to: GHSA-78xj-cgh5-2h22
- Warn: Project is vulnerable to: GHSA-2p57-rm9w-gvfp
- Warn: Project is vulnerable to: GHSA-896r-f27r-55mw
- Warn: Project is vulnerable to: GHSA-9c47-m6qq-7p4h
- Warn: Project is vulnerable to: GHSA-8cf7-32gw-wr33
- Warn: Project is vulnerable to: GHSA-hjrf-2m68-5959
- Warn: Project is vulnerable to: GHSA-qwph-4952-7xr6
- Warn: Project is vulnerable to: GHSA-p6mc-m468-83gw
- Warn: Project is vulnerable to: GHSA-29mw-wpgm-hmr9
- Warn: Project is vulnerable to: GHSA-35jh-r3h4-6jhm
- Warn: Project is vulnerable to: GHSA-5v2h-r2cx-5xgj
- Warn: Project is vulnerable to: GHSA-rrrm-qjm4-v8hf
- Warn: Project is vulnerable to: GHSA-4xcv-9jjx-gfj3
- Warn: Project is vulnerable to: GHSA-952p-6rrq-rcjv
- Warn: Project is vulnerable to: GHSA-f8q6-p94x-37v3
- Warn: Project is vulnerable to: GHSA-vh95-rmgr-6w4m
- Warn: Project is vulnerable to: GHSA-xvch-5gv4-984h
- Warn: Project is vulnerable to: GHSA-r683-j2x4-v87g
- Warn: Project is vulnerable to: GHSA-w7rc-rwvf-8q5r
- Warn: Project is vulnerable to: GHSA-5fw9-fq32-wv5p
- Warn: Project is vulnerable to: GHSA-px4h-xg32-q955
- Warn: Project is vulnerable to: GHSA-93f3-23rq-pjfp
- Warn: Project is vulnerable to: GHSA-jmqm-f2gx-4fjv
- Warn: Project is vulnerable to: GHSA-pw54-mh39-w3hc
- Warn: Project is vulnerable to: GHSA-xgh6-85xh-479p
- Warn: Project is vulnerable to: GHSA-hj48-42vr-x3v9
- Warn: Project is vulnerable to: GHSA-9wv6-86v2-598j
- Warn: Project is vulnerable to: GHSA-rhx6-c78j-4q9w
- Warn: Project is vulnerable to: GHSA-hrpp-h998-j3pp
- Warn: Project is vulnerable to: GHSA-p8p7-x288-28g6
- Warn: Project is vulnerable to: GHSA-gcx4-mw62-g8wm
- Warn: Project is vulnerable to: GHSA-r2j6-p67h-q639
- Warn: Project is vulnerable to: GHSA-c2qf-rxjj-qqgw
- Warn: Project is vulnerable to: GHSA-44c6-4v22-4mhx
- Warn: Project is vulnerable to: GHSA-4x5v-gmq8-25ch
- Warn: Project is vulnerable to: GHSA-m6fv-jmcg-4jfg
- Warn: Project is vulnerable to: GHSA-cm22-4g7w-348p
- Warn: Project is vulnerable to: GHSA-g4rg-993r-mgx7
- Warn: Project is vulnerable to: GHSA-vx3p-948g-6vhq
- Warn: Project is vulnerable to: GHSA-3jfq-g458-7qm9
- Warn: Project is vulnerable to: GHSA-r628-mhmh-qjhw
- Warn: Project is vulnerable to: GHSA-9r2w-394v-53qc
- Warn: Project is vulnerable to: GHSA-5955-9wpr-37jh
- Warn: Project is vulnerable to: GHSA-qq89-hq3f-393p
- Warn: Project is vulnerable to: GHSA-f5x3-32g6-xq36
- Warn: Project is vulnerable to: GHSA-29xr-v42j-r956
- Warn: Project is vulnerable to: GHSA-jgrx-mgxx-jf9v
- Warn: Project is vulnerable to: GHSA-72xf-g2v4-qvf3
- Warn: Project is vulnerable to: GHSA-7p7h-4mm5-852v
- Warn: Project is vulnerable to: GHSA-38fc-wpqx-33j7
- Warn: Project is vulnerable to: GHSA-9m6j-fcg5-2442
- Warn: Project is vulnerable to: GHSA-hh27-ffr2-f2jc
- Warn: Project is vulnerable to: GHSA-rqff-837h-mm52
- Warn: Project is vulnerable to: GHSA-8v38-pw62-9cw2
- Warn: Project is vulnerable to: GHSA-hgjh-723h-mx2j
- Warn: Project is vulnerable to: GHSA-jf5r-8hm2-f872
- Warn: Project is vulnerable to: GHSA-j8xg-fqg3-53r7
- Warn: Project is vulnerable to: GHSA-6fc8-4gx4-v693
- Warn: Project is vulnerable to: GHSA-3h5v-q93c-6h6q
- Warn: Project is vulnerable to: GHSA-c4w7-xm78-47vh
- Warn: Project is vulnerable to: GHSA-p9pc-299p-vxgp
Score
2.1
/10
Last Scanned on 2025-02-10
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn MoreOther packages similar to prisma-test-utils
prisma-test-utils-tmp
[](https://circleci.com/gh/prisma/prisma-test-utils/tree/master) [](https://c
prisma-generator-test-utils
A [Prisma generator](https://www.prisma.io/docs/concepts/components/prisma-schema/generators) to create some utility functions useful for writing unit/integration tests.
prisma-generate-test-utils
A [Prisma generator](https://www.prisma.io/docs/concepts/components/prisma-schema/generators) to create some utility functions useful for writing unit/integration tests.
prisma-utils
utils for prisma