morintd / prismock

A mock for PrismaClient, dedicated to unit testing.
https://www.npmjs.com/package/prismock
MIT License
203 stars 23 forks source link

Running Prismock in client browser #1176

Open JoeRoddy opened 3 days ago

JoeRoddy commented 3 days ago

Hi!

Is there any way to get Prismock running in the browser? I have an application with extremely complex client state, and I basically want an autogenerated in-memory querying engine for that state, and this was the first library I thought of.

Unsure if this leverages the actual Prisma engine at all, or if everything is literally an in-memory JS implementation of Prisma's API's.

When I try to import Prismock into a client component, I get the following: image

I guess I assumed this lib only referenced Prisma's types, and didn't use the actual engine? Do you think there's any chance this is possible @morintd ?

JoeRoddy commented 3 days ago

Ok it definitely could work. I have a little proof of concept working:

https://github.com/user-attachments/assets/3e32006f-2160-4035-815a-b7f70a78d56d

But I basically had to take out all of Prismock's non-type imports of Prisma, and then serialize the dmmf json after the prisma client is generated, and feed that into prismock to supply the datamodels, rather than importing it from prisma.

https://github.com/JoeRoddy/prismock-web-test/tree/main