-
Notifications
You must be signed in to change notification settings - Fork 71
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
refactor(test): heavily simplify the context
helper
#404
Merged
ezolenko
merged 2 commits into
ezolenko:master
from
agilgur5:refactor-test-simplify-context
Aug 25, 2022
Merged
refactor(test): heavily simplify the context
helper
#404
ezolenko
merged 2 commits into
ezolenko:master
from
agilgur5:refactor-test-simplify-context
Aug 25, 2022
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
agilgur5
added
kind: internal
Changes only affect the internals, and _not_ the public API or external-facing docs
scope: tests
Tests could be improved. Or changes that only affect tests
labels
Jul 29, 2022
- since we're type-casting it anyway, we can heavily simplify this and remove the stubs entirely - they're actually unused in the unit tests, so we don't need them at all - besides the type-checking, which we force with a cast anyway - the `as unknown as` is bad practice, and probably why I didn't use it initially (plus other typing issues), but it's much simpler this way and reflects the intent better -- just making it type-check with the few properties we use - we can also use Jest mocks directly instead of the hacky `contextualLogger` and passing `data` in - `makeContext` now creates the mocks, so we just need to check against `context.error` etc - this is _much_ more familiar as it's what we use in the source and follows idiomatic Jest - rewrite all the checks to test against the mocks instead - I thought this felt too complicated / verbose before, but I had left this as is from brekk's initial test structure - now that I understand all the tests and test intent much better, I could rewrite this to be a good bit simpler - make the `toBeFalsy()` checks more precise by checking that the mock _wasn't_ called - it returns `void` anyway, so `toBeFalsy()` _always_ returns true; it's not much of a test - checking that the low verbosity level didn't trigger the mock to be called actually checks the test's intent
- `get-options-overrides`'s coverage func % decreased bc funcs passed to `context.debug` weren't being called - took me a bit to notice too since we have no coverage checks - and then another bit to realize _why_ it decreased
agilgur5
force-pushed
the
refactor-test-simplify-context
branch
from
August 24, 2022 15:40
9385152
to
7e316b8
Compare
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
kind: internal
Changes only affect the internals, and _not_ the public API or external-facing docs
scope: tests
Tests could be improved. Or changes that only affect tests
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
NOTE: this is built on top of #397 as that also uses thecontext
helper. It may also merge conflict with #396 if that is merged. As such, I've marked this PR as "Draft" until those PRs are merged (or otherwise closed).Rebased on top, fixed merge conflicts, and marked as ready for review.
Summary
Significantly simplify the
context
helper used in the unit tests with more forceful type-casting and directly using Jest mocks. This makes all usage ofcontext
significantly easier and less hacky, as can be seen in the changed tests here.Details
since we're type-casting it anyway, we can heavily simplify this and remove the stubs entirely
as unknown as
is bad practice, and probably why I didn't use it initially (plus other typing issues), but it's much simpler this way and reflects the intent better -- just making it type-check with the few properties we usewe can also use Jest mocks directly instead of the hacky
contextualLogger
and passingdata
inmakeContext
now creates the mocks, so we just need to check againstcontext.error
etcmake the
toBeFalsy()
checks more precise by checking that the mock wasn't calledvoid
anyway, sotoBeFalsy()
always returns true; it's not much of a test