Search code examples
node.jsmocha.jsprismaexpress-graphqlprisma-graphql

How to set up a different database for testing in prisma?


I want to use a different database for testing my app instead of local database.

this is my env file

# Environment
NODE_ENV=development

# Backend
API_PORT=4000
APP_SECRET=omg
DASHBOARD_URL=http://localhost:1234

# Prisma
PRISMA_ENDPOINT=http://localhost:4466
PRISMA_SECRET=omg
PRISMA_MANAGEMENT_API_SECRET=omg

what I have tried is changing the Prisma endpoint into http://localhost:4466/default/test

but, then how to dynamically change the endpoint? so that when I need to run the app it will point to that http://localhost:4466/default/default and when I need to run test suits it will point to that http://localhost:4466/default/test endpoint.


Solution

  • you can testing against a test stage.

    all you need is two different env file. one is for the development environment and one is for testing environment.

    • on .env.dev: http://localhost:4466/default/default
    • on .env.test: http://localhost:4466/default/test

    after that, you can run docker separately for development and test environment.