-
Notifications
You must be signed in to change notification settings - Fork 971
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
Allow configuring test database #691
Conversation
@RobertBroersma I'm excited about the overall approach here. The
^^ you're referring to the "test" db, correct? I wasn't quite sure I'm following this part -- but for me if you mean DB Config and CommandPeter is removing the DB process from I'm not quite understanding the config options "test" and "dev" -- how are they different? Or is it that you're just making the existing "dev" option from env.default explicit in the config, and also adding the "test"? I know Peter has been thinking about how to handle the Database in general as he's been doing work on Sides. I'll default to him in general, but some thoughts:
Misc
|
@thedavidprice Thanks for the feedback! I'll try to explain my thoughts going into the points you mentioned.
I was more referring to how I'd like to remove calling
I was thinking it would be weird to define one DB from
Tbh I don't know! I could imagine having a Postgres instance for dev and a SQLite (inmemory) for test for speed. I know other's don't really like this approach tho.
|
Ah, I completely misunderstood. That does make sense to me. Although, let it be clear that I defer all decisions and primary direction to @peterp 😆 And I do know there's some re-thinking happening about how to name structure the current "primsa/" to make it more flexible and general as "db/". I'm thinking out loud, but re-reading your comments makes me question how much of this config should initially be exposed. A part of this feels to me like we could move forward under the "Redwood's handles API tests like this out of the box and makes these convention assumptions..." E.g. you're going to have a Anyway, that's my day 2 take. Kicking things over to @peterp |
@thedavidprice Out of the box defaults sound good to me! In fact, I think the way I set it up it should already default to this config 😅 |
@thedavidprice @peterp I'm also considering whether or not we should expose an Apollo Test Client You would then instead of calling the services directly, test your services by sending queries. This involves the entire request chain, which would e.g. prevent typos in your Downsides would include awkward location of the queries? I wouldn't want to duplicate the queries used in Cells just to test them in the API side. But I also don't want to import them from a Cell? Do I locate them somewhere else? 🤷♂️ This "problem" might be mitigated by the ability to do e2e tests in the web side (something I am working on!), which I would personally use most, and then I would only test on the API side things that aren't (directly) consumed by the frontend I guess. Anyway I hope I'm making some kind of sense, rant over! |
Hey @RobertBroersma 👋, I'm going to summarise my understanding of the thing we're trying to solve: The main idea is that we're able to run tests against a real database. The steps are the following:
So, what do we need?
|
I think you're right that it probably makes more sense that this works with e2e tests! I think there's some benefit in having unit tests for services. I think our diagnostic stuff from decoupled studio will solve the majority of issues that people will have when integrating the SDL to the services side. (We should jump on a call and I can show you some of the diagnostics stuff, I think it's right up your alley of interesting things to work on.) |
I think we should!
I think right now it could easily work using an env var for the connection string. The other thing we might need is a My initial worry was that e.g. a postgres db might have (in the future?) more config options than just a provider and a connection string. If this is not the case I think the env var route is indeed easier. In any case I can simplify the PR so that it works with env vars instead of redwood.toml for starters! |
Agreed! I guess the simplicity of testing services directly outweighs the benefits of running the queries. I'd be very interested to see the diagnostics stuff. Aldo's presentation last week looked very promising, but I'd be lying if I said I understoof all of it. 😅 |
Ah, good call!
I can't really think of anything else off the top of my head right now, but I'm sure we can come up with something elegant if/ when that happens. |
@peterp I've replaced the I keep getting this error tho when running the tests:
Can't really grasp what that means, any ideas? |
👋 Hi again
I created a little setup that allows users to define a
dev
db and atest
db in theirredwood.toml
file as discussed as an option in #502I think it works pretty well.
I want to move (at least) one thing around: move the database
up
to inside the api test setup file. This would allow us to more easily split up jest project files later and separate concerns from the CLI command. (Also allowing users to pass jest--flags
toyarn rw test
.I would also like to test this somehow. Maybe this could be part of some kind of test suite for the tutorial that was talked about during yesterday's call.
When this PR is a bit more polished it would also be great to test it out with some other databases. However until you can set
provider
through an env variable, that option won't really do anything. So it would currently be limited to being able to configure multiple of the same db provider.Example
redwood.toml
: https://github.com/RobertBroersma/redwood-testing/blob/master/redwood.tomlExample service test file: https://github.com/RobertBroersma/redwood-testing/blob/master/api/src/services/posts/posts.test.js
@peterp @thedavidprice What do you think, does this look usable?