Skip to content

Commit

Permalink
Bump versions to 2.8.0, update CHANGELOG.md and docs
Browse files Browse the repository at this point in the history
  • Loading branch information
mrbbot committed Sep 7, 2022
1 parent ecb48fb commit 57428ca
Show file tree
Hide file tree
Showing 38 changed files with 869 additions and 345 deletions.
94 changes: 94 additions & 0 deletions docs/CHANGELOG.md
@@ -1,5 +1,99 @@
# 🚧 Changelog

# 2.8.0

## Features

- ⚡️ Add **custom Vitest testing environment**. This behaves almost identically
to the Jest environment. However, isolated storage must be installed manually
in each test file. Call the `setupMiniflareIsolatedStorage()` global function
and use the returned `describe` function instead of the regular
`describe`/`suite` functions imported from `vitest`. See
[⚡️ Vitest Environment](https://miniflare.dev/testing/vitest) for more
details.
- 🌐 **Populate Workers Sites `__STATIC_CONTENT_MANIFEST`** with site files
instead of an empty object. Miniflare will still disable caching of Workers
Sites files to ensure the most up-to-date files are always returned. Closes
[issues #233](https://github.com/cloudflare/miniflare/issues/233),
[#326](https://github.com/cloudflare/miniflare/issues/326) and
[cloudflare/wrangler2#1632](https://github.com/cloudflare/wrangler2/issues/1632).
Thanks [@ItalyPaleAle](https://github.com/ItalyPaleAle),
[@Skye-31](https://github.com/Skye-31),
[@CraigglesO](https://github.com/CraigglesO),
[@Hexstream](https://github.com/Hexstream) and
[@PolariTOON](https://github.com/PolariTOON).
-**Add global `getMiniflareWaitUntil()` method** and `ExecutionContext` class
to the Jest and Vitest testing environments. This can be used to `await` the
results of `waitUntil`ed `Promise`s in tests. See
[🤹️ Jest Environment](https://miniflare.dev/testing/jest#waiting-for-waituntiled-promises)
and
[⚡️ Vitest Environment](https://miniflare.dev/testing/vitest#waiting-for-waituntiled-promises)
for more details.
- ⏳ Match Web Streams implementations with Workers runtime, closes issue
[#168](https://github.com/cloudflare/miniflare/issues/168), thanks
[@leviwolfe](https://github.com/leviwolfe):
- Add support for the non-standard
[`IdentityTransformStream`](https://developers.cloudflare.com/workers/runtime-apis/streams/transformstream/#identitytransformstream)
class.
- Add support for the **`streams_enable_constructors` compatibility flag**.
`ReadableStream` and `WritableStream` constructors will throw unless this
flag is enabled. `ReadableByteStreamController`,
`ReadableStreamBYOBRequest`, `ReadableStreamDefaultController` and
`WritableStreamDefaultController` will only be included in the sandbox if
this flag is enabled.
- Add support for the **`transformstream_enable_standard_constructor`
compatibility flag**. `TransformStream` will behave like
`IdentityTransformStream` if this isn't enabled, ignoring custom
transformers. If `transformstream_enable_standard_constructor` is set, but
`streams_enable_constructors` isn't, the `TransformStream` constructor will
throw. `TransformStreamDefaultController` will only be included in the
sandbox if both flags are enabled.
- Add support for BYOB reads to the non-standard
[`FixedLengthStream`](https://developers.cloudflare.com/workers/runtime-apis/streams/transformstream/#fixedlengthstream)
class.
- 🇬🇧 Add support for **Queues**. Docs coming soon™... 👀
- 🙉 Allow calls to `addEventListener`, `removeEventListener` and
`dispatchEvent` in modules mode. Please note, calling `addEventListener` with
a special event type (e.g. `fetch`, `scheduled`) will log a warning prompting
you to use the `export default` syntax. Closes
[issue #207](https://github.com/cloudflare/miniflare/issues/207), thanks
[@Electroid](https://github.com/Electroid).
- 🍟 Add experimental and highly-inaccurate request CPU time measurements. These
are not representative of deployed worker performance, should only be used for
relative comparisons, and may be removed in the future. Enable measurements
with the `--inaccurate-cpu`/`[miniflare] inaccurate_cpu`/`inaccurateCpu`
option. Closes
[issue #161](https://github.com/cloudflare/miniflare/issues/161). Thanks
[@alexandernst](https://github.com/alexandernst) and
[@y21](https://github.com/y21).
- 🦄 Automatically enable watch mode when `live_reload = true` is set in
`wrangler.toml`.

## Fixes

- Return `Response`s with immutable headers from `fetch`es to Durable Objects
and service bindings. Closes
[issue #346](https://github.com/cloudflare/miniflare/issues/346), thanks
[@Cherry](https://github.com/Cherry).
- Fix `CryptoKey#algorithm.name` property of `NODE-ED25519` keys. Closes
[issue panva/jose#446](https://github.com/panva/jose/issues/446), thanks
[@ItalyPaleAle](https://github.com/ItalyPaleAle).
- Disable automatic insertion of `Sec-WebSocket-Protocol` header. Closes
[issue #179](https://github.com/cloudflare/miniflare/issues/179), thanks
[@aboodman](https://github.com/aboodman) and
[@grgbkr](https://github.com/grgbkr).
- Return `Content-Length` header is custom `Content-Encoding` is specified.
Closes [issue #313](https://github.com/cloudflare/miniflare/issues/313),
thanks [@vlovich](https://github.com/vlovich).
- Require `"automatic"` instead of `"auto"` for the `encodeBody` option when
constructing `Request`s. Closes
[issue #357](https://github.com/cloudflare/miniflare/issues/357), thanks
[@GregBrimble](https://github.com/GregBrimble) for
[the PR](https://github.com/cloudflare/miniflare/pull/358).
- Remove `request.cf.cacheTtl`/`request.cf.cacheTtlByStatus` support from the
Cache API to match the behaviour of the Workers runtime, which only supports
`request.cf.cacheKey`.

# 2.7.1

## Fixes
Expand Down
2 changes: 2 additions & 0 deletions docs/src/content/core/compatibility.md
Expand Up @@ -69,6 +69,8 @@ const mf = new Miniflare({

Specifically Miniflare supports the following flags:

- `streams_enable_constructors`/`streams_disable_constructors`
- `transformstream_enable_standard_constructor`/`transformstream_disable_standard_constructor`
- [`global_navigator`/`no_global_navigator`](https://developers.cloudflare.com/workers/platform/compatibility-dates#global-navigator)
- [`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)
- [`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)
Expand Down
3 changes: 2 additions & 1 deletion docs/src/content/core/standards.md
Expand Up @@ -33,7 +33,8 @@ Miniflare supports the following Web Standards in its sandbox:
`ReadableStreamDefaultController`, `ReadableStreamDefaultReader`,
`TransformStream`, `TransformStreamDefaultController`, `WritableStream`,
`WritableStreamDefaultController`, `WritableStreamDefaultWriter`,
`FixedLengthStream`, `CompressionStream`, `DecompressionStream`
`IdentityTransformStream`, `FixedLengthStream`, `CompressionStream`,
`DecompressionStream`
- **Events:** `Event`, `EventTarget`, `AbortController`, `AbortSignal`
- **Event Types:** `fetch`, `scheduled`, `unhandledrejection`,
`rejectionhandled`
Expand Down
4 changes: 2 additions & 2 deletions docs/src/content/developing/live-reload.md
Expand Up @@ -35,8 +35,8 @@ const mf = new Miniflare({

<Aside header="Tip">

When using the CLI, if `--live-reload` is set, `--watch` is automatically
assumed.
When using the CLI, if either `--live-reload` or `[miniflare] live_reload` is
set, `--watch` is automatically assumed.

</Aside>

Expand Down
4 changes: 4 additions & 0 deletions docs/src/content/get-started/api.md
Expand Up @@ -411,6 +411,10 @@ const mf = new Miniflare({
globalTimers: true, // Allow setting timers outside handlers
globalRandom: true, // Allow secure random generation outside handlers

acutalTime: true, // Always return current time from `Date.now()`/`new Date()`

inaccurateCpu: true, // Log experimental, highly-inaccurate CPU time measurements with each request

host: "127.0.0.1", // Host for HTTP(S) server to listen on
port: 8787, // Port for HTTP(S) server to listen on
https: true, // Enable self-signed HTTPS (with optional cert path)
Expand Down
3 changes: 3 additions & 0 deletions docs/src/content/get-started/cli.md
Expand Up @@ -275,6 +275,7 @@ Core Options:
--global-random Allow secure random generation outside [boolean]
handlers
--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]
Expand Down Expand Up @@ -416,6 +417,8 @@ actual_time = true # --actual-time
global_async_io = true # --global-async-io
global_timers = true # --global-timers
global_random = true # --global-random
actual_time = true # --actual-time
inaccurate_cpu = true # --inaccurate-cpu
[miniflare.https]
key = "./key.pem" # --https-key
cert = "./cert.pem" # --https-cert
Expand Down
8 changes: 4 additions & 4 deletions docs/src/content/storage/sites.md
Expand Up @@ -72,7 +72,7 @@ addEventListener("fetch", (event) => {

When you enable Workers Sites, a read-only KV namespace, bound to
`__STATIC_CONTENT`, is created using the file system (without key sanitisation)
as its storage. An empty object, `{}`, is bound to `__STATIC_CONTENT_MANIFEST`.
This tricks `@cloudflare/kv-asset-handler` into disabling edge caching, meaning
the most up-to-date file is always loaded from disk. Miniflare also binds this
empty object to the `__STATIC_CONTENT_MANIFEST` text module.
as its storage. Each entry in the bound `__STATIC_CONTENT_MANIFEST` object
contains a magic prefix that disables edge caching. This means the most
up-to-date file are always loaded from disk. Miniflare also binds this object to
the `__STATIC_CONTENT_MANIFEST` text module.
2 changes: 1 addition & 1 deletion docs/src/content/testing/ava.md
@@ -1,5 +1,5 @@
---
order: 1
order: 2
---

# 🚀 Testing with AVA
Expand Down
42 changes: 42 additions & 0 deletions docs/src/content/testing/jest.md
Expand Up @@ -296,3 +296,45 @@ test("mocks fetch", async () => {
expect(text).toBe("Mocked response!");
});
```
## Waiting for `waitUntil`ed `Promise`s
To `await` the results of `waitUntil`ed `Promise`s, call the
`getMiniflareWaitUntil()` global function on a `FetchEvent`, `ScheduledEvent` or
`ExecutionContext`. This will return a `Promise` that resolves to an array of
resolved `waitUntil`ed `Promise` values:
```js
---
filename: src/index.js
---
export default {
async fetch(request, env, ctx) {
ctx.waitUntil(Promise.resolve(1));
ctx.waitUntil(Promise.resolve(2));
ctx.waitUntil(Promise.resolve(3));
return new Response("body");
}
}
```
```js
---
filename: test/index.spec.js
---
import worker from "../src/index.js";

test("wait until", async () => {
const request = new Request("http://localhost:8787/");
const env = getMiniflareBindings();
const ctx = new ExecutionContext();

// Call module worker handler
const response = worker.fetch(request, env, ctx);
expect(await response.text()).toBe("body");

// Check resolved values of waitUntil'ed Promises
const waitUntils = await getMiniflareWaitUntil(ctx);
expect(waitUntils).toEqual([1, 2, 3]);
});
```

0 comments on commit 57428ca

Please sign in to comment.