Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ctrlplusb/prisma-pg-jest
Example showcasing how to use Prisma + Postgres + Jest, where each test has its own unique DB context
https://github.com/ctrlplusb/prisma-pg-jest
example jest postgres prisma prisma2
Last synced: 3 days ago
JSON representation
Example showcasing how to use Prisma + Postgres + Jest, where each test has its own unique DB context
- Host: GitHub
- URL: https://github.com/ctrlplusb/prisma-pg-jest
- Owner: ctrlplusb
- Created: 2019-12-05T02:40:39.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2023-01-06T02:19:34.000Z (almost 2 years ago)
- Last Synced: 2024-10-23T08:50:13.307Z (12 days ago)
- Topics: example, jest, postgres, prisma, prisma2
- Language: TypeScript
- Homepage:
- Size: 900 KB
- Stars: 103
- Watchers: 4
- Forks: 7
- Open Issues: 13
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
- awesome-prisma - Testing Prisma with PostgreSQL and Jest
README
# Prisma + Postgres + Jest
This example showcases how you can configure your Jest environment in order to perform integration tests against applications utilising Prisma and Postgres.
Each test suite will create a temporary schema within the database, allowing concurrent execution of them. The temporary schema is subsequently cleaned up after each test suite has completed.
## Setup
Clone the repo.
```bash
git clone https://github.com/ctrlplusb/prisma-pg-jest
```Install the dependencies.
```bash
cd prisma-pg-jest
npm install
```## Running the database
A `docker-compose.yml` file has been created to represent the Postgres database that we will use for local development.
You will need [Docker](https://docs.docker.com/v17.09/engine/installation/) installed.
To start the database run the following command:
```bash
npm run db:start
```Once you are finished developing you can stop the db by running the following command:
```bash
npm run db:stop
```This project has been configured to run with the following Postgres configuration. You can modify these to suit your needs by editing the [`docker-compose.yml`](docker-compose.yml) file.
```
- HOST=localhost
- PORT=54320
- POSTGRES_USER=prisma
- POSTGRES_PASSWORD=hilly-sand-pit
- POSTGRES_DB=prisma
```## Jest Configuration
We have configured Jest to execute with a custom test environment. See the [`prisma/prisma-test-environment.js](prisma/prisma-test-environment.js) file for more details.
This custom environment ensures that each test suite getting executed will have a unique schema created for them against the running Postgres database. The migrations will then be executed against them, via the `prisma migrate up --experimental` command, ensuring that the latest model has been applied to the schema.
## Running your tests
Ensure that your local Postgres is running.
```bash
npm run db:start
```Then execute the Jest tests via the following command:
```bash
npm run test
```