Gathering detailed insights and metrics for prisma-test-utils-tmp
Gathering detailed insights and metrics for prisma-test-utils-tmp
Gathering detailed insights and metrics for prisma-test-utils-tmp
Gathering detailed insights and metrics for prisma-test-utils-tmp
npm install prisma-test-utils-tmp
Typescript
Module System
TypeScript (96.52%)
JavaScript (3.48%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
114 Stars
163 Commits
11 Forks
22 Watchers
32 Branches
39 Contributors
Updated on Nov 18, 2024
Latest Version
0.0.1
Package Id
prisma-test-utils-tmp@0.0.1
Unpacked Size
3.40 MB
Size
959.72 kB
File Count
72
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
7
4
⚠️ 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.
No installation! Comes preinstalled with prisma2
! 🎉
1generator test-utils { 2 provider = "prisma-test-utils" 3 output = "node*modules/@generated/test-utils" 4}
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.
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}
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})
MIT @ Prisma
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
security policy file detected
Details
Reason
Found 2/29 approved changesets -- score normalized to 0
Reason
project is archived
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
license file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
95 existing vulnerabilities detected
Details
Score
Last Scanned on 2025-07-07
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 More