feat: tests can opt-in to retries
Problem
Tests have no way to retry without manually managing before_each and after_each setup/teardown. This is painful. And busted does a good job of guarding its internals and makes it impossible to extend it: AFAICT, consumers have no way to access the current "test context", or the current list of before_each/after_each hooks.
Solution
Introduce env.set_retries(), which allows test authors to optionally retry a test:
it('...', function()
set_retries(2) -- If the test fails, it will be retried up to 2 times.
end)
Todo
- On a fresh clone of this repo there are
91 failures(and 1583 successes).- I have only checked that this PR doesn't add new failures.
- ~~Haven't added docs/tests, want to see if this will be acceptable first.~~
- Should the test have access to the current retry number? I don't get why busted gives zero context to tests.
- Also send to https://github.com/lewis6991/nvim-test
* Haven't added docs/tests, want to see if this will be acceptable first.
Yes, I think I'm up for having this added.
* Should the test have access to the current retry number? I don't get why busted gives zero context to tests.
Yes I think it probably should be exposed.
Historically I think (speculating here) the reason zero context has been given is just because we're clearing out the environment and isolating tests and exposing any context would mean adding a new API surface to explicitly start making some things available inside the isolated test runner scope.
Thanks, I'll follow up on this then.
Any guidance on the interface? Defining new magic globals like set_retries feels a bit weird but that seems to be the pattern. Is set_retries the right name?
That sounds okay, but the code you used is a little confusing. We should either set the number of retries (zero being don't attempt any retries after failure) and default it to zero or set the max attempts and default it to one, but preferably not mix and match and have to calculate one from the other in code. Not that the math is hard, just that the code will be neater if the logic aligns with the interface naming the end user is seeing.
Don't look at the code yet, it's a broken mess :)
Still needs cleanup (and more tests), but the functionality (AI-generated) seems to work now.
Note: On a fresh clone of this repo there are 91 failures (and 1583 successes). I have only checked that this PR doesn't increase the failures.