Testing in Redwood

Kind of late to the party here but just wanted to say thanks for all of the thoughtful responses here. At my day job we are actually trying to figure out how to add Cypress testing into our Django monolith with a Vue.js frontend and had almost the same questions about the best approach. I’m still trying to figure out what approach we are going to take, and most of the pros and cons have already been listed here.

At least the great part about Redwood is that it is JS all the way through the stack; at my company our frontend devs are going to be writing Cypress tests, but would currently have to write a lot of Django ORM code to seed the database. We talked about mocking the data via JSON but not only can it get out of sync with the underlying data models, but then it isn’t even a true e2e test.

Needless to say I’m hoping I can learn from more of this conversation (which is might be dated at the velocity you guys are going at :slight_smile: ). Seems like I should look into Mirage JS. If/when Redwood has type checking all the way through from React -> DB schema, perhaps it will be easier for the tests to stay in sync with schema changes? Perhaps that is what you guys are saying would be the goal of using the factory method, sorry if I’m simply repeating what you already said, just in a more verbose way :grin:

3 Likes

Hi Aaron!

Thanks for your reply. We are not even close to done with this so any feedback is welcome :smiley:

What I would do in your case is create some API endpoints in your backend that enable you to create data in your database with a Cypress request (You probably already have these endpoints, because you need them in your app!).

Mirage is a great tool, but I would only use it if you’re developing FE before BE.

4 Likes

That’s absolutely one of the biggest benefits of the factory pattern, but it only works well if you have full control over your database layer.

I haven’t tried this, but it should be possible to automate a prisma introspect on your existing Django DB and then use factories to seed it in your tests before running cypress tests.

Outside of that, you may just have to open up endpoints only in the test ENV and use those to seed it (this sounds like what you’re doing currently)