Gathering detailed insights and metrics for @miniflare/shared-test-environment
Gathering detailed insights and metrics for @miniflare/shared-test-environment
Gathering detailed insights and metrics for @miniflare/shared-test-environment
Gathering detailed insights and metrics for @miniflare/shared-test-environment
๐ฅ Fully-local simulator for Cloudflare Workers. For the latest version, see https://github.com/cloudflare/workers-sdk/tree/main/packages/miniflare.
npm install @miniflare/shared-test-environment
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
3,796 Stars
750 Commits
205 Forks
32 Watching
13 Branches
126 Contributors
Updated on 28 Nov 2024
TypeScript (98.7%)
JavaScript (1.3%)
Cumulative downloads
Total Downloads
Last day
-15.9%
6,244
Compared to previous day
Last week
9.9%
40,348
Compared to previous week
Last month
20.9%
146,012
Compared to previous month
Last year
49%
1,474,435
Compared to previous year
[!WARNING]
This repository is for Miniflare 2, which is only receiving critical security updates. Miniflare 2 simulated the Workers runtime and the rest of the Cloudflare developer platform using Node.js. New versions of Miniflare can be found in the
workers-sdk
repository, and use the open-sourced Workers runtimeworkerd
. This practically eliminates behaviour mismatches between development and production deployments. We recommend you migrate to Miniflare 3 now if you can. Whilst Miniflare 3 supports most of Miniflare 2's features, one key omission is the unit testing environment. We're actively working on adding support for this to Miniflare 3. Once this is supported, we're planning to deprecate Miniflare 2 and archive this repository.
Miniflare is a simulator for developing and testing Cloudflare Workers.
It's an alternative to wrangler dev
, written in TypeScript, that runs your
workers in a sandbox implementing Workers' runtime APIs.
See https://legacy.miniflare.dev for more detailed documentation.
.env
FilesMiniflare is installed using npm:
1$ npm install -g miniflare@2 # either globally.. 2$ npm install -D miniflare@2 # ...or as a dev dependency
1$ miniflare worker.js --watch --debug 2[mf:dbg] Options: 3[mf:dbg] - Scripts: worker.js 4[mf:dbg] Reloading worker.js... 5[mf:inf] Worker reloaded! (97B) 6[mf:dbg] Watching .env, package.json, worker.js, wrangler.toml... 7[mf:inf] Listening on :8787 8[mf:inf] - http://127.0.0.1:8787
1import { Miniflare } from "miniflare"; 2 3const mf = new Miniflare({ 4 script: ` 5 addEventListener("fetch", (event) => { 6 event.respondWith(new Response("Hello Miniflare!")); 7 }); 8 `, 9}); 10const res = await mf.dispatchFetch("http://localhost:8787/"); 11console.log(await res.text()); // Hello Miniflare!
Usage: miniflare [script] [options]
Core Options:
-h, --help Show help [boolean]
-v, --version Show version number [boolean]
-c, --wrangler-config Path to wrangler.toml [string]
--wrangler-env Environment in wrangler.toml to use [string]
--package Path to package.json [string]
-m, --modules Enable modules [boolean]
--modules-rule Modules import rule [array:TYPE=GLOB]
--compat-date Opt into backwards-incompatible changes from [string]
--compat-flag Control specific backwards-incompatible changes [array]
--usage-model Usage model (bundled by default) [string]
-u, --upstream URL of upstream origin [string]
-w, --watch Watch files for changes [boolean]
-d, --debug Enable debug logging [boolean]
-V, --verbose Enable verbose logging [boolean]
--(no-)update-check Enable update checker (enabled by default) [boolean]
--repl Enable interactive REPL [boolean]
--root Path to resolve files relative to [string]
--mount Mount additional named workers [array:NAME=PATH[@ENV]]
--name Name of service [string]
--route Route to respond with this worker on [array]
--global-async-io Allow async I/O outside handlers [boolean]
--global-timers Allow setting timers outside handlers [boolean]
--global-random Allow secure random generation outside handlers [boolean]
--actual-time Always return correct time from Date methods [boolean]
--inaccurate-cpu Log inaccurate CPU time measurements [boolean]
HTTP Options:
-H, --host Host for HTTP(S) server to listen on [string]
-p, --port Port for HTTP(S) server to listen on [number]
-O, --open Automatically open browser to URL [boolean/string]
--https Enable self-signed HTTPS (with optional cert path) [boolean/string]
--https-key Path to PEM SSL key [string]
--https-cert Path to PEM SSL cert chain [string]
--https-ca Path to SSL trusted CA certs [string]
--https-pfx Path to PFX/PKCS12 SSL key/cert chain [string]
--https-passphrase Passphrase to decrypt SSL files [string]
--(no-)cf-fetch Path for cached Request cf object from Cloudflare [boolean/string]
--live-reload Reload HTML pages whenever worker is reloaded [boolean]
Scheduler Options:
-t, --cron CRON expression for triggering scheduled events [array]
Build Options:
-B, --build-command Command to build project [string]
--build-base-path Working directory for build command [string]
--build-watch-path Directory to watch for rebuilding on changes [array]
KV Options:
-k, --kv KV namespace to bind [array]
--kv-persist Persist KV data (to optional path) [boolean/string]
R2 Options:
-r, --r2 R2 bucket to bind [array]
--r2-persist Persist R2 data (to optional path) [boolean/string]
Durable Objects Options:
-o, --do Durable Object to bind [array:NAME=CLASS[@MOUNT]]
--do-persist Persist Durable Object data (to optional path) [boolean/string]
--(no-)do-alarms Enable Durable Object alarms (enabled by default) [boolean]
Cache Options:
--(no-)cache Enable default/named caches (enabled by default) [boolean]
--cache-persist Persist cached data (to optional path) [boolean/string]
Sites Options:
-s, --site Path to serve Workers Site files from [string]
--site-include Glob pattern of site files to serve [array]
--site-exclude Glob pattern of site files not to serve [array]
Bindings Options:
-e, --env Path to .env file [string]
-b, --binding Binds variable/secret to environment [array:KEY=VALUE]
--global Binds variable/secret to global scope [array:KEY=VALUE]
--wasm WASM module to bind [array:NAME=PATH]
--text-blob Text blob to bind [array:NAME=PATH]
--data-blob Data blob to bind [array:NAME=PATH]
-S, --service Mounted service to bind [array:NAME=MOUNT[@ENV]]
Miniflare was created by Brendan Coll.
Many thanks to dollarshaveclub/cloudworker and gja/cloudflare-worker-local for inspiration.
Durable Object's transactions are implemented using Optimistic Concurrency Control (OCC) as described in "On optimistic methods for concurrency control." ACM Transactions on Database Systems. Thanks to Alistair O'Brien for helping the Miniflare creator understand this.
No vulnerabilities found.
No security vulnerabilities found.