Skip to content
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

Improve testing for model #11

Open
antonmedv opened this issue Sep 12, 2023 · 7 comments
Open

Improve testing for model #11

antonmedv opened this issue Sep 12, 2023 · 7 comments

Comments

@antonmedv
Copy link

For example, I'd like to test my https://fx.wtf app. But right now testea only tests final output (which is 0 for fx).

I'd like to be able to send keystrokes and check intermediate results (same with -update model).

@caarlos0
Copy link
Member

It's possible to do that with waitfor: https://github.com/charmbracelet/x/blob/main/exp/teatest/app_test.go#L64

@antonmedv
Copy link
Author

It is, but not as easy as snapshotting of final result with RequireEqualOutput.

Will be cool to have similar snapshots for the intermediate model state.

@caarlos0
Copy link
Member

unfortunately its not as easy while the app is running, as you might get an "old" "snapshot", of the output, that's why there's the WaitFor, in which you can keep checking the output for X time every Y interval.

@antonmedv
Copy link
Author

It is understandable. But for my app after key press is done it will "freeze". So "snapshot" is possible.

@caarlos0
Copy link
Member

unfortunately, no, it isn't, as we can't guaranteed that the event was already processed after you send it, so you'll likely end up with a bunch of time.Sleep to try to synchronize the work.

you could do something like:

var snapshot []byte
teatest.WaitFor(t, tm.Output(), func(out []byte) bool {
  snapshot = out
  return true
}, teatest.WithDuration(time.Second), teatest.WithCheckInterval(time.Millisecond*100))

// verify snapshot

but I don't see how that's better than doing it inside WaitFor.


Forgot to add earlier: as for the model throughout the run, you have it when you start the test, so you can test it directly.

@caarlos0
Copy link
Member

Oh, you can also read tm.Output() at any given time.

@antonmedv
Copy link
Author

Oh, you can also read tm.Output() at any given time.

For some reason it is nil. But the snapshot technic works.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants