test(cacheable-request): replace sqlite3 test dependency with mock store#1668
Merged
Conversation
cacheable-request pulled in sqlite3 and @keyv/sqlite as devDependencies
solely to exercise two cache-connection error paths in its tests
(CacheError emission and automaticFailover fallback). sqlite3 is a heavy
native module: it needed an allowBuilds entry and carried two copies in
the lockfile (6.0.1 directly + 5.1.7 transitively via @keyv/sqlite).
Replace the two KeyvSqlite("sqlite://non/existent/database.sqlite") usages
with a lightweight in-test mock store whose operations reject with a
SQLITE_CANTOPEN-coded error. This preserves the exact coverage (the error
event path was already covered separately via a plain Keyv instance)
without a native dependency. SQLite remains a fully supported storage
adapter for users of the library.
- Drop @keyv/sqlite and sqlite3 devDependencies and the testdb.sqlite
path from the clean script
- Remove the sqlite3 allowBuilds entry and the testdb.sqlite .gitignore line
- Regenerate pnpm-lock.yaml
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011PoyCZFLpx5BXNih6jNiaQ
Contributor
There was a problem hiding this comment.
Code Review
This pull request removes the native SQLite dependencies (sqlite3 and @keyv/sqlite) from the cacheable-request package and replaces them with a mock unopenable store in tests to simulate database connection failures without a native driver. The review feedback suggests making the mock store's operations asynchronous to more accurately simulate a real database-backed Keyv store, and refactoring the error creation to avoid using the any type.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1668 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 29 29
Lines 3504 3504
Branches 810 808 -2
=========================================
Hits 3504 3504 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Address review feedback on the unopenable mock store: make its operations async so they reject a Promise (mirroring a real async Keyv adapter), and use Object.assign to attach the SQLITE_CANTOPEN code instead of an `any` cast. No behavior or coverage change. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011PoyCZFLpx5BXNih6jNiaQ
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Please check if the PR fulfills these requirements
What kind of change does this PR introduce? (Bug fix, feature, docs update, ...)
Test/build maintenance — removes an unnecessary native dependency.
cacheable-requestpulled insqlite3and@keyv/sqliteasdevDependenciessolely to exercise two cache-connection error paths in its tests (CacheErroremission andautomaticFailoverfallback).sqlite3is a heavy native (node-gyp) module: it required anallowBuildsentry inpnpm-workspace.yamland carried two copies in the lockfile (6.0.1directly +5.1.7transitively via@keyv/sqlite).This PR replaces the two
new KeyvSqlite("sqlite://non/existent/database.sqlite")usages with a small in-test mock Keyv store whose operations reject with aSQLITE_CANTOPEN-coded error. The mock reproduces the exact paths the SQLite adapter exercised:CacheErrorwhen the cache store fails onget()automaticFailoveris enabled and the store failsThe error-event path was already covered separately by an existing test that uses a plain
new Keyv()instance, so no coverage is lost.Changes
KeyvSqlitetest usages with acreateUnopenableStore()mock incacheable-request-instance.test.ts@keyv/sqliteandsqlite3devDependenciesand thetestdb.sqlitepath from thecleanscriptsqlite3allowBuildsentry frompnpm-workspace.yamland thetestdb.sqliteline from.gitignorepnpm-lock.yamlVerification
pnpm --filter cacheable-request lintpasses with no fixes appliedcacheable-request-instance.test.tspass, including the two former-SQLite testscache.test.ts > "return with url and port") is a pre-existing network timeout to the external hostmockhttp.org:8080— it is unreachable in sandboxed environments and does not touch any removed dependency🤖 Generated with Claude Code
https://claude.ai/code/session_011PoyCZFLpx5BXNih6jNiaQ
Generated by Claude Code