mardi 15 septembre 2020

Testing flow using prisma and graphql

I'm using prisma-graphql for backend server, and jest & supertest for testing graphql queries. For testing environment, I'd like to establish an in-memory database to create and retrieve data during test-phase. My questions are,

  1. What is a good way to configure a test DB for prisma client? Do I need to configure a memory DB at before all phase? like below?

    //setup.js for test
    
    beforeAll(async() => {
      db = new sqlite3.Database(':memory:', (err) => {
        if (err) {
          return console.error(err.message);
        }
        console.log('Connected to the in-memory SQlite database.');
      });
    })
    
  2. How & when can I run the commands for prisma? For instance, I need to run the below commands for in memory db, to create tables. https://github.com/prisma/prisma/issues/732 seems to suggest that in memory migration doesn't make sense - in other words, it does not support such thing?

    npx prisma migrate --experimental save/up
    npx prisma generate
    

Aucun commentaire:

Enregistrer un commentaire