github cloudflare/miniflare v2.7.0

latest releases: 2.14.3, v2.14.2, v3.20231025.0...
2 years ago

⚠️ Miniflare's minimum supported Node.js version is now 16.13.0. This was the first LTS release of Node.js 16.

We recommend you use the latest Node.js version if possible, as Cloudflare Workers use a very up-to-date version of V8. Consider using a Node.js version manager such as https://volta.sh/ or https://github.com/nvm-sh/nvm.

Features

  • 🎉 Add support for easily mocking outbound fetch requests. See 🕸 Web Standards for more details. Closes issue #162, thanks @william1616 for the PR.

    test("mocks fetch", async () => {
      // Get correctly set up `MockAgent`
      const fetchMock = getMiniflareFetchMock();
      // Throw when no matching mocked request is found
      fetchMock.disableNetConnect();
      // Mock request to https://example.com/thing
      const origin = fetchMock.get("https://example.com");
      origin.intercept({ method: "GET", path: "/thing" }).reply(200, "Mocked response!");
    
      const res = await fetch("https://example.com/thing");
      const text = await res.text();
      expect(text).toBe("Mocked response!");
    });
  • 🚽 Add support to immediately invoke ("flush") scheduled Durable Object alarms in the 🤹 Jest Environment. Closes issue #322, thanks @robertcepa and @CraigglesO for the PR.

    test("flushes alarms", async () => {
      // Get Durable Object stub
      const env = getMiniflareBindings();
      const id = env.TEST_OBJECT.newUniqueId();
      const stub = env.TEST_OBJECT.get(id);
    
      // Schedule Durable Object alarm
      await stub.fetch("http://localhost/");
    
      // Flush all alarms...
      await flushMiniflareDurableObjectAlarms();
      // ...or specify an array of `DurableObjectId`s to flush
      await flushMiniflareDurableObjectAlarms([id]);
    });
  • 🪣 Add support for R2 bucket bindings to the 🤹 Jest Environment. Closes issue #305, thanks @Cerberus for the PR.

  • 2️⃣ Add support for Wrangler 2's routes property. Closes issue #254, thanks @jrencz for the PR.

  • ⚠️ Upgrade undici to 5.9.1. Thanks @yusukebe and @cameron-robey for the PRs.

Fixes

Don't miss a new miniflare release

NewReleases is sending notifications on new releases.