keyv - chore: adding tests for code coverage#1845
Conversation
Summary of ChangesHello @jaredwray, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request enhances the test suite for the Highlights
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request adds two new tests to improve code coverage. The first test verifies that setting a Symbol value correctly throws an error and emits an error event. The second test ensures that Keyv can detect an iterable adapter based on the store's URL when a dialect is not specified. My review includes a suggestion to refactor the mock store in the second test to make it simpler, more maintainable, and more accurate.
| const map = new Map<string, unknown>(); | ||
| const store = { | ||
| opts: { url: "redis://localhost:6379" }, | ||
| async get(key: string) { | ||
| return map.get(key); | ||
| }, | ||
| async set(key: string, value: unknown) { | ||
| map.set(key, value); | ||
| }, | ||
| async delete(key: string) { | ||
| return map.delete(key); | ||
| }, | ||
| async clear() { | ||
| map.clear(); | ||
| }, | ||
| async *iterator(namespace?: string) { | ||
| for (const [key, value] of map) { | ||
| if (!namespace || key.startsWith(namespace)) { | ||
| yield [key, value]; | ||
| } | ||
| } | ||
| }, | ||
| on() { | ||
| return store; | ||
| }, | ||
| }; |
There was a problem hiding this comment.
The mock store object is more complex than necessary for this test. The get, set, delete, clear, and iterator methods are not actually used by the logic under test, which only checks for the presence of the iterator method. You can simplify this by using test.vi.fn() for the unused methods and providing an empty generator for iterator. This also removes the need for the map variable.
Additionally, the on() method mock is incorrect. It should accept arguments and return the store instance to be compliant with the IEventEmitter interface. Using test.vi.fn().mockReturnValue(store) is a better approach.
const store = {
opts: { url: "redis://localhost:6379" },
get: test.vi.fn(),
set: test.vi.fn(),
delete: test.vi.fn(),
clear: test.vi.fn(),
async *iterator() { /* empty */ },
on: test.vi.fn(),
};
store.on.mockReturnValue(store);
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1845 +/- ##
==========================================
+ Coverage 99.79% 99.95% +0.16%
==========================================
Files 32 32
Lines 2432 2432
Branches 448 448
==========================================
+ Hits 2427 2431 +4
+ Misses 5 1 -4 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Please check if the PR fulfills these requirements
What kind of change does this PR introduce? (Bug fix, feature, docs update, ...)
keyv - chore: adding tests for code coverage