Registry / testing / vitest-environment-prisma-postgres

vitest-environment-prisma-postgres

JSON →
library1.0.1jsnpmunverified

Vitest environment for Prisma & PostgreSQL designed for fast integration tests: seed your database once with production-like data, then run each test in a transaction that is rolled back after execution. Tests remain isolated without expensive reseeding. Current version 1.0.1 requires Prisma 7.x and Vitest 4.x. Provides a custom test environment, setup hooks, and typed configuration. Key differentiator: transaction-rollback isolation without database-level overhead, unlike alternatives that reseed per test.

npm install vitest-environment-prisma-postgres
INSTALL
IMPORT
SIG · VITEST-ENVIRONMENT
V
vitest-environment-prisma-postgres
testingjavascriptv1.0.1
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default (environment module)
export default defineConfig({ test: { environment: 'prisma-postgres' } })
import { prismaPostgres } from 'vitest-environment-prisma-postgres'
The environment is registered via string name in vitest config, not imported directly.
setup (setup module)
import 'vitest-environment-prisma-postgres/setup'
import { setup } from 'vitest-environment-prisma-postgres'
Setup file must be imported via full path in vitest config setupFiles array.

Configuration and setup for Vitest integration tests using prisma-postgres environment, including client path, setup files, and mocking.

// vitest.config.ts import { defineConfig } from 'vitest/config'; export default defineConfig({ test: { environment: 'prisma-postgres', environmentOptions: { 'prisma-postgres': { clientPath: './generated/prisma-client', }, }, setupFiles: [ 'vitest-environment-prisma-postgres/setup', './vitest.setup.ts', ], }, }); // vitest.setup.ts import { PrismaClient } from './generated/prisma-client'; import { environment } from 'vitest-environment-prisma-postgres'; const prisma = new PrismaClient({ adapter: environment.prismaAdapter, }); vi.mock('./generated/prisma-client', () => ({ PrismaClient: vi.fn().mockImplementation(() => prisma), })); // Run tests with DATABASE_URL set // DATABASE_URL=postgresql://user:pass@localhost:5432/testdb npx vitest
Debug
Known issues
breakingRequires Node >=24.0.0 – older versions will fail to install or run.
fix
Upgrade Node.js to version 24 or later.
affects: <1.0.0
deprecatedThe 'clientPath' option will be required in future versions; currently optional but recommended.
fix
Always specify clientPath in environmentOptions.
affects: >=1.0.0
gotchaApplication-level transactions (e.g., nested transactions) may conflict with the test transaction rollback.
fix
Avoid manual transaction calls in tests; rely on the environment's automatic rollback.
affects: >=1.0.0
gotchaThe setup file must be imported before your own setup files to ensure the transaction is started.
fix
Add 'vitest-environment-prisma-postgres/setup' as the first entry in setupFiles.
affects: >=1.0.0
Errors
Common errors & fixes
Error: Cannot find module 'vitest-environment-prisma-postgres/setup'
Missing import path or module not installed.
fix
Ensure the package is installed: npm install vitest-environment-prisma-postgres --save-dev
ReferenceError: vi is not defined
Vitest globals not enabled when using vi.mock in setup file.
fix
Set globals: true in vitest config or import vi from 'vitest'.
Error: Environment "prisma-postgres" is not registered
Environment not configured correctly in vitest config.
fix
Add environment: 'prisma-postgres' to your vitest config under test.
Upgrade
Version history
1.0.1latest on npm
Audit
Dependencies
@prisma/adapter-pgrequiredRequired peer dependency for Prisma PostgreSQL adapter.
prismarequiredRequired peer dependency for Prisma ORM.
vitestrequiredRequired peer dependency for the Vitest test framework.
Agent activity
9 hits · last 30 days
node
8
Resources
vitest-environment-prisma-postgres — npm install vitest-environment-prisma-postgres · libregistry