[TUTORIAL]: Using in-memory Postgres when testing with vitest #4216
wilfredjonathanjames
started this conversation in
General
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Crosspost from here - just realised discussions gets use.
Sharing for posterity as it may help someone. A
vi.mock
to switchpg
databases to in-memorypglite
, push your drizzle schema, and insert seed data.pglite
runs-WASM compiled postgres in memory, which is ideal for testing as there's no docker containers, no delay, and it's real pg. This solution supports parallelism and watch mode. Most importantly - it uses push in place of migrate, as there's no need to create migration files when testing.Note to Drizzle maintainers, please do not remove
drizzle-kit/api
'spushSchema
method. While it's not well documented, it allows us to push schema directly to test dbs. Please don't make me push via child_process execSync again.Stack:
drizzle-orm/node-postgres
)Mock:
Detail:
Beta Was this translation helpful? Give feedback.
All reactions