P
Prisma5mo ago
Ben

'Too many clients' error when using NestJS and Jest even with a singleton Service

Is there a canonical example of how to create a PrismaService that can be used with Jest to do integration testing? I'm getting 'too many client' errors even with a PrismaService that uses a global client and using --runInBand. Does anybody have a exmaple of how to configure a PrismaService to use with NestJS and Jest?
4 Replies
Prisma AI Help
Prisma AI Help5mo ago
You decided to hold for human wisdom. We'll chime in soon! Meanwhile, #ask-ai is there if you need a quick second opinion.
Nurul
Nurul5mo ago
Hey 👋 Did you follow the example mentioned in this guide? https://www.prisma.io/docs/orm/prisma-client/testing
Testing with Prisma ORM | Prisma Documentation
How to implement unit and integration testing with Prisma ORM
Ben
BenOP5mo ago
@Nurul (Prisma) Thank you for the link. My issue is with running many integration tests in NestJS in quick succession. Individually they run fine but when run as a complete test suite eventually I get a 'too many clients' error. I suspect the issue is with setup and teardown but I'm running out of places to look 🙂 If somebody else ever looks at this in the future, the issue was the Prisma client was being re-created in each beforeEach rather than once in beforeAll and then rebuilding the testing module
Nurul
Nurul5mo ago
Thank you so much for taking the time to share the solution 🙏

Did you find this page helpful?