
Product
Announcing Precomputed Reachability Analysis in Socket
Socketโs precomputed reachability slashes false positives by flagging up to 80% of vulnerabilities as irrelevant, with no setup and instant results.
@variablesoftware/mock-kv
Advanced tools
๐๏ธ๐ท๏ธโจ Mock KV Namespace for testing Cloudflare Workers
Mock Cloudflare KV Namespace for unit and integration testing
๐๏ธ๐ท๏ธโจ @variablesoftware/mock-kv
provides an in-memory simulation of Cloudflare Workers KV. It is designed for testing key-value storage logic with expiration, metadata, and batch operations โ without any external dependencies.
yarn add --dev @variablesoftware/mock-kv
This package assumes a test environment with Vitest and support for ESM.
import { mockKVNamespace } from '@variablesoftware/mock-kv';
const kv = mockKVNamespace();
await kv.put('token-abc', 'value', { expirationTtl: 60 });
const result = await kv.get('token-abc');
console.log(result); // 'value'
@variablesoftware/logface
is required for test and runtime logging, but does not rely on any external servicesIncludes matching behavior for edge cases like:
Key expiration mid-test
list()
with prefix collisions and limits
Metadata preservation across put/get calls
In-memory mock of Cloudflare KVNamespace
Supports put
, get
, delete
, list
, and metadata options
TTL-aware: honors expirationTtl
and expiration
Returns values as string
, ArrayBuffer
, or null
just like real KV
Simulates listing behavior including prefix + limit
Supports metadata in put()
and getWithMetadata()
Compatible with Vitest and any Cloudflare Worker test setup
Logs via @variablesoftware/logface
Optional .dump()
method for inspecting KV state during tests
Tested using vitest run
, with coverage for:
put()
with TTL and metadataget()
and getWithMetadata()
matching real behaviordelete()
and list()
consistency.dump()
snapshots for inspection and debuggingRun tests:
yarn test
This package is under active development and not yet stable.
Once stable, it will be published as:
"@variablesoftware/mock-kv": "^0.5.0"
MIT ยฉ Rob Friedman / Variable Software
Built with โค๏ธ by @variablesoftware
Thank you for downloading and using this project. Pull requests are warmly welcomed!
FAQs
๐๏ธ๐ท๏ธโจ Mock KV Namespace for testing Cloudflare Workers
The npm package @variablesoftware/mock-kv receives a total of 66 weekly downloads. As such, @variablesoftware/mock-kv popularity was classified as not popular.
We found that @variablesoftware/mock-kv demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago.ย It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Socketโs precomputed reachability slashes false positives by flagging up to 80% of vulnerabilities as irrelevant, with no setup and instant results.
Product
Socket is launching experimental protection for Chrome extensions, scanning for malware and risky permissions to prevent silent supply chain attacks.
Product
Add secure dependency scanning to Claude Desktop with Socket MCP, a one-click extension that keeps your coding conversations safe from malicious packages.