Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion fixtures/vitest-pool-workers-examples/rpc/test/unit.test.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import {
createExecutionContext,
env,
runDurableObjectAlarm,
runInDurableObject,
SELF,
} from "cloudflare:test";
import { RpcStub } from "cloudflare:workers";
import { describe, it, onTestFinished } from "vitest";
import { Counter, TestObject } from "../src";
import TestDefaultEntrypoint, { Counter, TestObject } from "../src";

describe("named entrypoints", () => {
it("dispatches fetch request to named ExportedHandler", async ({
Expand Down Expand Up @@ -154,6 +155,25 @@ describe("Durable Object", () => {
});
});

// Regression: https://github.com/cloudflare/workers-sdk/issues/7077
// Fixed in workerd by https://github.com/cloudflare/workerd/pull/3782
it("can construct a WorkerEntrypoint with mocked env", async ({ expect }) => {
const data = new Map<string, string>([["mocked-key", "mocked-value"]]);
const mockedKv = new Proxy(env.KV_NAMESPACE, {
get: (target, prop, receiver) =>
prop === "get"
? async (key: string) => data.get(key) ?? null
: Reflect.get(target, prop, receiver),
});

const ctx = createExecutionContext();
const worker = new TestDefaultEntrypoint(ctx, {
...env,
KV_NAMESPACE: mockedKv,
});
expect(await worker.read("mocked-key")).toBe("mocked-value");
});

describe("counter", () => {
it("increments count", ({ expect }) => {
const counter = new Counter(3);
Expand Down
Loading