Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/tockn/prisma-database-rewinder
https://github.com/tockn/prisma-database-rewinder
Last synced: 3 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/tockn/prisma-database-rewinder
- Owner: tockn
- Created: 2024-03-21T17:48:49.000Z (10 months ago)
- Default Branch: main
- Last Pushed: 2024-03-21T18:07:57.000Z (10 months ago)
- Last Synced: 2024-11-10T21:42:53.185Z (2 months ago)
- Language: TypeScript
- Size: 11.7 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# prisma-database-rewinder
[![npm version](https://badge.fury.io/js/prisma-database-rewinder.svg)](https://badge.fury.io/js/prisma-database-rewinder)
`prisma-database-rewinder` is a port of [database-rewinder](https://github.com/amatsuda/database_rewinder) for [Prisma](https://github.com/prisma/prisma).
This library is designed to **extremely fast** clean up test database records in Integration tests using a database.
It's currently intended for use with Jest and PostgreSQL.## Installation
```
npm install prisma-database-rewinder
or
yarn add prisma-database-rewinder
or
pnpm add prisma-database-rewinder
```## Usage
At the beginning of your Jest test file, include the following setup:
```typescript
// prepare prisma client for test db
const prismaTestClient = new PrismaClient();const rewinder = new PrismaDatabaseRewinder(prismaTestClient);
beforeAll(async () => {
await rewinder.beforeAll();
});
afterEach(async () => {
await rewinder.afterEach();
});
```This setup ensures that your test database is cleaned up before all tests run and after each test completes, keeping your database in a consistent state and ready for the next test.