npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@iodome/prisma

v0.4.1

Published

<img width="84" height="78" alt="iodome-logo-3" src="https://github.com/user-attachments/assets/69aacbd2-6305-4fac-a842-22637d8b0439" />

Readme

@iodome/prisma

Prisma utilities for complete test data isolation support for Postgres in Playwright and Vitest. Ensures each test runs with a fresh, isolated database state to prevent test interference and flaky tests.

Installation

npm install --save-dev @iodome/prisma
# or
pnpm add -D @iodome/prisma
# or
yarn add -D @iodome/prisma

Features

  • 🔒 Complete test isolation - Each test runs in its own database state
  • Fast execution - Template databases for Playwright, transactions for Vitest
  • 🔄 Automatic cleanup - No manual database cleanup needed
  • 🏃 Parallel testing - Run tests in parallel without conflicts
  • 🛠️ Easy integration - Works with your existing Prisma setup

Usage

Playwright (E2E Testing)

1. Create test fixtures

// tests/fixtures.ts
import { PrismaClient } from "@prisma/client";
import { createTestFixtures } from "@iodome/prisma/playwright";

export const test = createTestFixtures(PrismaClient);

2. Set up global hooks

// global.setup.ts
import { createTemplateDatabase } from "@iodome/prisma/playwright";

export default async function globalSetup() {
  // Create a template database for faster test initialization
  await createTemplateDatabase();
}
// global.teardown.ts
import { dropDatabases } from "@iodome/prisma/playwright";

export default async function globalTeardown() {
  // Clean up all test databases
  await dropDatabases();
}

3. Configure Playwright

// playwright.config.ts
export default defineConfig({
  globalSetup: "./tests/e2e/global.setup.ts", // path to setup file
  globalTeardown: "./tests/e2e/global.teardown.ts", // path to teardown file
  // ...
});

4. Write tests

// tests/example.spec.ts
import { test } from "./fixtures";
import { expect } from "@playwright/testing";

test("create and verify user", async ({ page, prisma }) => {
  // Create test data with isolated Prisma client pointing
  // to an unique database per test
  const user = await prisma.user.create({
    data: {
      name: "Test User",
      email: "[email protected]",
    },
  });

  // Test your application
  await page.goto("/users");
  await expect(page.getByText(user.name)).toBeVisible();
});

Vitest (Unit/Integration Testing)

1. Set up test isolation

// vitest.setup.ts
import prisma from "@/prisma/db";
import { wrapTestsInTransactions } from "@iodome/prisma/vitest";

wrapTestsInTransactions(prisma);
/* wraps tests in transactions using
beforeEach, afterEach from vitest /*

2. Configure Vitest

// vitest.config.ts
export default defineConfig({
  test: {
    setupFiles: ["./vitest.setup.ts"],
    // ... other config
  },
});

3. Write tests

// tests/actions/articles.test.ts
import prisma from "@/prisma/db";
import { describe, it, expect } from "vitest";
import { getComments } from "../actions/articles";

describe("getComments", () => {
  it("returns comments for an article in descending order", async () => {
    const article = await prisma.article.create({
      data: {
        title: "title",
        content: "content",
      },
    });
    const firstComment = await prisma.comment.create({
      data: {
        content: "first comment",
        articleId: article.id,
        authorId: user.id,
      },
    }); // ... secondComment, thirdComment

    const comments = await getComments(article.id);

    expect(comments).toStrictEqual([thirdComment, secondComment, firstComment]);
  });
});

How It Works

Playwright Mode

  • Creates a separate PostgreSQL database for each test (pattern: iodome_test_[testId])
  • Uses a template database for fast initialization
  • Automatically starts a test server with isolated database
  • Cleans up databases after tests complete

Vitest Mode

  • Wraps each test in a PostgreSQL transaction
  • Automatically rolls back all changes after each test
  • Much faster than creating separate databases
  • Perfect for unit and integration tests

Configuration

Environment Variables

  • DATABASE_URL - PostgreSQL connection string (required for Playwright)
  • IODOME_DEBUG - Enable query logging
  • CI or IODOME_BUILD - Use production server command instead of dev - better for running large amounts of tests.

Database Requirements

  • PostgreSQL (tested with versions 12+)
  • Default connection: postgres://postgres:postgres@localhost:5432

API Reference

Playwright

createTestFixtures(PrismaClientConstructor)

Creates Playwright test fixtures with an isolated database.

Returns: Extended test object with fixtures:

  • prisma - Isolated PrismaClient instance pointing to your isolated database
  • baseURL - URL of the test server
  • All standard Playwright fixtures (page, context, etc.)

createTemplateDatabase()

Creates a template database for faster test initialization. Call in global setup.

dropDatabases()

Removes all test databases. Call in global teardown.

Vitest

wrapTestsInTransactions(prismaClient)

Enables transaction-based test isolation. Call once in setup file.

Parameters:

  • prismaClient - Your configured PrismaClient instance

Best Practices

  1. Playwright: Always use global setup/teardown for template database management
  2. Vitest: Call wrapTestsInTransactions() once in your setup file
  3. Performance: Use template databases for Playwright tests with complex schemas

Troubleshooting

Tests are slow

  • For Playwright: Ensure you're using createTemplateDatabase() in global setup
  • For Vitest: Verify transactions are enabled with wrapTestsInTransactions()

Database not found errors

  • Check your PostgreSQL server is running
  • Ensure your PostgreSQL user has CREATE DATABASE permissions

Tests are flaking

  • This is more likely to happen when running large amounts of tests using playwright. Using a production-like server (i.e. next start) instead of a dev server (i.e. next dev) is much more reliable and will use far less resources on your machine. The tradeoff is that you'll have to run your build (i.e. next build) before running your test.

I have found that using dev servers is faster for test-driven development where I'm rerunning a single test, and using production servers is better when running my test suite locally or in CI. Due to the amount of resources used by spinning up a lot of dev servers in parallel, flakiness becomes more of an issue.

Using production servers on my local machine, I was able to run 600 playwright tests across 12 workers with consistent success. This will vary from machine to machine.

License

MIT © Michael (fundefined)