@pkgverse/prismock 2.0.1-beta.9 → 2.0.2-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +9 -24
- package/package.json +4 -3
package/README.md
CHANGED
|
@@ -5,8 +5,7 @@
|
|
|
5
5
|
|
|
6
6
|
## NOTE
|
|
7
7
|
Originally forked from https://github.com/morintd/prismock. This library is awesome, and I felt it could use some modernization to work with newer versions of prisma and add support for
|
|
8
|
-
client extensions. My current intention is to try to maintain this and stay up to speed with bug-fixes
|
|
9
|
-
I haven't personally tested the CJS functionality.
|
|
8
|
+
client extensions. My current intention is to try to maintain this and stay up to speed with bug-fixes, contributions are welcome! The focus is ESM-first, so although both ESM and CJS exports are provided, I haven't personally tested the CJS functionality.
|
|
10
9
|
|
|
11
10
|
---
|
|
12
11
|
|
|
@@ -44,9 +43,9 @@ $ bun add -E -D @pkgverse/prismock
|
|
|
44
43
|
|
|
45
44
|
```ts
|
|
46
45
|
import { PrismaClient } from "${your_prisma_client_directory}"
|
|
47
|
-
import { getClient } from 'prismock';
|
|
46
|
+
import { getClient } from '@pkgverse/prismock';
|
|
48
47
|
|
|
49
|
-
// Pass in
|
|
48
|
+
// Pass in your PrismaClient class and the path to your schema
|
|
50
49
|
let mockedClient = await getClient({
|
|
51
50
|
prismaClient: PrismaClient,
|
|
52
51
|
schemaPath: "prisma/schema.prisma",
|
|
@@ -64,7 +63,7 @@ If you're using prisma with postgres, you can optionally choose to have the mock
|
|
|
64
63
|
|
|
65
64
|
```ts
|
|
66
65
|
import { PrismaClient } from "${your_prisma_client_directory}"
|
|
67
|
-
import { getClient } from 'prismock';
|
|
66
|
+
import { getClient } from '@pkgverse/prismock';
|
|
68
67
|
|
|
69
68
|
let mockedClient = await getClient({
|
|
70
69
|
prismaClient: PrismaClient,
|
|
@@ -83,16 +82,16 @@ The PgLite database is initialized by executing your migration history. It's cur
|
|
|
83
82
|
as the schema file, i.e. the directory of the file path you pass in as `schemaPath`. If that's not the case, this will most likely fail.
|
|
84
83
|
|
|
85
84
|
|
|
86
|
-
## PrismaClient
|
|
85
|
+
## Mocking the PrismaClient module
|
|
87
86
|
|
|
88
|
-
You can mock the PrismaClient directly in your test, or setupTests ([Example](https://github.com/JQuezada0/prismock/blob/
|
|
87
|
+
You can mock the PrismaClient directly in your test, or setupTests ([Example](https://github.com/JQuezada0/prismock/blob/main/src/__tests__/client/example-prismock.test.ts)):
|
|
89
88
|
|
|
90
89
|
```ts
|
|
91
90
|
import { vi } from "vitest"
|
|
92
91
|
|
|
93
92
|
vi.mock('@prisma/client', async () => {
|
|
94
93
|
const actual = await vi.importActual<typeof import("@prisma/client")>("@prisma/client")
|
|
95
|
-
const actualPrismock = await vi.importActual<typeof import("prismock")>("prismock")
|
|
94
|
+
const actualPrismock = await vi.importActual<typeof import("@pkgverse/prismock")>("@pkgverse/prismock")
|
|
96
95
|
|
|
97
96
|
return {
|
|
98
97
|
...actual,
|
|
@@ -106,11 +105,11 @@ vi.mock('@prisma/client', async () => {
|
|
|
106
105
|
|
|
107
106
|
## Use prismock manually
|
|
108
107
|
|
|
109
|
-
You can
|
|
108
|
+
You can get an instantiated prisma client and pass it wherever you need to
|
|
110
109
|
|
|
111
110
|
```ts
|
|
112
111
|
import { PrismaClient } from '${your_prisma_client_directory}';
|
|
113
|
-
import { getClient } from 'prismock';
|
|
112
|
+
import { getClient } from '@pkgverse/prismock';
|
|
114
113
|
|
|
115
114
|
const client = await getClient({
|
|
116
115
|
PrismaClient,
|
|
@@ -297,20 +296,6 @@ Basic groupBy queries are supported, including `having` and `orderBy`. `skip`, `
|
|
|
297
296
|
- Restore test on `_count` for mongodb
|
|
298
297
|
- Add custom client method for MongoDB (`$runCommandRaw`, `findRaw`, `aggregateRaw`)
|
|
299
298
|
|
|
300
|
-
# Motivation
|
|
301
|
-
|
|
302
|
-
While _Prisma_ is amazing, its `unit testing` section is treated as optional. On the other hand, it should be a priority for developers to write tests.
|
|
303
|
-
|
|
304
|
-
As I love _Prisma_, I decided to create this package, in order to keep using it on real-world projects.
|
|
305
|
-
|
|
306
|
-
I'm also a teacher and believe it's mandatory for students to learn about testing. I needed a similar solution for my [backend course](https://www.scalablebackend.com/), so I created my own.
|
|
307
|
-
|
|
308
|
-
# Feature request
|
|
309
|
-
|
|
310
|
-
I'm personally using this library in my day-to-day activities, and add features or fix bugs depending on my needs.
|
|
311
|
-
|
|
312
|
-
If you need unsupported features or discover unwanted behaviors, feel free to open an issue, I'll take care of it.
|
|
313
|
-
|
|
314
299
|
# Credit
|
|
315
300
|
|
|
316
301
|
Inspired by [prisma-mock](https://github.com/demonsters/prisma-mock).
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pkgverse/prismock",
|
|
3
|
-
"version": "2.0.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "2.0.2-beta.0",
|
|
4
|
+
"description": "An in-memory implementation of PrismaClient, dedicated to unit testing.",
|
|
5
5
|
"repository": {
|
|
6
6
|
"url": "https://github.com/JQuezada0/prismock"
|
|
7
7
|
},
|
|
@@ -24,7 +24,8 @@
|
|
|
24
24
|
"test",
|
|
25
25
|
"prisma",
|
|
26
26
|
"in-memory",
|
|
27
|
-
"mock"
|
|
27
|
+
"mock",
|
|
28
|
+
"pglite"
|
|
28
29
|
],
|
|
29
30
|
"prisma": {
|
|
30
31
|
"seed": "tsx prisma/seed.ts"
|