Open cruessler opened 4 weeks ago
@extrawurst I just marked this PR as ready for review! I found it way easier to create the test than I had anticipated, mostly because the application is already structured in a way that is very amenable to snapshot testing.
Known issues:
sleep
after sending events to the app, and I found that the test on Windows failed before I found a value that didn’t fail. 500
most likely is way too high. I don’t exactly know what the best approach here is. In an ideal world, we would have something like wait_for
which we could use to wait for specific events that would indicate that the app has finished loading or gotten a specific kind of async result.App
and the test as the test currently requires a bit of setup that in turn requires certain knowledge about how App
works. By abstracting that away, writing tests might get even easier. Another option is to move the existing setup or parts of it into App
.@extrawurst Did you get a chance to have a look? :smile:
@cruessler ok i think this is a great prototype but i don't think its ready to be merged in this form.
main.rs
what you pointed out would allow us to put this into a testing suite: putting what we have now in main on top of App
into another layer, lets call it simply Gitui
that we can then use in our tests with a proper public api.@extrawurst I’ve extracted app initialization as well as the main loop into a new struct, Gitui
. main.rs
is now a lot lighter, with the code and tests living in gitui.rs
.
I’m not sure about how to best implement a busy loop, though. We might be able to send the event that we get here, through a channel to the caller. Then, we could, in the caller, have a recv_timeout
that we could use to wait for specific events. Does that sound like a possible solution? (I’m only vaguely familiar with crossbeam
, so I’m happy about any context that you might be able to share.)
@cruessler awesome!
through a channel to the caller
yeah lets do that. and please fix the clippy lints
@extrawurst This PR is another try at adding snapshot tests to
gitui
. It doesn’t render to SVG as some of the other approaches do, but it works with the existingApp
anddraw
and only requires a minor type change in order to get it to work. Also, the text-based snapshot is still reasonably easy to read. So this feels very promising.Next, I want to try to write a test that has interactivity, be it loading data from an actual git repo or keyboard input from a user.