-
Notifications
You must be signed in to change notification settings - Fork 742
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Miniflare] Cloudflare Pages Support for unit testing #4365
Comments
Hey! 👋 Thanks for raising this issue, and apologies for the delayed response. I'm going to transfer this to const ctx = new ExecutionContext();
const context: EventContext<Env, string, Record<string, unknown>> = {
request: new Request("http://localhost"),
functionPath: "",
waitUntil: ctx.waitUntil.bind(ctx),
passThroughOnException: ctx.passThroughOnException.bind(ctx),
async next(input) {
return new Response();
},
env: {
...getMiniflareBindings(),
ASSETS: {
async fetch(input, info) {
const request = new Request(input, info);
const url = new URL(request.url);
if (url.pathname === "/index.html") {
return new Response("<h1>Hello!</h1>");
} else {
return new Response(null, { status: 404 });
}
}
}
},
params: {},
data: {}
};
// ...do something with `context`...
await getMiniflareWaitUntil(ctx); |
Since this issue was opened, we've released the revamped Vitest work for Miniflare 3, which should work with Pages Functions: https://developers.cloudflare.com/workers/testing/unit-testing/ |
I saw cloudflare/miniflare#113, but I am interested in using miniflare with Jest to test Cloudflare Pages Functions.
It doesn't seem possible to create a mock
EventContext
with Miniflare at current.The text was updated successfully, but these errors were encountered: