-
Notifications
You must be signed in to change notification settings - Fork 994
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Testing] Get Jest up and running #502
Comments
Related topic --> adding here so it doesn't get lost. From #181, how do we want to handle:
|
I'm looking into the API side of testing. I think the best would be to have a database or a mocked database somehow, and let tests just run the services and assert on said database (through the prisma client perhaps?) As I mentioned in this topic I think an in-memory SQLite database would be very easy for this. However as @olance also mentioned in that topic: databases are different, you can't just swap out a Postgres databse for an in-memory SQLite database. However if we're thinking of Redwood as the ideal future, we could argue that it's Prisma's job to deal with the database, and we don't care about which database is used, we're only interfacing with the Prisma client. I see 2 options:
Other things: Let me know what you think or if any or none of that makes sense! @thedavidprice @olance @peterp |
If by this you mean: we leave the DB choice to the user and don't try to interfere because it's Prisma's responsibility, then I agree. And actually, I don't think it's a matter of agreeing or not: there's a range of features that exist on Postgres that do not on SQLite (thinking about enums for instance, but there's probably more). And Prisma will for sure adapt from one to another when features exist on both sides, but it cannot make up for missing features between the two systems. Coming from Rails, I see a third options: it's the responsibility of the developer to spin up their own DB. I think trying to be smarter than this would come at a price on flexibility, putting unnecessary constraints on the developer's setup. The way Rails does this, is by having a configuration file for DB credentials, such as: development:
adapter: mysql
encoding: utf8
reconnect: false
database: db_dev
pool: 5
username: root
password:
socket: /tmp/mysql.sock
# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
adapter: mysql
encoding: utf8
reconnect: false
database: db_test
pool: 5
username: root
password:
socket: /tmp/mysql.sock I fill in the information depending on my own setup, and things are ready to roll! |
Thanks for the explanation. I'm not so hot on databases and their features, which is why I like to use tools like Prisma. 😄 I've never used rails, but I the idea of just configuring another DB for tests LGTM. This is kind of what I've been doing in my experiments using Cypress with Prisma; just exporting a different
On a sidenote I remember I was using enums in SQLite with Prisma not too long ago. Of course that's "fake" on the SQLite side, but the Type checking by Prisma Client is real. They recently removed that, but might bring it back in the shape of Polyfills: prisma/specs#382 Like I said I'm not much of a backend developer, so I kind of get the problem, but I'm having some trouble coming up with a concrete example where a SQLite DB in a test wouldn't work/would make the test bad when I'm using Postgres in the actual application. Do you have an example for that? |
Hmmm... I guess if I'm building an app with geolocation features, I would choose to use Postgres with its postgis extension to handle that. Then I guess I wouldn't be able to have tests running for those queries that need postgis, if I can't provide my own database instance to the tests process. I don't have such an extended experience myself that I'm gonna be able to find the example that solves the conversation I believe... however I do think we can look at it this way:
On that last point, here are a few ideas:
|
I think this is good. Kind of what I have in my head! Default simple SQLite (possibly in-memory if that gets support) and override with own DB when needed.
Not exactly (I think), but you could get the same effect using environment variables in your |
👍 |
@RobertBroersma I think what you've suggested so far is super reasonable, especially based off of this comment: https://github.com/prisma/prisma-client-js/issues/317#issuecomment-574164787 |
As discussed on the forum
Goal
To be able to succesfully run
yarn rw test
after creating a new app and generating new components.Steps
@redwoodjs/router
Routes to work inside tests.The text was updated successfully, but these errors were encountered: