Skip to content
This repository was archived by the owner on Mar 13, 2025. It is now read-only.

Commit f671590

Browse files
authored
Bump versions to 2.12.0, update CHANGELOG.md and docs (#502)
1 parent e285955 commit f671590

File tree

31 files changed

+592
-390
lines changed

31 files changed

+592
-390
lines changed

docs/CHANGELOG.md

Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,155 @@
11
# 🚧 Changelog
22

3+
## 2.12.0
4+
5+
### Features
6+
7+
- Add support for R2 multipart upload bindings.
8+
- Add support for dynamic `import()`s. Closes
9+
[issue #456](https://github.com/cloudflare/miniflare/issues/456), thanks
10+
[@calebmer](https://github.com/calebmer).
11+
- Add support for the
12+
[`new WebSocket()` constructor](https://developer.mozilla.org/en-US/docs/Web/API/WebSocket/WebSocket).
13+
This is an alternative standard API to `fetch`-with-`Upgrade: websocket` for
14+
creating WebSocket clients.
15+
- Add support for the `nodejs_compat` compatibility flag, specifically the
16+
`node:assert`, `node:async_hooks`, `node:buffer`, `node:events`, and
17+
`node:util` modules. For now, the `experimental` compatibility flag must also
18+
be enabled to use `node:assert`, `node:buffer` or `node:events`. Thanks
19+
[@GregBrimble](https://github.com/GregBrimble) for
20+
[the PR](https://github.com/cloudflare/miniflare/pull/478).
21+
- Extract out types for test environment global helper functions. Add either
22+
`jest-environment-miniflare/globals` or `vitest-environment-miniflare/globals`
23+
to your `tsconfig.json`'s `types` array to include them. Closes
24+
[issue #94](https://github.com/cloudflare/miniflare/issues/94), thanks
25+
[@ryan-mars](https://github.com/ryan-mars).
26+
27+
```jsonc
28+
// tsconfig.json
29+
{
30+
"compilerOptions": {
31+
// ...
32+
"types": [
33+
"@cloudflare/workers-types",
34+
// For Jest...
35+
"jest",
36+
"jest-environment-miniflare/globals"
37+
// ...or for Vitest
38+
"vitest-environment-miniflare/globals"
39+
]
40+
}
41+
}
42+
```
43+
44+
- Allow direct access to Durable Object instances inside testing environments.
45+
Thanks [@cdrx](https://github.com/cdrx) for
46+
[the PR](https://github.com/cloudflare/miniflare/pull/385). See
47+
[🤹 Jest Environment](https://miniflare.dev/testing/jest#constructing-durable-objects-directly)
48+
or
49+
[⚡️ Vitest Environment](https://miniflare.dev/testing/vitest#constructing-durable-objects-directly)
50+
for more details.
51+
- Forward `/cdn-cgi/scripts/*` to Cloudflare. This allows scripts such as
52+
`rocket-loader.min.js` to be loaded during development. Closes
53+
[issue #421](https://github.com/cloudflare/miniflare/issues/421), thanks
54+
[@jstevans](https://github.com/jstevans) for
55+
[the PR](https://github.com/cloudflare/miniflare/pull/422)
56+
- Implement `structuredClone` `transfer` option for Node.js versions below 17.
57+
Note Miniflare's minimum supported Node.js version is still 16.13.0.
58+
- Set default-on date for `streams_enable_constructors` and
59+
`transformstream_enable_standard_constructor` compatibility flags to
60+
`2022-11-30`.
61+
- Add support for the `DurableObjectStorage#sync()` method. See
62+
[cloudflare/workerd#87](https://github.com/cloudflare/workerd/pull/87) for
63+
details.
64+
- Accept
65+
[multiple keys in `R2Bucket#delete()`](https://community.cloudflare.com/t/2022-9-16-workers-runtime-release-notes/420496).
66+
Closes [issue #420](https://github.com/cloudflare/miniflare/issues/420),
67+
thanks [@TateB](https://github.com/TateB).
68+
- Implement the
69+
[`r2_list_honor_include`](https://developers.cloudflare.com/workers/platform/compatibility-dates/#r2-bucket-list-respects-the-include-option)
70+
compatibility flag.
71+
- Add support for the
72+
[HTTP `Range` header](https://community.cloudflare.com/t/2022-8-12-workers-runtime-release-notes/410873)
73+
to `R2Bucket#get()`.
74+
- Add support for
75+
[R2 `SHA-*` checksums](https://community.cloudflare.com/t/2022-9-16-workers-runtime-release-notes/420496),
76+
and return these from `R2Bucket#{get,head}`.
77+
- Implement the
78+
[`export_commonjs_default`/`export_commonjs_namespace`](https://developers.cloudflare.com/workers/platform/compatibility-dates/#commonjs-modules-do-not-export-a-module-namespace)
79+
compatibility flags. Note Miniflare previously implemented
80+
`export_commonjs_default` behaviour for `CommonJS` modules, but
81+
`export_commonjs_namespace` behaviour for all other types. This change
82+
switches everything to the correct `export_commonjs_default` by default, but
83+
allows old behaviour to be enabled by setting `export_commonjs_namespace`.
84+
- Add support for `D1Database#dump()`
85+
- Add support for `meta.{last_row_id,changes}` properties on D1 responses
86+
87+
### Fixes
88+
89+
- Fix request body type when mocking fetch requests in testing environments with
90+
`getMiniflareFetchMock()` and via the `fetchMock` option. Thanks
91+
[@robertcepa](https://github.com/robertcepa) for
92+
[the PR](https://github.com/cloudflare/miniflare/pull/423).
93+
- Respect the `maxBatchSize` setting of queue consumers. Thanks
94+
[@a-robinson](https://github.com/a-robinson) for
95+
[the PR](https://github.com/cloudflare/miniflare/pull/450).
96+
- Fix `jest-environment-miniflare`'s `homepage` URL. Thanks
97+
[@aaharu](https://github.com/aaharu) for
98+
[the PR](https://github.com/cloudflare/miniflare/pull/451).
99+
- Fix typo in R2 documentation. Thanks [@aarhus](https://github.com/aarhus) for
100+
[the PR](https://github.com/cloudflare/miniflare/pull/452).
101+
- Rename queue producer binding class to `WorkerQueue`, matching the name in the
102+
real runtime. This will enable
103+
[`workers-rs`](https://github.com/cloudflare/workers-rs) to provide queue
104+
bindings. Thanks [@zebp](https://github.com/zebp) for
105+
[the PR](https://github.com/cloudflare/miniflare/pull/455).
106+
- Reset internal body stream when cloning `Request`s and `Response`s. This
107+
ensures both clones' bodies can be read. Thanks
108+
[@DSergiu](https://github.com/DSergiu) for
109+
[the PR](https://github.com/cloudflare/miniflare/pull/449).
110+
- Bump `npx-import` to `1.1.4`, fixing `require is not defined` error when using
111+
D1. Closes [issue #400](https://github.com/cloudflare/miniflare/issues/400),
112+
thanks [@tgriesser](https://github.com/tgriesser) and
113+
[@geelen](https://github.com/geelen).
114+
- Bump `undici` to `5.11.0`, allowing third-party `FormData`/`Blob`
115+
`Request`/`Response` bodies. Closes
116+
[issue #351](https://github.com/cloudflare/miniflare/issues/351), thanks
117+
[@yusefnapora](https://github.com/yusefnapora).
118+
- Get `CryptoKey` class from global scope if available. Fixes
119+
`'instanceof' is not an object` error in Node.js 19 and above. Closes
120+
[issue #457](https://github.com/cloudflare/miniflare/issues/457), thanks
121+
[@edevil](https://github.com/edevil) and [@panva](https://github.com/panva).
122+
- Bump `better-sqlite3` to `8.0.1`, adding support for Node.js 19.
123+
- Coerce R2 keys to `string`s.
124+
- Fix return type of `D1PreparedStatement#raw()`. Closes
125+
[issue cloudflare/workers-sdk#2238](https://github.com/cloudflare/workers-sdk/issues/2238),
126+
thanks [@repository](https://github.com/repository) for
127+
[the PR](https://github.com/cloudflare/miniflare/pull/474).
128+
- Throw when calling `D1PreparedStatement#run()` with statements that return
129+
data. Closes [issue #441](https://github.com/cloudflare/miniflare/issues/441),
130+
thanks [@AlexBlokh](https://github.com/AlexBlokh).
131+
- Fix D1 response envelope format. Closes issues
132+
[#442](https://github.com/cloudflare/miniflare/issues/442) and
133+
[cloudflare/workers-sdk#2504](https://github.com/cloudflare/workers-sdk/issues/2504),
134+
thanks [@jiripospisil](https://github.com/jiripospisil) and
135+
[@demosjarco](https://github.com/demosjarco).
136+
- Fix binding/return of `BLOB`-typed values in D1 operations. Closes
137+
[cloudflare/workers-sdk#2527](https://github.com/cloudflare/workers-sdk/issues/2527),
138+
thanks [@JoshVazq](https://github.com/JoshVazq).
139+
- Ensure `D1Database#{batch,exec}()` statements are executed in an implicit
140+
transaction. Closes
141+
[issue #484](https://github.com/cloudflare/miniflare/issues/484), thanks
142+
[@anthonymclaughlin](https://github.com/anthonymclaughlin).
143+
- Ensure only first statements are executed when calling
144+
`D1PreparedStatement#{first,run,all,raw}()`
145+
- Throw an error when KV expiration values exceed 32-bit signed integer bounds.
146+
Closes [issue #485](https://github.com/cloudflare/miniflare/issues/485),
147+
thanks [@huw](https://github.com/huw) for
148+
[the PR](https://github.com/cloudflare/miniflare/pull/487).
149+
- Pass through WebSocket abnormal closure code. Closes
150+
[issue #465](https://github.com/cloudflare/miniflare/issues/465), thanks
151+
[@yw662](https://github.com/yw662).
152+
3153
## 2.11.0
4154

5155
### Features

docs/src/content/core/compatibility.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,16 @@ const mf = new Miniflare({
6969

7070
Specifically Miniflare supports the following flags:
7171

72-
- `streams_enable_constructors`/`streams_disable_constructors`
73-
- `transformstream_enable_standard_constructor`/`transformstream_disable_standard_constructor`
72+
- `nodejs_compat` (specifically the _`node:assert`_\*, `node:async_hooks`,
73+
_`node:buffer`_\*, `node:events`, _`node:util`_\* modules)
74+
- [`transformstream_enable_standard_constructor`/`transformstream_disable_standard_constructor`](https://developers.cloudflare.com/workers/platform/compatibility-dates#compliant-transformstream-constructor)
75+
- [`streams_enable_constructors`/`streams_disable_constructors`](https://developers.cloudflare.com/workers/platform/compatibility-dates#streams-constructors)
76+
- [`export_commonjs_default`/`export_commonjs_namespace`](https://developers.cloudflare.com/workers/platform/compatibility-dates#commonjs-modules-do-not-export-a-module-namespace)
77+
- [`r2_list_honor_include`](https://developers.cloudflare.com/workers/platform/compatibility-dates#r2-bucket-list-respects-the-include-option)
7478
- [`global_navigator`/`no_global_navigator`](https://developers.cloudflare.com/workers/platform/compatibility-dates#global-navigator)
7579
- [`durable_object_fetch_requires_full_url`/`durable_object_fetch_allows_relative_url`](https://developers.cloudflare.com/workers/platform/compatibility-dates#durable-object-stubfetch-requires-a-full-url)
7680
- [`fetch_refuses_unknown_protocols`/`fetch_treats_unknown_protocols_as_http`](https://developers.cloudflare.com/workers/platform/compatibility-dates#fetch-improperly-interprets-unknown-protocols-as-http)
7781
- [`formdata_parser_supports_files`/`formdata_parser_converts_files_to_strings`](https://developers.cloudflare.com/workers/platform/compatibility-dates#formdata-parsing-supports-file)
7882
- [`html_rewriter_treats_esi_include_as_void_tag`](https://developers.cloudflare.com/workers/platform/compatibility-dates#htmlrewriter-handling-of-esiinclude)
83+
84+
\* _Additionally requires the `experimental` compatibility flag to be set_

docs/src/content/core/web-sockets.md

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,9 @@ webSocket.send("Hello!"); // Above listener logs "Hello!"
5959

6060
## Client
6161

62-
Miniflare also supports using workers as WebSocket clients too via `fetch`:
62+
Miniflare also supports using workers as WebSocket clients too via `fetch` or
63+
the
64+
[standard `new WebSocket()` constructor](https://developer.mozilla.org/en-US/docs/Web/API/WebSocket/WebSocket):
6365

6466
```js
6567
---
@@ -92,13 +94,8 @@ Like the real Workers runtime, Miniflare will throw errors when:
9294

9395
- Attempting to use a `WebSocket` in a `Response` that has already been used
9496
- Attempting to use a `WebSocket` in a `Response` after calling `accept()` on it
95-
- Attempting to construct a `WebSocket` using the `WebSocket` constructor
9697
- Attempting to call `WebSocket#send()` or `WebSocket#close()` without first
9798
calling `accept()`
9899
- Attempting to call `WebSocket#send()` after calling `close()`
99100
- Attempting to call `WebSocket#close()` on an already closed WebSocket
100101
- Attempting to call `WebSocket#close()` with an invalid close code
101-
102-
Note Miniflare intentionally doesn't support the `WebSocket#readyState`
103-
property, or the `open` event, as these aren't yet supported by the real Workers
104-
runtime.

docs/src/content/testing/jest.md

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,27 @@ export default {
4141
};
4242
```
4343

44+
To enable TypeScript type checking and completions for global helper functions,
45+
add `jest-environment-miniflare/globals` to your `tsconfig.json`'s `types`
46+
array:
47+
48+
```json
49+
---
50+
filename: tsconfig.json
51+
highlight: [7]
52+
---
53+
{
54+
"compilerOptions": {
55+
...
56+
"types": [
57+
"@cloudflare/workers-types",
58+
"jest",
59+
"jest-environment-miniflare/globals"
60+
]
61+
}
62+
}
63+
```
64+
4465
## Writing and Running Tests
4566

4667
The Miniflare environment lets us import our worker's functions with regular
@@ -290,7 +311,9 @@ function. This allows you to call instance methods and access ephemeral state
290311
directly. Wrapping calls to instance methods with
291312
`runWithMiniflareDurableObjectGates()` will close the Durable Object's input
292313
gate, and wait for the output gate to open before resolving. Make sure to use
293-
this when calling your `fetch()` method.
314+
this when calling your `fetch()` method. The
315+
`getMiniflareDurableObjectInstance()` global function can also be used to get
316+
instances directly.
294317
295318
```js
296319
---
@@ -308,8 +331,10 @@ test("increments count", async () => {
308331
const state = await getMiniflareDurableObjectState(id);
309332
await state.storage.put("count", 3);
310333

311-
// Construct object directly
334+
// Construct object...
312335
const object = new TestObject(state, env);
336+
// ...or get an instance directly
337+
const object = getMiniflareDurableObjectInstance(id);
313338

314339
// Concurrently increment the count twice. Wrapping `object.fetch`
315340
// calls with `runWithMiniflareDurableObjectGates(state, ...)`

docs/src/content/testing/vitest.md

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,26 @@ export default defineConfig({
4545
})
4646
```
4747

48+
To enable TypeScript type checking and completions for global helper functions,
49+
add `vitest-environment-miniflare/globals` to your `tsconfig.json`'s `types`
50+
array:
51+
52+
```json
53+
---
54+
filename: tsconfig.json
55+
highlight: [6]
56+
---
57+
{
58+
"compilerOptions": {
59+
...
60+
"types": [
61+
"@cloudflare/workers-types",
62+
"vitest-environment-miniflare/globals"
63+
]
64+
}
65+
}
66+
```
67+
4868
## Writing and Running Tests
4969

5070
The Miniflare environment lets us import our worker's functions with regular
@@ -324,7 +344,9 @@ function. This allows you to call instance methods and access ephemeral state
324344
directly. Wrapping calls to instance methods with
325345
`runWithMiniflareDurableObjectGates()` will close the Durable Object's input
326346
gate, and wait for the output gate to open before resolving. Make sure to use
327-
this when calling your `fetch()` method.
347+
this when calling your `fetch()` method. The
348+
`getMiniflareDurableObjectInstance()` global function can also be used to get
349+
instances directly.
328350
329351
```js
330352
---
@@ -345,8 +367,10 @@ test("increments count", async () => {
345367
const state = await getMiniflareDurableObjectState(id);
346368
await state.storage.put("count", 3);
347369

348-
// Construct object directly
370+
// Construct object...
349371
const object = new TestObject(state, env);
372+
// ...or get an instance directly
373+
const object = getMiniflareDurableObjectInstance(id);
350374

351375
// Concurrently increment the count twice. Wrapping `object.fetch`
352376
// calls with `runWithMiniflareDurableObjectGates(state, ...)`

0 commit comments

Comments
 (0)