DT
Drizzle Team•2mo ago
32cls

Integration tests with Deno and drizzle

Hello, I'm wondering what's the best approach when dealing with integration tests using PostgreSQL+ Drizzle. I'm using deno and I get an error each time I try to access my database as I don't close the connection because I rely on the global db instance (which I believe seems to be the pattern illustrated in the docs?). If I close the connection after a test, the other tests just break with
Caused by Error: Cannot use a pool after calling end on the pool
Caused by Error: Cannot use a pool after calling end on the pool
. If I don't close the connection Deno gives me the
error: Leaks detected:
- A TCP connection was opened/accepted during the test, but not closed during the test. Close the TCP connection by calling `tcpConn.close()`.
- A timer was started in this test, but never completed. This is often caused by not calling `clearTimeout`.
- An async call to op_read was started in this test, but never completed.
To get more details where leaks occurred, run again with the --trace-leaks flag.
error: Leaks detected:
- A TCP connection was opened/accepted during the test, but not closed during the test. Close the TCP connection by calling `tcpConn.close()`.
- A timer was started in this test, but never completed. This is often caused by not calling `clearTimeout`.
- An async call to op_read was started in this test, but never completed.
To get more details where leaks occurred, run again with the --trace-leaks flag.
treatment. I don't use vitest, just the Deno default test runner. Passing the db instance to each function looks like an awful solution to me, I don't really know if there is a better solution? I see that the drizzle driver can be mocked, but that does not solve my global db instance problem. Could the singleton pattern be relevant for my use case?
1 Reply
32cls
32clsOP•2mo ago
😅

Did you find this page helpful?