{"_id":"vitest-environment-prisma-postgres","_rev":"3-5b5bb511a0deb1110b34e39565ca158d","name":"vitest-environment-prisma-postgres","dist-tags":{"latest":"2.0.0"},"versions":{"1.0.0":{"name":"vitest-environment-prisma-postgres","version":"1.0.0","keywords":["vitest","prisma","postgres","prisma orm","postgesql","test","testing","test isolation","transaction"],"author":{"name":"Christoph Werner","email":"christoph@codepunkt.de"},"license":"MIT","_id":"vitest-environment-prisma-postgres@1.0.0","maintainers":[{"name":"cwer","email":"christoph+npm@codepunkt.de"}],"homepage":"https://github.com/codepunkt/vitest-environment-prisma-postgres#readme","bugs":{"url":"https://github.com/codepunkt/vitest-environment-prisma-postgres/issues"},"dist":{"shasum":"c64113bbfc57b82a166a83dfe07cc00d77dae72b","tarball":"https://registry.npmjs.org/vitest-environment-prisma-postgres/-/vitest-environment-prisma-postgres-1.0.0.tgz","fileCount":9,"integrity":"sha512-VceNGh4L2a7xYm4ZVjzRSUulGmBqoIGgBVG2Or/7VbP42LnxtPdkYd5B2+45Ajrn94vUVDvvLA1pfhnROQS7Rw==","signatures":[{"sig":"MEQCIGzdElEhkCfzS5nllMXz8E67b4vI5gNBf97D07pdXu/BAiBz0wW6Im/qqqxTpuPpiTwK//g3yw5jiqEGCj+6xsusNA==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":23893},"type":"module","engines":{"node":">=24.0.0"},"exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.js","require":"./dist/index.js"},"./setup":{"import":"./dist/setup.js","require":"./dist/setup.js"}},"gitHead":"8ce36e8f6ac9d44d655045030096f8c5351f908a","scripts":{"lint":"biome lint","test":"vitest run --coverage","build":"tsup","format":"biome format --write","release":"dotenv -e .env -- release-it","typecheck":"tsc --noEmit","format:check":"biome format"},"_npmUser":{"name":"cwer","email":"christoph+npm@codepunkt.de"},"repository":{"url":"git+https://github.com/codepunkt/vitest-environment-prisma-postgres.git","type":"git"},"_npmVersion":"11.6.2","description":"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.","directories":{},"_nodeVersion":"24.11.1","_hasShrinkwrap":false,"packageManager":"pnpm@9.12.3","devDependencies":{"tsup":"8.5.1","prisma":"7.0.1","vitest":"4.0.14","dotenv-cli":"11.0.0","release-it":"19.0.6","typescript":"5.9.3","@types/node":"24.10.1","@biomejs/biome":"2.3.8","@prisma/adapter-pg":"7.0.1","@vitest/coverage-v8":"4.0.14","@release-it/conventional-changelog":"10.0.1"},"peerDependencies":{"prisma":">=4 <8","vitest":">=4 <5","@prisma/adapter-pg":">=4 <8"},"_npmOperationalInternal":{"tmp":"tmp/vitest-environment-prisma-postgres_1.0.0_1764405912710_0.14733309229459124","host":"s3://npm-registry-packages-npm-production"}},"1.0.1":{"name":"vitest-environment-prisma-postgres","version":"1.0.1","keywords":["vitest","prisma","postgres","prisma orm","postgesql","test","testing","test isolation","transaction"],"author":{"name":"Christoph Werner","email":"christoph@codepunkt.de"},"license":"MIT","_id":"vitest-environment-prisma-postgres@1.0.1","maintainers":[{"name":"cwer","email":"christoph+npm@codepunkt.de"}],"homepage":"https://github.com/codepunkt/vitest-environment-prisma-postgres#readme","bugs":{"url":"https://github.com/codepunkt/vitest-environment-prisma-postgres/issues"},"dist":{"shasum":"7954e92c74e46e797a0e7aa032bfde54d5ae540e","tarball":"https://registry.npmjs.org/vitest-environment-prisma-postgres/-/vitest-environment-prisma-postgres-1.0.1.tgz","fileCount":9,"integrity":"sha512-kUmthYXxQTPuz8NvSo9GxUd7Htn8jMkBXZuqDiCPJtK5ycjRxSjYkW0WESMzxYDOp1YtwfVyIxNcpYDaKu1LGw==","signatures":[{"sig":"MEUCIG2M4Wb1NlkJRcsoHtHLWKq9Iay3FPGlHcvTzTRfuHbbAiEA9C+j/bkh554tSo83VVB/o3GXVvrgA0TKk9ApxdVumKw=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":24793},"type":"module","engines":{"node":">=24.0.0"},"exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.js","require":"./dist/index.js"},"./setup":{"import":"./dist/setup.js","require":"./dist/setup.js"}},"gitHead":"4914711f70f49a6ef54716c89adfe3edb99421a0","scripts":{"lint":"biome lint","test":"vitest run --coverage","build":"tsup","format":"biome format --write","release":"dotenv -e .env -- release-it","typecheck":"tsc --noEmit","format:check":"biome format"},"_npmUser":{"name":"cwer","email":"christoph+npm@codepunkt.de"},"repository":{"url":"git+https://github.com/codepunkt/vitest-environment-prisma-postgres.git","type":"git"},"_npmVersion":"11.6.2","description":"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.","directories":{},"_nodeVersion":"24.11.1","_hasShrinkwrap":false,"packageManager":"pnpm@10.24.0","devDependencies":{"tsup":"8.5.1","prisma":"7.0.1","vitest":"4.0.14","dotenv-cli":"11.0.0","release-it":"19.0.6","typescript":"5.9.3","@types/node":"24.10.1","@biomejs/biome":"2.3.8","@prisma/adapter-pg":"7.0.1","@vitest/coverage-v8":"4.0.14","@release-it/conventional-changelog":"10.0.1"},"peerDependencies":{"prisma":">=4 <8","vitest":">=4 <5","@prisma/adapter-pg":">=4 <8"},"_npmOperationalInternal":{"tmp":"tmp/vitest-environment-prisma-postgres_1.0.1_1764440142273_0.08470575639412892","host":"s3://npm-registry-packages-npm-production"}},"2.0.0":{"name":"vitest-environment-prisma-postgres","version":"2.0.0","license":"MIT","author":{"name":"Christoph Werner","email":"christoph@codepunkt.de"},"description":"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.","type":"module","packageManager":"pnpm@10.27.0","repository":{"type":"git","url":"git+https://github.com/codepunkt/vitest-environment-prisma-postgres.git"},"engines":{"node":">=20"},"scripts":{"build":"tsup","format":"biome format --write","format:check":"biome format","lint":"biome lint","prepare":"husky","release":"dotenv -e .env -- release-it","test":"vitest run --coverage","typecheck":"tsc --noEmit"},"keywords":["vitest","prisma","postgres","prisma orm","postgesql","test","testing","test isolation","transaction"],"exports":{".":{"types":"./dist/index.d.ts","require":"./dist/index.js","import":"./dist/index.js"},"./setup":{"require":"./dist/setup.js","import":"./dist/setup.js"}},"devDependencies":{"@biomejs/biome":"2.3.10","@prisma/adapter-pg":"7.2.0","@release-it/conventional-changelog":"10.0.4","@types/node":"24.10.4","@vitest/coverage-v8":"4.1.8","dotenv-cli":"11.0.0","husky":"9.1.7","prisma":"7.2.0","release-it":"20.2.0","tsup":"8.5.1","typescript":"5.9.3","vitest":"4.1.8"},"peerDependencies":{"@prisma/adapter-pg":">=4 <8","prisma":">=4 <8","vitest":">=4.1 <5"},"gitHead":"97efe07574e2bec4d0e8ebd42d041b3edb8e8346","_id":"vitest-environment-prisma-postgres@2.0.0","bugs":{"url":"https://github.com/codepunkt/vitest-environment-prisma-postgres/issues"},"homepage":"https://github.com/codepunkt/vitest-environment-prisma-postgres#readme","_nodeVersion":"24.12.0","_npmVersion":"11.6.2","dist":{"integrity":"sha512-92S0jx5aRLco48rW+uPPnmrvLADpc2BdJKJM3LB/2C4DnRADiTjiLAEKwyNhfVEi+Zwi3Gfn5VDvT+keFqeLWQ==","shasum":"9d96b55f34451b73f3c4c4fd59115eff1c69a3ca","tarball":"https://registry.npmjs.org/vitest-environment-prisma-postgres/-/vitest-environment-prisma-postgres-2.0.0.tgz","fileCount":9,"unpackedSize":27522,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIFdikc2WVFxvmrXRzVOoPhmqYwpoTNqILYNFHXORl2gFAiEAliWc2YHt8h0ZymfE3iI6BrY9KOjYR0vKrDUfzPd7CQI="}]},"_npmUser":{"name":"cwer","email":"christoph+npm@codepunkt.de"},"directories":{},"maintainers":[{"name":"cwer","email":"christoph+npm@codepunkt.de"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/vitest-environment-prisma-postgres_2.0.0_1781190689676_0.15083018434413442"},"_hasShrinkwrap":false}},"time":{"created":"2025-11-29T08:45:12.709Z","modified":"2026-06-11T15:11:29.934Z","1.0.0":"2025-11-29T08:45:12.907Z","1.0.1":"2025-11-29T18:15:42.471Z","2.0.0":"2026-06-11T15:11:29.816Z"},"bugs":{"url":"https://github.com/codepunkt/vitest-environment-prisma-postgres/issues"},"author":{"name":"Christoph Werner","email":"christoph@codepunkt.de"},"license":"MIT","homepage":"https://github.com/codepunkt/vitest-environment-prisma-postgres#readme","keywords":["vitest","prisma","postgres","prisma orm","postgesql","test","testing","test isolation","transaction"],"repository":{"type":"git","url":"git+https://github.com/codepunkt/vitest-environment-prisma-postgres.git"},"description":"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.","maintainers":[{"name":"cwer","email":"christoph+npm@codepunkt.de"}],"readme":"![vitest-environment-prisma-postgres](https://i.imgur.com/KUxDm4b.png)\n\n<div align=\"center\">\n  <h1>vitest-environment-prisma-postgres</h1>\n  <a href=\"https://www.npmjs.com/package/vitest-environment-prisma-postgres\"><img src=\"https://img.shields.io/npm/v/vitest-environment-prisma-postgres.svg?style=flat\" /></a>\n  <a href=\"https://github.com/codepunkt/vitest-environment-prisma-postgres/blob/main/.github/CONTRIBUTING.md\"><img src=\"https://img.shields.io/badge/PRs-welcome-brightgreen.svg\" /></a>\n  <a href=\"https://github.com/codepunkt/vitest-environment-prisma-postgres/blob/main/LICENSE\"><img src=\"https://img.shields.io/badge/license-MIT-blue\" /></a>\n  <a href=\"https://codecov.io/gh/codepunkt/vitest-environment-prisma-postgres\"><img src=\"https://codecov.io/gh/codepunkt/vitest-environment-prisma-postgres/graph/badge.svg?token=BI1IWN0F3G\" /></a>\n  <br />\n  <br />\n  <a href=\"#features\">Features</a>\n  <span>&nbsp;&nbsp;•&nbsp;&nbsp;</span>\n  <a href=\"#installation--setup\">Installation & Setup</a>\n  <span>&nbsp;&nbsp;•&nbsp;&nbsp;</span>\n  <a href=\"#typescript-configuration\">TypeScript Configuration</a>\n  <span>&nbsp;&nbsp;•&nbsp;&nbsp;</span>\n  <a href=\"#known-limiations\">Known Limitations</a>\n  <br />\n  <hr />\n</div>\n\n## Motivation\n\n[Vitest](https://vitest.dev/) environment for [Prisma](https://www.prisma.io/) + [PostgreSQL](https://www.postgresql.org/) designed for fast integration tests.\n\nIntegration tests against a database are often slow because each test needs its own database state. Teams typically either:\n\n- Reseed the database before every test, or\n- Insert all required data inside each test.\n\nBoth approaches are slow, repetitive, and dominate test runtime.\n\n**This environment eliminates that cost.**\n\nYou run migrations and seed your test database once.\nEach test then runs inside its own database transaction, which is rolled back automatically after the test finishes. Your tests stay isolated, realistic, and extremely fast, creating dedicated data for every test.\n\nIf you want to understand the full design rationale, implementation details, and performance benchmarks behind this environment, check out the in-depth article on my blog:\n\nhttps://codepunkt.de/writing/blazing-fast-prisma-and-postgres-tests-in-vitest/\n\n## Features\n\n- Run integration tests against a real PostgreSQL instance.\n- Seed your database once at the beginning of the test run.\n- Tests run inside sandboxed transactions, but application-level transactions still work normally.\n- Test transactions are rolled back after every test.\n- Tests are isolated, fast, and order independent.\n\n## Installation & Setup\n\n> Requires Node.js 20 or newer (CI covers 20.x, 22.x, 24.x).\n\n#### Step 1: Install the environment\n\nFirst, install the environnment:\n\n```shell\nnpm install vitest-environment-prisma-postgres --save-dev\n```\n\n#### Step 2: Ensure peer dependency availability\n\nThen, ensure that the required peer dependencies are available. This library requires that you have all of the following installed in your project:\n\n- `vitest` in version `4.1` or newer\n- `prisma` in version `7.x`\n- `@prisma/adapter-pg` in version `7.x`\n\n#### Step 3: Enable and configure the environment in your Vitest config\n\nConfigure the environment in your Vitest config:\n\n```ts\nimport { defineConfig } from 'vitest/config';\n\nexport default defineConfig({\n  test: {\n    environment: 'prisma-postgres',\n    environmentOptions: {\n      'prisma-postgres': {\n        // You must configure the path to your prisma client.\n        clientPath: \"./generated/prisma-client\"\n      }\n    },\n    setupFiles: [\n      // Registers hooks that start and roll back a database transaction around every test.\n      'vitest-environment-prisma-postgres/setup',\n      // This is where you mock your Prisma client to use the test environment's client.\n      './vitest.setup.ts'\n    ],\n  }\n});\n```\n\n#### Step 4: Provide a `DATABASE_URL`\n\nThis environment will create the Prisma client and PostgreSQL adapter for your tests, so it has to know the connectionString to your test database.\n\nYou provide it by running your tests with a `DATABASE_URL` environment variable, which must point to a PostgreSQL instance for testing. It can point to:\n\n- a real local PostgresSQL instance\n- a docker-compose container\n- a Testcontainers-created instance (see below)\n- a cloud-hosted PostgresSQL instance, e.g, Supabase or Prisma Postgres\n\n#### Step 5: Mock Prisma client\n\nIn your setupFile, `vitest.setup.ts`, mock your local Prisma client with the client provided by this environment:\n\n```ts\nimport { vi } from 'vitest';\n\nvi.mock('./generated/prisma-client', () => ({\n  default: prismaPostgresTestContext.client,\n}));\n```\n\nThis ensures that your application code uses the Prisma client created by the test environment. Combined with the vitest-environment-prisma-postgres/setup file, which starts and rolls back a transaction around every test, this means all Prisma queries from your code run inside an isolated transaction per test.\n\nPlease make sure that you're mocking exactly the module path that your code is using to import your Prisma client.\n\n#### Step 6: Seed once per test run\n\nMake sure to seed your test database at the beginning of every test run. \n\n## TypeScript configuration\n\nIf you are using TypeScript, make sure to add this environment to your `compilerOptions.types` array in your `tsconfig.json`:\n\n```json\n{\n  \"compilerOptions\": {\n    \"types\": [\n      \"node\",\n      \"vitest/globals\",\n      \"vitest-environment-prisma-postgres\"\n    ]\n  }\n}\n```\n\nThis is required because this environment provides a global type declaration:\n\n```ts\ndeclare global {\n  var prismaPostgresTestContext: PublicPrismaPostgresTestContext;\n}\n```\n\nWithout adding the package to `compilerOptions.types`, TypeScript will not include this global augmentation, and you will get type errors when mocking your Prisma client in `vitest.setup.ts`:\n\n```ts\nvi.mock('./generated/prisma-client', () => ({\n  default: globalThis.prismaPostgresTestContext.client,\n  //                  ^^^^^^^^^^^^^^^^^^^^^^^^^\n  //                  Error: Element implicitly has an 'any' type because\n  //                  type 'typeof globalThis' has no index signature.\n}));\n```\n\n\nAdding \"vitest-environment-prisma-postgres\" to `compilerOptions.types` ensures that the global declaration is loaded and the mock is type-safe.\n\n## Known limitations\n\n- Support for [Vitest pools](https://vitest.dev/config/pool.html#pool) set to `vmThreads` or `vmThreads` is not implemented\n- This environment assumes that tests inside a single worker run one at a time:\n  - Do not use `test.concurrent` for tests that touch the database.\n  - Keep `maxConcurrency` at `1` for DB integration tests so a worker does not run multiple DB tests at once.\n\n## License\n\nMIT\n","readmeFilename":"README.md"}