Running Test for prisma on console output

Sometimes to test the logic, we need to run the test on the local machine in the console. To do it, we can create a simple module and a test script. then we can configure this test script in the script command in package.json file. 

Then using the following command, you run the test code.

const {PrismaClient} = require("@prisma/client");
async function helloPrisma() {
    const {user} = new PrismaClient();
    const userDetails = await user.findFirst({
        where: {
            id: 1
        }
    });
    return userDetails;
}
module.exports = { helloPrisma }

tests.js code

const {helloPrisma} = require ("./group");
helloPrisma().then( r => r).then(r=>console.log(r));
console.log("Test Completed");
process.exit(0);

Now add the following line in package.json

"test": "node services/group-tests.js",

and then run the following command

npm test

 

 

Tags