I was fiddling around with testing in Cypress within a Redwood/Prisma application and it works pretty neatly!
It’s very convenient to do database operations using the generated PrismaClient
when setting up your tests.
cy.task('db', {
operation: 'post.create',
variables: {
data: randomPost,
},
}).as('newPost')
cy.visit('/posts')
cy.assertOnThatPost()
It does require some setup with babel, and then I couldn’t figure out how to import the db
from the api/src/lib/db.js
file, so I just created a new PrismaClient
that uses the same SQLite file.
Note: You might want a separate db file and clean db before every test. Not sure how to do that!
Example repo: