test(logger): migrate to vitest & custom matchers #3131
Merged
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.
Summary
Changes
This PR migrates the unit tests for the Logger utility to use Vitest rather than Jest.
With this change, we can also finally start investing time/effort in custom matchers that can further reduce the boilerplate we write in our tests.
The first example of this are two new custom matchers introduced in this PR:
These two matchers will be available across all the test suites of our project and allow you to assert that a mocked console method has emitted a specific JSON-structured object.
Before this change, to use the matcher we had to directly drill down the mock calls and manually parse the object each time like this:
expect(JSON.parse(logSpy.mock.calls[0][0])).toEqual(...)
.These new matchers, in addition to providing a more ergonomic call signature, also provide better error messaging when tests fail. The new matchers leverage framework APIs and provide a more targeted diff between expected and received objects.
Besides the above, the tests are largely unchanged except for 2 new test cases being added due to the new coverage reporter (now using v8 instead of istanbul).
Issue number: closes #3130
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.
Disclaimer: We value your time and bandwidth. As such, any pull requests created on non-triaged issues might not be successful.